Skip to content

add callback to syncers? #17

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

Closed
beeplin opened this issue Oct 21, 2016 · 4 comments
Closed

add callback to syncers? #17

beeplin opened this issue Oct 21, 2016 · 4 comments

Comments

@beeplin
Copy link
Contributor

beeplin commented Oct 21, 2016

I understand that an itemSyncer is actually an automatic get, and a collectionSyncer is an automatic find, but it seems currently it lacks callback params, so we cannot do something after the authomatic get/find is done or failed.

I suggest that in the sync option, allow users to pass in a success and a failure callback, so make the syncers can do all things find and get can do. Just like this:

new Vue {
  data: ...,
  sync: {
    item: {
      service: 'xxx',
      id: 'xxxxxx',
      success: (data) => {
        do something;
      },
    collection: {
      service: 'xxx',
      query: { ... },
      failure: (error) => {
        do something;
      }
    }
  }
}

Or any better names or better ways to do this?

@beeplin beeplin changed the title add a callback for syncers? add callback to syncers? Oct 21, 2016
@t2t2
Copy link
Owner

t2t2 commented Oct 21, 2016

Events?

example in tests

@beeplin
Copy link
Contributor Author

beeplin commented Oct 21, 2016

Hmmm, events could do the job. While, those developers who are already familiar with the ordinary feathers syntax might feel better if an additional callback-style interface is provided. Let's compare the two syntax:

new Vue {
  sync: {
    item: {
      service: 'xxx',
      id: 'xxxx',
      success: (data) => { 
        console.log(data)
      }
    }
  }
}

or:

new Vue {
  sync: {
    item: {
      service: 'xxx',
      id: 'xxxx'
    }
  }
  ...
  inSomeHooksOrMethods: {
    this.$on('syncer-loaded', (path, error) => {
      if (path === 'item') {
        console.log(this.item)
      }
    }
  }
}   

I feel the event way separates the declaration of the syncer and it's behavior apart, making it a little big hard to read, and is not that concise.

@t2t2
Copy link
Owner

t2t2 commented Oct 21, 2016

Yeah that's way better for that use

Regarding interface, I feel like loaded/error would be better so it matches the event name, or onLoaded/onError so it's clearer from name that it's a callback

@beeplin
Copy link
Contributor Author

beeplin commented Oct 21, 2016

yeah I prefer loaded/error.

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

No branches or pull requests

2 participants