1 | import types from "./types/index";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export default {
|
9 | create(expression) {
|
10 | var type = this.sel.attr("type"),
|
11 | tag = this.el.tagName.toLowerCase(),
|
12 | ValueType = types[type] || types[tag];
|
13 |
|
14 | if (!ValueType) {
|
15 | this.logWarn(`Cannot apply d3-value directive to ${tag}`);
|
16 | return;
|
17 | }
|
18 | this.tag = new ValueType(this.el);
|
19 | return expression;
|
20 | },
|
21 |
|
22 | mount(model) {
|
23 | var expr = this.expression;
|
24 |
|
25 | if (expr.parsed.type !== expr.codes.IDENTIFIER) {
|
26 | this.logWarn(
|
27 | `support identifiers only, got "${expr.parsed.type}": ${
|
28 | this.expression
|
29 | }`
|
30 | );
|
31 | return;
|
32 | }
|
33 | var attrName = this.expression.expr;
|
34 |
|
35 |
|
36 | model.$set(attrName, this.tag.value());
|
37 | // register dom event
|
38 | this.tag.on(model, attrName);
|
39 | return model;
|
40 | },
|
41 |
|
42 | refresh(model, value) {
|
43 | this.tag.value(value);
|
44 | },
|
45 |
|
46 | destroy(model) {
|
47 | this.tag.off(model);
|
48 | }
|
49 | };
|