Declarativas API
Methods
Mutating the Canvas Context 2d Api
import { createMutator } from 'declarativas';
createMutator(ctx => ctx.fillRect(1, 1, 10, 10));
createMutator(ctx => {
ctx.fillStyle = 'green';
});Building Components
/**
* @jsx createElement
*/
import { createMutator, createElement } from 'declarativas';
const FillText = (props, children, context2d) => {
return [
createMutator((ctx) => { ctx.fillStyle = props.color; }),
createMutator((ctx) => ctx.fillText(props.text, props.x, props.y)),
];
}
// And to use the component:
createElement(FillText, { color: 'black', text: 'foo', x: 10, y: 10 });
// OR
<FillText color='black' text='foo' x={10} y={10} />Render components to the canvas
Built-in Components
Last updated