Data will be collected automatically
Create data collector
Basic usage
using dc = await app.collector('data.csv');
dc.add({ name: 'Alice', age: 25 });
dc.add({ name: 'Bob', age: 30 });
dc.final(); // get final text
dc.download(); // download data.csv
Add listeners
using dc = await app
.collector('data.csv')
.on('add', (row) => {
console.log('add a row', row);
})
.on('chunk', (chunk) => {
console.log('a chunk of raw is ready', chunk);
});
Create a scene
Create text scene
const setup = (props: { text: string }, ctx: Scene<any>) => {
const el = document.createElement('div');
ctx.on('scene:show', (props) => {
el.textContent = props.text; // update element
});
return { node: el, data: () => ({ text: el.textContent }) }; // return element and data getter
};
// create scene by setup function
using scene = app.scene(setup, {
defaultProps: { text: 'default text' }, // default props is required
close_on: 'key: ', // close when space is pressed
duration: 100, // auto close after 100ms
});
// change props.text and show, then get data
const data = await scene.show({ text: 'new text' });
Root element of the app