Created
October 26, 2018 10:50
-
-
Save jnv/8952cecc36cec33e2e4bbf63a34631aa to your computer and use it in GitHub Desktop.
BakeryJS Example Component (helloworld.js)
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
const {boxFactory} = require('bakeryjs'); | |
// Just a helper to throttle emitting | |
const {promisify} = require('util'); | |
const timeout = promisify(setTimeout); | |
module.exports = boxFactory( | |
'helloworld', | |
{ | |
provides: ['text'], | |
requires: [], | |
emits: ['text'], | |
aggregates: false, | |
}, | |
async function(serviceProvider, value, emit) { | |
emit([{text: 'Hello world!'}]); | |
await timeout(230); | |
emit([{text: 'This is a bit longer text'}, {text: 'Ahoj světe!'}]); | |
await timeout(150); | |
emit([{text: 'This text is shorter'}, {text: 'Bonjour monde!'}]); | |
await timeout(200); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment