Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

refresh() instance method on PromiseState #182

Open

Description

@cadbox1

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?

Activity

  1. heyimalex commented on Sep 21, 2017

    @heyimalex

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions