Last active
April 8, 2016 19:35
-
-
Save trabus/4a05098ac1df27b6ffa0252706dc0182 to your computer and use it in GitHub Desktop.
Funky Computed Property
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 Ember from 'ember'; | |
const {Component, computed} = Ember; | |
export default Component.extend({ | |
mything: null, | |
// thing value is also passed into the component | |
// thing watches no keys, and is not consumed | |
thing: computed({ | |
// the getter is ignored entirely | |
set(k, v) { | |
// do any amount of work here | |
// could replace observer | |
console.log('do a mything'); | |
//affect other property on change | |
this.set('mything', v); | |
return v; | |
} | |
}), | |
actions: { | |
setmything(val) { | |
this.set('mything', val); | |
} | |
} | |
}); |
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 Ember from 'ember'; | |
const {Controller, computed} = Ember; | |
export default Controller.extend({ | |
appName: 'Ember Twiddle', | |
thing: computed({ | |
get() { | |
// default | |
console.log('thing get'); | |
return 'nothing'; | |
}, | |
set(k, v) { | |
// do something when the value changes | |
console.log('do a thing'); | |
return v; | |
} | |
}), | |
actions: { | |
reset() { | |
this.set('thing', 'nothing'); | |
}, | |
setThing(val) { | |
console.log('setting thing'); | |
this.set('thing', val); | |
} | |
} | |
}); |
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
{ | |
"version": "0.7.2", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment