Created
April 26, 2017 21:10
-
-
Save alexander-alvarez/3d4130fea587ebb38dccc6bc15460ff8 to your computer and use it in GitHub Desktop.
Derived state
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'; | |
import {task, timeout} from 'ember-concurrency'; | |
const { computed } = Ember; | |
export default Ember.Component.extend({ | |
requiredInputA: null, | |
requiredInputB: null, | |
hasRequiredInputA: computed.bool('requiredInputA'), | |
hasRequiredInputB: computed.bool('requiredInputB.length'), | |
hasValidInputs: computed.and('hasRequiredInputA', 'hasRequiredInputB'), | |
taskInstance: computed('requiredInputB.[]', 'requiredInputA', function(){ | |
return this.get('task').perform(); | |
}), | |
task: task(function * () { | |
this.incrementProperty('counter'); | |
yield timeout(1000); | |
return [this.get('requiredInputA'), ...this.get('requiredInputB')]; | |
}).keepLatest(), | |
// for demo purposes | |
counter: 0 | |
}); |
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', | |
foo: null, | |
bar: null, | |
actions : { | |
addInputs(){ | |
this.set('foo', 'abc'); | |
this.set('bar', [1, 2]); | |
}, | |
addAnother() { | |
this.get('bar').pushObject('z'); | |
} | |
} | |
}); |
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.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-data": "2.12.1", | |
"ember-truth-helpers": "*", | |
"ember-concurrency": "*" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment