[deprecations] Don't use before observer

This commit is contained in:
Piotr Sarnacki 2016-01-07 11:58:13 +01:00
parent 85b2837c52
commit f9df4b1896
2 changed files with 25 additions and 16 deletions

View File

@ -3,6 +3,12 @@ import Ember from 'ember';
export default Ember.Mixin.create({
polling: Ember.inject.service(),
init() {
this.set('currentPollModels', {});
return this._super(...arguments);
},
didInsertElement() {
this._super.apply(this, arguments);
return this.startPolling();
@ -17,16 +23,20 @@ export default Ember.Mixin.create({
return this.pollModel(key);
},
pollModelWillChange(sender, key, value) {
return this.stopPollingModel(key);
},
pollModel(property) {
var addToPolling, model;
addToPolling = () => {
var model = this.get(property),
currentPollModels = this.get('currentPollModels');
if(currentPollModels[property]) {
this.get('polling').stopPolling(currentPollModels[property]);
}
currentPollModels[property] = model;
var addToPolling = () => {
return this.get('polling').startPolling(model);
};
if (model = this.get(property)) {
if (model) {
if (model.then) {
return model.then(function(resolved) {
return addToPolling(resolved);
@ -38,8 +48,8 @@ export default Ember.Mixin.create({
},
stopPollingModel(property) {
var model;
if (model = this.get(property)) {
var model = this.get(property);
if (model) {
return this.get('polling').stopPolling(model);
}
},
@ -54,7 +64,6 @@ export default Ember.Mixin.create({
pollModels.forEach( (property) => {
this.pollModel(property);
this.addObserver(property, this, 'pollModelDidChange');
return Ember.addBeforeObserver(this, property, this, 'pollModelWillChange');
});
}
if (this.pollHook) {
@ -63,15 +72,15 @@ export default Ember.Mixin.create({
},
stopPolling() {
var pollModels;
if (pollModels = this.get('pollModels')) {
var pollModels = this.get('pollModels');
if (pollModels) {
if (!Ember.isArray(pollModels)) {
pollModels = [pollModels];
}
pollModels.forEach( (property) => {
this.stopPollingModel(property);
this.removeObserver(property, this, 'pollModelDidChange');
return Ember.removeBeforeObserver(this, property, this, 'pollModelWillChange');
});
}
return this.get('polling').stopPollingHook(this);

View File

@ -16,13 +16,13 @@ window.deprecationWorkflow.config = {
{ handler: "log", matchMessage: "Using the same function as getter and setter is deprecated." },
{ handler: "log", matchMessage: "`Ember.ArrayController` is deprecated." },
{ handler: "log", matchMessage: "The default behavior of `shouldBackgroundReloadRecord` will change in Ember Data 2.0 to always return true. If you would like to preserve the current behavior please override `shouldBackgroundReloadRecord` in your adapter:application and return false." },
{ handler: "log", matchMessage: "Function#observesBefore is deprecated and will be removed in the near future." },
{ handler: "log", matchMessage: "Ember.addBeforeObserver is deprecated and will be removed in the near future." },
{ handler: "log", matchMessage: "Ember.removeBeforeObserver is deprecated and will be removed in the near future." },
// TODO
{ handler: "silence", matchMessage: "Ember.View is deprecated. Consult the Deprecations Guide for a migration strategy." },
{ handler: "silence", matchMessage: "The filter API will be moved into a plugin soon. To enable store.filter using an environment flag, or to use an alternative, you can visit the ember-data-filter addon page" },
{ handler: "silence", matchMessage: "Function#observesBefore is deprecated and will be removed in the near future." },
{ handler: "silence", matchMessage: "Ember.addBeforeObserver is deprecated and will be removed in the near future." },
{ handler: "silence", matchMessage: "Ember.removeBeforeObserver is deprecated and will be removed in the near future." },
{ handler: "silence", matchMessage: "Using DS.Snapshot.get() is deprecated. Use .attr(), .belongsTo() or .hasMany() instead." },
]
};