Basically, our (new) project isn’t easily adaptable to Ember’s Models (from what we can gather). It seems like it would be a lot easier to store our data on an Observable object that we then inject wherever needed.
The problem is that Ember doesn’t detect updates to our data when it changes due to user input. The example in the SO question shows that we can’t simply set the data, because we don’t know the precise path from the service to the nested object that we want to update.
Would it be crazy to suggest making the path available to the action callbacks? I know of a similar library (Ractive) that makes the path (keypath) available on all events: http://docs.ractivejs.org/latest/proxy-events
I figured out that the use of Ember.A is not necessary - you can use a native array (so long as prototype extensions are allowed). But why is there no prototype extension for native objects?
Second question, I tried to use Ember.Object instead of arrays…but that doesn’t work either. Is Object not Observable?
I tried a trick wherein I take my native java object, and pass it as an argument to Ember.Object.create(). Here’s my code:
fix(obj) {
if(obj === null || typeof(obj) !== 'object') {
// Not an object, so just return it as-is
return obj;
}
// Just grab the own properties of the given object
var newObj = {};
for(var prop in obj) {
if(!obj.hasOwnProperty(prop)) {
continue;
}
newObj[prop] = this.fix(obj[prop]);
}
// Now, convert to an Ember object
return Ember.Object.create(
newObj
);
}
Actually the code should dig into Arrays, but for my toy example I just have objects. But this doesn’t work either. Nor does it work if I make newObj an empty Ember.Object and set the properties using newObj.set(prop, this.fix(obj[prop])).
I figured that I must have misunderstood your comment. When you said “predefined”, I guess you meant that I have to extend Object and tell it what properties I need, not just create new ones with dynamic properties. So, I tried the following:
Basically, the critService is used by two (nearly identical) Components.
The Crits are Ember objects.
The “change” button doesn’t work - it changes the value, but the view does not update.