Created
April 5, 2017 17:22
-
-
Save bfgeek/5914b69c79d390ea510eb9aa7bb74ca3 to your computer and use it in GitHub Desktop.
tasklet examples.
This file contains 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
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