Closed ouronghuang closed 4 years ago
Thanks for the question! You should never use the SVGParentView
constructor directly – instead, you can do something like const $svg = $N('svg')
which is a shortcut for document.createElement()
.
The observer()
function takes an object as argument, which contains the initial state of the model, and .bindModel()
should only be called a single time for every DOM element.
For example, something like this:
<svg id="canvas"><circle :cx="point.x" :cy="point.y" r="20"/></svg>
const $svg = $('#canvas'); // Select the <svg>
const model = observer({point: new Point(10, 10)});
$svg.bindModel(model);
model.point = new Point(20, 20); // position of the <circle> will automatically change
You can have a look at https://github.com/mathigon/boost.js/blob/master/src/elements.ts for the source code, and we are working on some additional documentation.
Thank you so much!
Codes:
How do I understand
$step.model.rad
,$step.model.a
and$step.model.b
?When I try write that:
So what can I bind model for myself?