Created
November 29, 2017 13:37
-
-
Save matthias-k/c801b46983b761cfdaf9848f421bfc64 to your computer and use it in GitHub Desktop.
Nested Dependencies
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', | |
recordings: [{ | |
id: 'recording1', | |
recordingParts: ['a', 'b'], | |
}, { | |
id: 'recording2', | |
recordingParts: ['c', 'd'], | |
}], | |
recordingParts: Ember.computed('recordings.@each.recordingParts', function() { | |
const recordingParts = this.get('recordings').map(recording => Ember.get(recording, 'recordingParts')); | |
console.log("New RecParts", recordingParts); | |
return recordingParts; | |
}), | |
flatRecordingParts: Ember.computed('recordingParts.[]', function() { | |
console.log("new flat rec Parts"); | |
return this.get('recordingParts').toArray().reduce((a, b) => a.concat(b), []); | |
}), | |
interestingProperty: Ember.computed('flatRecordingParts', function() { | |
console.log("update interesting stuff"); | |
// without getting flatRecordingParts, interesting Property is not | |
// updated although I don't need it's actual value here here. | |
let foobar = this.get('flatRecordingParts'); | |
return this.get('recordings'); | |
}), | |
actions: { | |
buttonClicked() { | |
console.log("Click"); | |
const firstRecording = this.get('recordings')[0]; | |
Ember.set(firstRecording, 'recordingParts', ['e', 'f']); | |
}, | |
}, | |
}); |
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" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment