Last active
May 9, 2016 21:24
-
-
Save alexgb/4199d0eef326a5d22ac26f446dc710de 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'; | |
import DS from 'ember-data'; | |
function delayedResolveWith(obj) { | |
return new Ember.RSVP.Promise(function(resolve, reject) { | |
window.setTimeout(resolve.bind(null, obj), 1000); | |
}); | |
} | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
items: null, | |
init() { | |
this._super(...arguments); | |
Ember.set(this, 'items', [{ | |
nested : DS.PromiseObject.create({ | |
promise: delayedResolveWith({ id: '123' }) | |
}), | |
nestedId: Ember.computed.reads('nested.id') | |
}, { | |
nested : DS.PromiseObject.create({ | |
promise: delayedResolveWith({ id: '234' }) | |
}), | |
nestedId: Ember.computed.reads('nested.id') | |
}, { | |
nested : DS.PromiseObject.create({ | |
promise: delayedResolveWith({ id: '345' }) | |
}) | |
}]); | |
}, | |
itemsWithNestedId: Ember.computed('items.@each.nested', function() { | |
return Ember.get(this, 'items').map((item) => { | |
return { | |
nested: Ember.get(item, 'nested'), | |
nestedId: Ember.computed.reads('nested.id') | |
}; | |
}); | |
}), | |
allIds: Ember.computed('itemsWithNestedId.@each.nestedId', function() { | |
return Ember.get(this, 'itemsWithNestedId').mapBy('nestedId').join(', '); | |
}) | |
}); |
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.8.0", | |
"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.5.1", | |
"ember-data": "2.5.2", | |
"ember-template-compiler": "2.5.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment