-
Notifications
You must be signed in to change notification settings - Fork 6
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
Supporting didUpdateAttrs
#4
Comments
The mixin approach works great, here's the WIP API that I'm using: import Ember from 'ember';
import DidChangeAttrs from 'ember-did-change-attrs';
export default Ember.Component.extend(DidChangeAttrs, {
didChangeAttrsConfig: {
attrs: ['email', 'isAdmin']
},
didChangeAttrs(changes) {
if(changes.email) {
console.log('email previous', changes.email.previous);
console.log('email current', changes.email.current);
}
}
}); |
WIP PR: #5 |
For comparison: Current API: import diffAttrs from 'ember-diff-attrs';
export default Ember.Component.extend({
didReceiveAttrs: diffAttrs('email', 'isAdmin', function(changedAttrs, ...args) {
this._super(...args);
if(changedAttrs && changedAttrs.email) {
let oldEmail = changedAttrs.email[0],
newEmail = changedAttrs.email[1];
// Do stuff
}
})
}); New API (which works with both import DidChangeAttrs from 'ember-did-change-attrs';
export default Ember.Component.extend(DidChangeAttrs, {
didChangeAttrsConfig: {
attrs: ['email', 'isAdmin']
},
didChangeAttrs(changes) {
if(changes.email) {
let oldEmail = changes.email.previous,
newEmail = changes.email.current;
// Do stuff
}
}
}); (hopefully we can come up with a better name than |
@workmanw, a couple of (possibly controversial) thoughts:
|
@GavinJoyce I'd like to know if anyone else (who might be lurking 👀) would feel about that. I understand the goal of that change would be to only have one way to do use it. I'm a little hesitant to go whole-hog and do away with the decorator approach because I genuinely think there are a lot of people against Mixins. Again, I'm not one of them, had I just written this for myself (and not as an Addon) I would have reached for a Mixin solution. Maybe the best option would be for us to create a new addon Thoughts? |
Sounds like a good approach to me, thanks |
@GavinJoyce I'm on it. Hold tight. |
@GavinJoyce et al, done! ember-did-change-attrs is now a bootstrapped addon. I'm happy to continue collaborating over there. I'll open an issue and cross link it. |
Having the addon only support
didReceiveAttrs
makes it much less valuable as it's only a partial solution to attribute change tracking and leaves consuming app having to implement their own tracking logic when they are interested in changes indidUpdateAttrs
.I'm interested in helping to explore how this addon might support
didUpdateAttrs
as well as the currently supporteddidReceiveAttrs
(see emberjs/rfcs#191 (comment) for some context).I'm just beginning to look into it now, I'm creating this issue to track any conversation or progress.
/cc @workmanw
The text was updated successfully, but these errors were encountered: