Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Array Proxy Infinite Loop
import Controller from '@ember/controller';
import ArrayProxy from "@ember/array/proxy"
import PromiseProxyMixin from "@ember/object/promise-proxy-mixin"
import { all } from "rsvp"
import { computed } from "@ember/object"
const ArrayPromiseProxy = ArrayProxy.extend(PromiseProxyMixin)
export default class ApplicationController extends Controller {
ids = [1, 2, 3]
// If you uncomment the @computed decorator, you won't get the infinite render.
// @computed("ids.[]")
get models(){
console.log("fetching models")
let promises = this.ids.map(id => {
return new Promise((resolve) => {
setTimeout(() => resolve(`document-${id}`), 10 * Math.random())
})
})
return ArrayPromiseProxy.create({
promise: all(promises)
})
}
}
{{#each this.models as |model| }}
{{model}}
{{/each}}
{
"version": "0.17.0",
"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.3.1/jquery.js",
"ember": "3.17.0",
"ember-template-compiler": "3.17.0",
"ember-testing": "3.17.0"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.