I'm not sure whether the issue I'm dealing with is related to this addon, or plain ember practice, anyway:
I'm using the addon on two controllers (Application and a specific one called Employee) and is used to manage and display specific settings:
From the Employee controller one can save an employee-ID into localStorage. You can see your actions 'live' at the related template when setting and unsetting this employee.
The application template displays the name of your chosen employee (through a service), but doesn't change 'live' when the Employee controller sets / unsets an employee...
Here's my code:
/controllers/application.js
import Ember from 'ember';
import Settings from 'my-app/models/settings';
export default Ember.Controller.extend({
settings : Settings.create(),
myContact : null,
myContactService : Ember.inject.service('my-contact'),
myContactUpdater : Ember.observer('settings.myContact_employeeID', function() {
var self = this;
this.get('myContactService').retrieve()
.then(function(employee){
self.set('myContact', employee);
});
}),
init: function () {
this.myContactUpdater();
}
});
/controllers/employees/single.js
import Ember from 'ember';
export default Ember.Controller.extend({
// myContactService: Ember.inject.service('my-contact'),
application: Ember.inject.controller('application'),
settings: Ember.computed.alias('application.settings'),
isMyContact: function() {
return this.model.id == this.get('settings.myContact_employeeID');
}.property('settings.myContact_employeeID', 'this.model.id'),
actions: {
'setMyContact': function (employee_id) {
this.set('settings.myContact_employeeID', employee_id);
},
'removeMyContact': function () {
this.set('settings.myContact_employeeID', null);
}
}
});
services/my-contact.js
import Ember from 'ember';
import Settings from 'my-app/models/settings';
export default Ember.Service.extend({
store : Ember.inject.service(),
settings: Settings.create(),
/**
* Returns a Promise
*/
retrieve: function() {
var employee_id = this.get('settings.myContact_employeeID');
if( employee_id ) {
// return promise
// for fetchById
// on Employee model
return this.get('store').fetchById('employee', employee_id);
}
else{
// return promise
// with Null param
return new Ember.RSVP.Promise(function(resolve, reject) {
resolve(null);
});
}
}
});