Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
attributeBindings: 'style',
style: Ember.computed('color', function() {
let color = this.get('color');
return `width: 100px; height: 100px; background-color: ${color}`;
}),
color: 'red',
init() {
this._super();
if (this.get('autoStart')) {
this.get('colorAlternator').start();
}
},
colorAlternator: process(function * () {
let colors = ['red', 'blue', 'green'];
for (;;) {
for (let color of colors) {
this.set('color', color);
yield sleep(this.get('ms'));
}
}
}),
click() {
let process = this.get('colorAlternator');
if (process.isRunning) {
process.kill();
} else {
process.start();
}
import Ember from 'ember';
import { process, sleep } from 'ember-concurrency';
export default Ember.Component.extend({
innerProgressStyle: Ember.computed('progress', function() {
let width = Math.floor(this.get('progress') * 100);
return `width: ${width}%`;
}),
progress: 0,
status: "Ready",
results: null,
query: "csp",
wikiSearcher: process(function * (query) {
this.set('progress', 0.1);
let countdown = 4;
while (countdown--) {
this.set('status', `Gearing up for an AJAX query in ${countdown}`);
this.set('progress', this.get('progress') + 0.02);
yield sleep(1000);
}
this.set('status', `Performing AJAX query for ${query}...`);
this.set('progress', 0.5);
let encodedQuery = window.encodeURIComponent("query");
let url = `https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=${encodedQuery}&callback=?`;
let ajaxRequest = Ember.$.getJSON(url);
import Ember from 'ember';
import { process } from 'ember-concurrency';
let delay = (ms) => {
return new Ember.RSVP.Promise(r => {
Ember.run.later(r, ms);
});
};
export default Ember.Component.extend({
status: "Ready",
numInvocations: 0,
promiseHandler: process(function * (promise) {
try {
this.set('status', "Resolving a promise...");
let value = yield promise;
this.set('status', `OK, promise resolved with ${value}`);
} catch(e) {
this.set('status', `Oh no, it rejected with a value of ${e}`);
} finally {
this.incrementProperty('numInvocations');
}
}),
actions: {
doFulfillPromise() {
let promise = delay(1000).then(() => "HOORAY");
this.get('promiseHandler').start(promise);
},