Please see below sample code. Given I have a component my-text-box
my-text-box.hbs
I want to observe the changes of value
property via didReceiveAttrs
hook instead of observers
for better performance.
my-text-box.js
didReceiveAttrs: function(args) {
if (args.oldAttrs == null) {
// This is the initial render, but I don't need to anything here.
} else if (args.newAttrs.value != args.oldAttrs.value) {
// supposed `value` was changed from outside, I can do something here...
// BUT, `args.newAttrs.value` is not always the prop value,
// `Ember` would automatically wrap it with `` helper.
// The data structure would be:
// {
// value: value,
// update: function (val) {
// source.setValue(val);
// }
// }
}
}
What I want is that I don't have to care whether the attr value is a mutable
cell or not, I should get a way that always get the real value. I see there is a HTMLBars hook
ember-htmlbars/hooks/get-value
but it's not exposed to public API. And what I'm thinking is that maybe Ember
should change both newAttrs
and oldAttrs
to have direct values instead of those mutable
objects.
Does anybody have a way to handle that? Thanks!
Aucun commentaire:
Enregistrer un commentaire