Last active
March 27, 2020 16:02
-
-
Save GreatWizard/a341f1aa9dea364c4057dff7d25cd796 to your computer and use it in GitHub Desktop.
promise-rendering
This file contains hidden or 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 Component from '@glimmer/component'; | |
import fetch from 'fetch'; | |
export default class GetPkmnComponent extends Component { | |
get getPokemon() { | |
let { model, forceReject } = this.args; | |
return fetch(`//pokeapi.co/api/v2/pokemon/${model}`).then(function(response) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
if (!forceReject && response.ok) { | |
resolve(response.json()); | |
} | |
reject("Oulalah!"); | |
}, 500); | |
}); | |
}); | |
} | |
} |
This file contains hidden or 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 GetPkmnComponent from './-get-pkmn'; | |
import { task } from 'ember-concurrency'; | |
export default class DemoConcurrency extends GetPkmnComponent { | |
taskPokemon = task(function*() { | |
yield this.getPokemon(); | |
}); | |
} |
This file contains hidden or 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 GetPkmnComponent from './-get-pkmn'; | |
export default class DemoEdc extends GetPkmnComponent { | |
} |
This file contains hidden or 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 GetPkmnComponent from './-get-pkmn'; | |
export default class DemoNative extends GetPkmnComponent { | |
} |
This file contains hidden or 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 GetPkmnComponent from './-get-pkmn'; | |
import { computed } from '@ember/object' | |
import ObjectProxy from '@ember/object/proxy'; | |
import PromiseProxyMixin from '@ember/object/promise-proxy-mixin'; | |
const ObjectPromiseProxy = ObjectProxy.extend(PromiseProxyMixin) | |
export default class DemoProxy extends GetPkmnComponent { | |
@computed('model', 'forceReject', 'getPokemon') | |
get proxy() { | |
let promise = this.getPokemon | |
return ObjectPromiseProxy.create({ | |
promise | |
}) | |
} | |
} |
This file contains hidden or 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 { tracked } from '@glimmer/tracking'; | |
import { action } from '@ember/object'; | |
export default class ApplicationController extends Controller { | |
@tracked value = 132; | |
@tracked forceReject = false; | |
@action | |
updateValue(event) { | |
this.value = event.target.value; | |
} | |
@action | |
updateReject(event) { | |
this.toggleProperty("forceReject"); | |
} | |
} |
This file contains hidden or 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 Application from '../app'; | |
import config from '../config/environment'; | |
import { setApplication } from '@ember/test-helpers'; | |
import { assign } from '@ember/polyfills'; | |
import { start } from 'ember-qunit'; | |
let attributes = { | |
rootElement: '#test-root', | |
autoboot: false | |
}; | |
attributes = assign(attributes, config.APP); | |
let application = Application.create(attributes); | |
setApplication(application); | |
start(); |
This file contains hidden or 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.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.16.3", | |
"ember-template-compiler": "3.16.3", | |
"ember-testing": "3.16.3" | |
}, | |
"addons": { | |
"@glimmer/component": "1.0.0", | |
"ember-fetch": "7.0.1", | |
"ember-deferred-content": "1.0.0", | |
"ember-concurrency": "1.1.6" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment