Supervision of property in service from a route in EmberJS

I think I do not understand the concept here. As far as I know, anyone Ember.objectcan observe the properties on the other Ember.object.

So, I have a service, a router, and a component. I need a component and a router in order to be able to monitor the service property. It is possible that I am simply structuring the solution not so, I will talk about what I'm trying to do in the end.

Here is roughly what I have:

/services/thing-manager.js

export default Ember.Service.extend({
  observedProperty: 'original value'
});

/components/thing-shower.js

export default Ember.Component.extend({
  thingManager: Ember.inject.service(),
  myObserver: Ember.observer(
    'thingManager.observedProperty',
    function() {
      // This shows up as anticipated, unlike the one in the routes
      console.log('THING SHOWER COMPONENT observed change on thingManager')
    }
  ),
 actions: {
   changeObservedProperty: function() {
     let thingManager = this.get('thingManager')
     let newText = thingManager.get('observedProperty') + '!'
     // here i am sure to call `set` to make sure observers fire
     thingManager.set('observedProperty', newText)
   }
 }

});

/routes/things.js

export default Ember.Route.extend({
  thingManager: Ember.inject.service(),

  underObservation: Ember.observer('thingManager.observedProperty', function() {
    // This is what I expect to fire, but does not.
    console.log('THINGS ROUTE observed change on thingManager')
  }),
});

As you can see, I expect console output from both observers in the component and the router. Why is this not working?

Twiddle is here!

My common goals

, , , , , . " , ", . , json GPS .

, . . , , , , . .

, !

+4
1

things.js / thing-manager, .

/thing.js

init(){
    this._super(...arguments);
    this.get('thingManager');
},

.

, DDAU, thing-manager. .

. Ember.Object, , .

+3

Source: https://habr.com/ru/post/1681784/


All Articles