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

[Feature request] Make it possible to add an extra 'callback' function to custom actions #46

Closed
Windvis opened this issue Jun 20, 2018 · 3 comments

Comments

@Windvis
Copy link

Windvis commented Jun 20, 2018

I think it would be nice if you could pass extra 'callback' functions to the modelAction function.

This makes it possible to optimistically change the state of the model to what is the expected result from the server which improves usability.

What it could look like:

export default Model.extend({
  isFavorited: attr('boolean'),

  favorite: modelAction('favorite', {}, function () {
    this.set('isFavorited', true);
  }),
});

At the moment this is possible by writing a wrapper function, which calls the custom action, but I think it would be an improvement if this was included in this addon.

Let me know what you think!

@Windvis
Copy link
Author

Windvis commented Jun 20, 2018

It should probably be integrated differently, the function in the code example might be confused for a response handler.

Maybe the function should be passed as a property on the options object?

@Exelord
Copy link
Member

Exelord commented Jun 24, 2018

You shouldn't change model state during the adapter request. This is not an action form the ember meaning. If you need some custom behavior just use:

export default Model.extend({
  isFavorited: attr('boolean'),

  _markAsFavorite: modelAction('favorite'),

  markAsFavorite() {
    this.set('isFavorited', true);
    return this._markAsFavorite();
  },
});

naming is an example.

@Exelord Exelord closed this as completed Jun 24, 2018
@Windvis
Copy link
Author

Windvis commented Jun 25, 2018

Yes, that is how I do it now. It would have been nice to not have to wrap it though, but fair enough.

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