Created
May 13, 2016 20:49
-
-
Save chandlerkent/f7fce468bb0183eb8fe0166ce620f8df to your computer and use it in GitHub Desktop.
ember-parent-child-select-promise
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 ObjectPromiseProxy = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin); | |
export default Ember.Controller.extend({ | |
storeInventoryItems: Ember.inject.service(), | |
appName: 'Ember Twiddle', | |
stores: [ | |
{id: 1, displayName: 'rob'}, | |
{id: 2, displayName:'chandler'} | |
], | |
selectedStoreIndex: 0, | |
selectedInvItemIndex: 0, | |
inventoryItems: function() { | |
var stores = this.get('stores'); | |
if (stores.get('length') === 0) { | |
return []; | |
} | |
var store = this.get('stores').objectAt(this.get('selectedStoreIndex')); | |
var storeId = store.id; | |
var inventoryPromise = this.get('storeInventoryItems') | |
.getInventoryItemsForStore(storeId) | |
.then(function (items) { return { items }; }); | |
return ObjectPromiseProxy.create({ | |
promise: inventoryPromise | |
}); | |
}.property('selectedStoreIndex', 'stores') | |
}); |
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 function isEq(params/*, hash*/) { | |
return params[0] === params[1]; | |
} | |
export default Ember.Helper.helper(isEq); |
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.Service.extend({ | |
getInventoryItemsForStore: function(storeId) { | |
var that = this; | |
return new Ember.RSVP.Promise(function(resolve, reject) { | |
Ember.run.later(function () { | |
if (storeId === 1) { | |
resolve([{id:33, name:'shaw'}]); | |
} else if (storeId === 2) { | |
resolve([{id:33, name:'kent'}]); | |
} else { | |
resolve([]); | |
} | |
}, randomNumberOfMilliseconds()); | |
}); | |
} | |
}); | |
function randomNumberOfMilliseconds() { | |
return Math.random() * (1000 - 150) + 150; | |
} |
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.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.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