Last active
December 30, 2015 15:17
-
-
Save workmanw/9caf25254d6d35c436c2 to your computer and use it in GitHub Desktop.
New 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'; | |
const DEFAULT_MODEL = { | |
relationship: { | |
isFulfilled: false, | |
someValue: false | |
} | |
} | |
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle', | |
model: Ember.copy(DEFAULT_MODEL, true), | |
actions: { | |
changeModel() { | |
this.set('model', Ember.copy(DEFAULT_MODEL, true)); | |
} | |
} | |
}); |
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
// app/helpers/async-value.js | |
import Ember from 'ember'; | |
const { | |
get, | |
addObserver, | |
removeObserver | |
} = Ember; | |
export default Ember.Helper.extend({ | |
installObserver(relationship, key) { | |
if(this._installObsRelationship !== relationship || this._installObsKey !== key) { | |
this.uninstallObserver(); | |
this._installObsRelationship = relationship; | |
this._installObsKey = key; | |
addObserver(this._installObsRelationship, this._installObsKey, this, this.recompute); | |
addObserver(this._installObsRelationship, 'isFulfilled', this, this.recompute); | |
} | |
}, | |
uninstallObserver() { | |
if(this._installObsRelationship && this._installObsKey) { | |
removeObserver(this._installObsRelationship, this._installObsKey, this, this.recompute); | |
removeObserver(this._installObsRelationship, 'isFulfilled', this, this.recompute); | |
this._installObsRelationship = null; | |
this._installObsKey = null; | |
} | |
}, | |
willDestroy() { | |
this.uninstallObserver(); | |
}, | |
compute([asyncRelationship, key], hash) { | |
this.installObserver(asyncRelationship, key); | |
return asyncRelationship && !get(asyncRelationship, key) && get(asyncRelationship, 'isFulfilled'); | |
} | |
}); |
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.4.17", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment