Skip to content

Instantly share code, notes, and snippets.

@YoranBrondsema
Last active May 6, 2021 08:27
Show Gist options
  • Save YoranBrondsema/adeebbcd184296522ba5537df8337ebd to your computer and use it in GitHub Desktop.
Save YoranBrondsema/adeebbcd184296522ba5537df8337ebd to your computer and use it in GitHub Desktop.
Alternative to observers in Ember.js with ember-concurrency
import { task, waitForProperty } from 'ember-concurrency';
import EmberObject from '@ember/object';
function waitForPropertyChange(object, prop) {
const curValue = object.get(prop);
return waitForProperty(object, prop, (newValue) => {
return newValue !== curValue;
});
}
EmberObject.extend({
differentObserver: task(function* () {
while(true) {
yield waitForPropertyChange(this, 'someProperty');
// do something
}
}).on('init')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment