Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refresh() instance method on PromiseState #182

Open
cadbox1 opened this issue Aug 4, 2017 · 1 comment
Open

refresh() instance method on PromiseState #182

cadbox1 opened this issue Aug 4, 2017 · 1 comment

Comments

@cadbox1
Copy link

cadbox1 commented Aug 4, 2017

I'm new to the library but i've been using the manual refresh pattern from the readme a lot because each of my screens have a refresh button.

connect(props => {
 const url = `/users/${props.userId}`

 return {
   userFetch: url,
   refreshUser: () => ({
     userFetch: {
       url,
       force: true,
       refreshing: true
     }
   })
 }
})(Profile)

Reading through the documentation for PromiseState i noticed that there is a refresh() static method but not an instance method. I think adding it as an instance method would be hugely helpful to a lot of people. It would reduce the above to:

connect(props => ({
   userFetch: `/users/${props.userId}`,
 })(Profile)

and then call the refresh using props.userFetch.refresh()

Am i missing something? It doesn't look like anyone has mentioned it before, do they just write the extra code?

@heyimalex
Copy link

PromiseState is only a representation of promise state, its methods don't actually do anything but synchronously make more PromiseStates. Not that the idea is bad or your gripe is unjustified, just that PromiseState isn't the right place for it.

I personally just write the code when I need it. If you're really lazy you could write a helper function :)

function refreshable(key, url) {
  return {
    `${key}Fetch`: url,
    `${key}Refresh`: () => ({
      `${key}Fetch`: {
        url,
        force: true,
        refreshing: true
      }
    })
  }
}

connect(props => ({
  ...refreshable('user', `/users/${props.userId}`)
}))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants