I’m trying to create a service that has some private/scoped state. I’d like to expose this state as a readOnly or oneWay binding but I can’t seem to figure out how to do this unless the state object is part of the class, I.E like this:
init() {
var internalVal = obj.create();
this.__internalVal = internalVal;
this.publicAlias = Ember.computed.readOnly('__internalVal.internalValue');
}
This, of course, defeats the purpose if you can still access __internalVal.
What I ended up with was using an observer:
init() {
var self = this;
var internalVal = obj.create();
this.color = internalVal.get('internalValue');
internalVal.addObserver('internalValue', function(sender) {
self.set('color', sender.get('internalValue'));
});
this.setColor = function(colorName) {
internalVal.set('internalValue', colorName);
};
}
Is this the correct way to get the behavior i’m looking for, or is there some alternate syntax for computed that will allow me to do it using the macro? I tried having ‘obj’ declared a computed alias and then setting this.color to that property but it didn’t work right and or would only ever set it’s initial value.
Here’s a twiddle with the setup in case it’s not clear what I’m trying to do. Ember Twiddle