Last active
February 3, 2021 06:11
-
-
Save Kilowhisky/4a4344310f79688a836b8f6fb4b57f11 to your computer and use it in GitHub Desktop.
Issue with ObjectPromiseProxy
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 Controller from '@ember/controller'; | |
import { computed } from '@ember/object'; | |
import { ObjectPromiseProxy, resolvingPromise, resultObject } from '../utils/object-proxy'; | |
export default class ApplicationController extends Controller { | |
regularObject = resultObject; | |
//@computed() // uncomment this to get it to work 'somehow' | |
get promiseObj() { | |
return ObjectPromiseProxy.create({ | |
promise: resolvingPromise(resultObject) | |
}); | |
} | |
get promiseObjQuick() { | |
return ObjectPromiseProxy.create({ | |
promise: resolvingPromise(resultObject, 0) | |
}); | |
} | |
// This is really to support something like this | |
// Which cannot be in a route model hook | |
// get myModel() { | |
// return this.store.findRecord('model', 1); | |
//} | |
// If i happened to be using an array ember-data has a solution that works | |
// instances: computed('userIds.[]', function () { | |
// return DS.PromiseArray.create({ | |
// promise: all(this.userIds.map(u => this.store.find('user', u))) | |
// }); | |
// }), | |
} |
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 Controller from '@ember/controller'; | |
import { computed } from '@ember/object'; | |
import { ObjectPromiseProxy, resolvingPromise, resultObject } from '../utils/object-proxy'; | |
export default Controller.extend({ | |
regularObject: resultObject, | |
promiseObj: computed(function() { | |
return ObjectPromiseProxy.create({ | |
promise: resolvingPromise(resultObject) | |
}); | |
}), | |
promiseObjQuick: computed(function() { | |
return ObjectPromiseProxy.create({ | |
promise: resolvingPromise(resultObject, 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
{ | |
"version": "0.17.1", | |
"EmberENV": { | |
"FEATURES": {}, | |
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": false, | |
"_APPLICATION_TEMPLATE_WRAPPER": true, | |
"_JQUERY_INTEGRATION": true | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.js", | |
"ember": "3.18.1", | |
"ember-template-compiler": "3.18.1", | |
"ember-testing": "3.18.1" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.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 ObjectProxy from '@ember/object/proxy'; | |
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin'; | |
import EmberObject from '@ember/object'; | |
import { Promise } from 'rsvp'; | |
import { later } from '@ember/runloop'; | |
export const ObjectPromiseProxy = ObjectProxy.extend(PromiseProxyMixin); | |
export const resultObject = EmberObject.create({ | |
name: 'loaded' | |
}); | |
export function resolvingPromise(result, timeout = 5000) { | |
return new Promise(resolve => { | |
later(this, () => resolve(result), timeout); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment