UNPKG

668 BJavaScriptView Raw
1//
2// d3-on directive
3//
4// A one-way data binding from dom events to model properties/methods
5// Event listeners are on the DOM, not on the model
6export default {
7 mount(model) {
8 var eventName = this.arg || "click",
9 expr = this.expression;
10
11 // DOM event => model binding
12 this.on(this.sel, `${eventName}.${this.uid}`, event => {
13 var md = model.$child();
14 md.$event = event;
15 expr.eval(md);
16 });
17
18 this.bindDestroy(model);
19 // Does not return the model so that model data binding is not performed
20 },
21
22 destroy() {
23 var eventName = this.arg || "click";
24 this.on(this.sel, `${eventName}.${this.uid}`, null);
25 }
26};