Skip to content

Instantly share code, notes, and snippets.

@bfgeek
Created April 5, 2017 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bfgeek/5914b69c79d390ea510eb9aa7bb74ca3 to your computer and use it in GitHub Desktop.
Save bfgeek/5914b69c79d390ea510eb9aa7bb74ca3 to your computer and use it in GitHub Desktop.
tasklet examples.
api = await remote {
import B from 'b.js';
export class A {
constructor() { this.b = new B(); }
}
export function thing() {
}
}
var a = new api.A();
await api.thing();
api = await tasklet.import('api.js');
api = await tasklet.import(remote`
import B from 'b.js';
export class A {
constructor() { this.b = new B(); }
}
export function thing() {
}
`);
class Thingy {
constructor() {
}
async init() {
this.thingy = (await remote {
import SyncManager from 'sync.js'
export function thingy() {
return 42;
}
}).thingy;
}
}
api = await remote {
export class SyncManager extends EventTarget() { fetch() { dispatchEvent('fetchhappened'); } }
};
var sm = new api.SyncManager();
sm.addEventListener('fetchhappened', () => { /* update UI here */ });
api2 = await remote {
export function fetchImage(sm, imageURL) {
sm.fetch(imageURL);
}
}
imgData = await api2.fetchImage(sm, 'ponies.jpg');
imgNode.url = imgData;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment