Last active
February 10, 2017 17:19
-
-
Save machty/3284ef4a446468ee8f34dff019d8443f 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'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember 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 Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
Ember.computed.async = function (...args) { | |
// Remove computed function to call later | |
const func = args.pop(); | |
// Add new custom computed function that returns promise proxy | |
args.push(function(propName) { | |
// Call original computed function | |
const promise = Ember.RSVP.resolve().then(() => func.call(this, propName)); | |
const ObjectPromiseProxy = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin); | |
return ObjectPromiseProxy.create({ | |
promise: promise, | |
}); | |
}); | |
return Reflect.apply(Ember.computed, this, args); | |
}; | |
Ember.computed.async.prorotype = Ember.computed.prototype; | |
export default Model.extend({ | |
name: attr('string'), | |
promise: Ember.computed('name', () => { | |
const name = this.get('name'); | |
const promise = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(name); | |
}, 1000); | |
}); | |
return promise; | |
}), | |
asyncComputed: Ember.computed.async('promise', () => { | |
console.log(arguments); | |
console.log(this); | |
}), | |
}); |
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.Route.extend({ | |
model() { | |
return this.get('store').createRecord('application', { | |
name: "Alex", | |
}); | |
} | |
}); |
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.11.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.10.2", | |
"ember-data": "2.11.0", | |
"ember-template-compiler": "2.10.2", | |
"ember-testing": "2.10.2" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment