Last active
May 6, 2021 08:27
-
-
Save YoranBrondsema/adeebbcd184296522ba5537df8337ebd to your computer and use it in GitHub Desktop.
Alternative to observers in Ember.js with ember-concurrency
This file contains hidden or 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 { 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