Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
baz: task(function * () {
let val = yield waitForProperty(this, 'bazValue', (v) => v % 2 === 0);
yield timeout(500);
this.set('state', `${this.state} Baz got even value ${val}.`);
}),
// END-SNIPPET
let onUp = () => {
this._waitForDragStart.cancelAll();
};
// give preference to native drag/drop handlers
let onHtmlDrag = () => {
this._waitForDragStart.cancelAll();
};
// register local events
document.addEventListener('mousemove', onMove, {passive: false});
document.addEventListener('mouseup', onUp, {passive: false});
document.addEventListener('drag', onHtmlDrag, {passive: false});
try {
yield waitForProperty(this, '_dragStartConditionsMet');
} finally {
// finally is always called on task cancellation
this.set('_dragStartConditionsMet', false);
document.removeEventListener('mousemove', onMove, {passive: false});
document.removeEventListener('mouseup', onUp, {passive: false});
document.removeEventListener('drag', onHtmlDrag, {passive: false});
}
}).keepLatest(),
performSearch: task(function* (term) {
if (isBlank(term)) {
return [];
}
// start loading immediately in the background
this.refreshContent.perform();
// debounce searches to 200ms to avoid thrashing CPU
yield timeout(200);
// wait for any on-going refresh to finish
if (this.refreshContent.isRunning) {
yield waitForProperty(this, 'refreshContent.isIdle');
}
// set dependent CP term and re-calculate CP
this.set('currentSearch', term);
return this.groupedContent;
}).restartable(),
getIndex: task(function* (name) {
if (this.keys[name]) {
return this.keys[name];
} else if (this.getKeys.isRunning) { // eslint-disable-line no-else-return
yield waitForProperty(this, 'keys', k => Object.keys(k).length > 0);
} else {
const keys = yield this.getKeys.perform();
this.set('keys', keys);
}
const info = this.keys[name];
if (isEmpty(info)) { return null; }
const client = algoliasearch(config.algolia.appId, info.key);
const index = client.initIndex(info.index);
this.keys[name] = index;
return index;
})
});
bar: task(function * () {
yield waitForProperty(this, 'foo.isIdle');
this.set('state', `${this.state} Foo is idle.`);
yield timeout(500);
this.set('bazValue', 42);
this.set('state', `${this.state} Bar.`);
}),
async init() {
this._super(arguments);
if (this.web3.provider && this.web3.provider.isMetaMask) {
await waitForProperty(this, 'isWeb3Loaded');
let address = this.web3.address;
await this.getPortfolio.perform(address);
}
this.set('loadingAssets', false);
},