Last active
January 28, 2016 19:08
-
-
Save jerel/1523fd2fae4a21c261d7 to your computer and use it in GitHub Desktop.
Ember unloadRecord doesn't remove observers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
beforeModel: function() { | |
this.store.push({ | |
data: { | |
type: 'event', | |
id: 1, | |
attributes: { | |
name: 'test', | |
} | |
} | |
}); | |
}, | |
model: function() { | |
return this.store.peekAll('event'); | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Service.extend({ | |
init: function() { | |
var self = this; | |
console.log('clock started'); | |
window.setInterval(function() { | |
self.incrementProperty('tick'); | |
}, 1000); | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
clock: Ember.inject.service(), | |
name: DS.attr(), | |
ticks: Ember.computed('clock.tick', function() { | |
return this.get('clock.tick'); | |
}), | |
// this is a way of removing stale models after a certain time period has passed | |
aging: Ember.observer('clock.tick', function() { | |
console.log(this.get('clock.tick')); | |
if (this.get('clock.tick') > 5) { | |
// manually removing observer fixes the issue | |
// this.removeObserver('clock.tick'); | |
this.unloadRecord(this); | |
console.log('record unloaded, observer should stop now'); | |
} | |
}), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.5.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "canary", | |
"ember-data": "canary", | |
"ember-template-compiler": "canary" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment