diff --git a/demo/js/config/fix.js b/demo/js/config/fix.js index 974671759..65a38c144 100644 --- a/demo/js/config/fix.js +++ b/demo/js/config/fix.js @@ -86,6 +86,26 @@ Demo.FIX_CONFIG = [{ }, { id: 71, pId: 7, - text: "fix框架", + text: "定义响应式数据", + value: "demo.fix1" +}, { + id: 72, + pId: 7, + text: "计算属性", + value: "demo.fix2" +}, { + id: 73, + pId: 7, + text: "store", + value: "demo.fix3" +}, { + id: 74, + pId: 7, + text: "watcher表达式", + value: "demo.fix4" +}, { + id: 75, + pId: 7, + text: "一个混合的例子", value: "demo.fix" }]; \ No newline at end of file diff --git a/demo/js/fix-2.0/computed.js b/demo/js/fix-2.0/computed.js new file mode 100644 index 000000000..347dae96b --- /dev/null +++ b/demo/js/fix-2.0/computed.js @@ -0,0 +1,52 @@ +;(function(){ + var model = Fix.define({ + name: "原始属性", + arr: [{ + n: 'a' + }, { + n: 'b' + }] + }); + var Computed = BI.inherit(Fix.VM, { + computed: { + b: function () { + return this.name + "-计算属性" + } + } + }) + + Demo.Fix = BI.inherit(BI.Widget, { + _store: function () { + return new Computed(model); + }, + watch: { + b: function () { + this.button.setText(this.model.b) + } + }, + render: function () { + var self = this; + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.button", + ref: function () { + self.button = this; + }, + handler: function () { + self.model.name = "这是改变后的属性" + }, + text: this.model.b + } + }] + } + }, + mounted: function () { + + + } + }); + + BI.shortcut("demo.fix2", Demo.Fix); +}()); \ No newline at end of file diff --git a/demo/js/fix-2.0/define.js b/demo/js/fix-2.0/define.js new file mode 100644 index 000000000..ef7ebcacc --- /dev/null +++ b/demo/js/fix-2.0/define.js @@ -0,0 +1,45 @@ +;(function () { + var model = Fix.define({ + name: "原始属性", + arr: [{ + n: 'a' + }, { + n: 'b' + }] + }); + + Demo.Fix = BI.inherit(BI.Widget, { + _store: function () { + return model; + }, + watch: { + name: function () { + this.button.setText(this.model.name) + } + }, + render: function () { + var self = this; + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.button", + ref: function () { + self.button = this; + }, + handler: function () { + self.model.name = "这是改变后的属性" + }, + text: this.model.name + } + }] + } + }, + mounted: function () { + + + } + }); + + BI.shortcut("demo.fix1", Demo.Fix); +}()); diff --git a/demo/js/fix-2.0/demo.js b/demo/js/fix-2.0/demo.js index f6d30bd71..fb946f8db 100644 --- a/demo/js/fix-2.0/demo.js +++ b/demo/js/fix-2.0/demo.js @@ -1,55 +1,75 @@ -var model = Fix.define({ - name: 1, - arr: [{ - n: 'a' - }, { - n: 'b' - }] -}); -Demo.Computed = BI.inherit(Fix.VM, { - computed: { - b: function () { - return this.name + 1 - }, - c: function () { - return this.arr[1].n + this.b +;(function () { + var model = Fix.define({ + name: 1, + arr: [{ + n: 'a' + }, { + n: 0 + }] + }); + var Computed = BI.inherit(Fix.VM, { + computed: { + b: function () { + return this.name + 1 + }, + c: function () { + return this.arr[1].n + this.b + } } - } -}) + }) -Demo.Store = BI.inherit(Fix.VM, { - _init: function () { - this.comp = new Demo.Computed(model).model; - }, - computed: { - b: function () { - return this.comp.c + 1 + var Store = BI.inherit(Fix.VM, { + _init: function () { + this.comp = new Computed(model).model; }, - c: function () { - return this.comp.name - } - }, - actions: { - run: function () { - this.comp.name = 2; - this.comp.arr[1].n = "c" + computed: { + b: function () { + return this.comp.c + 1 + }, + c: function () { + return this.comp.arr[1].n & 1; + } + }, + actions: { + run: function () { + this.comp.name++; + this.comp.arr[1].n++; + } } - } -}); + }); -Demo.Fix = BI.inherit(BI.Widget, { - _store: function () { - return new Demo.Store(); - }, - watch: { - "b&&c||b": function () { - debugger; - } - }, - mounted: function () { + Demo.Fix = BI.inherit(BI.Widget, { + _store: function () { + return new Store(); + }, + watch: { + "b&&(c||b)": function () { + this.button.setText(this.model.b) + } + }, + render: function () { + var self = this; + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.button", + ref: function () { + self.button = this; + }, + handler: function () { + self.store.run() + }, + text: this.model.b + } + }] + } + }, + mounted: function () { - this.store.run() - } -}); -BI.shortcut("demo.fix", Demo.Fix); \ No newline at end of file + } + }); + + BI.shortcut("demo.fix", Demo.Fix); +}()); \ No newline at end of file diff --git a/demo/js/fix-2.0/store.js b/demo/js/fix-2.0/store.js new file mode 100644 index 000000000..30c93e203 --- /dev/null +++ b/demo/js/fix-2.0/store.js @@ -0,0 +1,60 @@ +;(function(){ + var model = Fix.define({ + name: "原始属性", + arr: [{ + n: 'a' + }, { + n: 'b' + }] + }); + + var Store = BI.inherit(Fix.VM, { + _init: function () { + }, + computed: { + b: function () { + return model.name + '-计算属性' + } + }, + actions: { + run: function () { + model.name = "这是改变后的属性"; + } + } + }); + + Demo.Fix = BI.inherit(BI.Widget, { + _store: function () { + return new Store(); + }, + watch: { + b: function () { + this.button.setText(this.model.b) + } + }, + render: function () { + var self = this; + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.button", + ref: function () { + self.button = this; + }, + handler: function () { + self.store.run() + }, + text: this.model.b + } + }] + } + }, + mounted: function () { + + + } + }); + + BI.shortcut("demo.fix3", Demo.Fix); +}()); \ No newline at end of file diff --git a/demo/js/fix-2.0/watcher.js b/demo/js/fix-2.0/watcher.js new file mode 100644 index 000000000..dabd4a646 --- /dev/null +++ b/demo/js/fix-2.0/watcher.js @@ -0,0 +1,51 @@ +;(function () { + var model = Fix.define({ + name: "原始属性", + arr: [{ + n: 'a' + }, { + n: 0 + }] + }); + + Demo.Fix = BI.inherit(BI.Widget, { + _store: function () { + return model; + }, + watch: { + "name||arr.1.n": function () { + this.button.setText(this.model.name + "-" + this.model.arr[1].n) + } + }, + render: function () { + var self = this; + var cnt = 0; + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.button", + ref: function () { + self.button = this; + }, + handler: function () { + if (cnt & 1) { + self.model.name += 1; + } else { + self.model.arr[1].n += 1; + } + cnt++; + }, + text: this.model.name + "-" + this.model.arr[1].n + } + }] + } + }, + mounted: function () { + + + } + }); + + BI.shortcut("demo.fix4", Demo.Fix); +}()); \ No newline at end of file diff --git a/dist/demo.js b/dist/demo.js index 49edef10a..ef8ec3265 100644 --- a/dist/demo.js +++ b/dist/demo.js @@ -5381,7 +5381,27 @@ Demo.FIX_CONFIG = [{ }, { id: 71, pId: 7, - text: "fix框架", + text: "定义响应式数据", + value: "demo.fix1" +}, { + id: 72, + pId: 7, + text: "计算属性", + value: "demo.fix2" +}, { + id: 73, + pId: 7, + text: "store", + value: "demo.fix3" +}, { + id: 74, + pId: 7, + text: "watcher表达式", + value: "demo.fix4" +}, { + id: 75, + pId: 7, + text: "一个混合的例子", value: "demo.fix" }];Demo.WIDGET_CONFIG = [{ id: 4, @@ -10070,61 +10090,286 @@ Demo.Func = BI.inherit(BI.Widget, { } }); BI.shortcut("demo.tmp", Demo.Func); -var model = Fix.define({ - name: 1, - arr: [{ - n: 'a' - }, { - n: 'b' - }] -}); -Demo.Computed = BI.inherit(Fix.VM, { - computed: { - b: function () { - return this.name + 1 +;(function(){ + var model = Fix.define({ + name: "原始属性", + arr: [{ + n: 'a' + }, { + n: 'b' + }] + }); + var Computed = BI.inherit(Fix.VM, { + computed: { + b: function () { + return this.name + "-计算属性" + } + } + }) + + Demo.Fix = BI.inherit(BI.Widget, { + _store: function () { + return new Computed(model); + }, + watch: { + b: function () { + this.button.setText(this.model.b) + } }, - c: function () { - return this.arr[1].n + this.b + render: function () { + var self = this; + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.button", + ref: function () { + self.button = this; + }, + handler: function () { + self.model.name = "这是改变后的属性" + }, + text: this.model.b + } + }] + } + }, + mounted: function () { + + } - } -}) + }); -Demo.Store = BI.inherit(Fix.VM, { - _init: function () { - this.comp = new Demo.Computed(model).model; - }, - computed: { - b: function () { - return this.comp.c + 1 + BI.shortcut("demo.fix2", Demo.Fix); +}());;(function () { + var model = Fix.define({ + name: "原始属性", + arr: [{ + n: 'a' + }, { + n: 'b' + }] + }); + + Demo.Fix = BI.inherit(BI.Widget, { + _store: function () { + return model; + }, + watch: { + name: function () { + this.button.setText(this.model.name) + } }, - c: function () { - return this.comp.name + render: function () { + var self = this; + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.button", + ref: function () { + self.button = this; + }, + handler: function () { + self.model.name = "这是改变后的属性" + }, + text: this.model.name + } + }] + } + }, + mounted: function () { + + } - }, - actions: { - run: function () { - this.comp.name = 2; - this.comp.arr[1].n = "c" + }); + + BI.shortcut("demo.fix1", Demo.Fix); +}()); +;(function () { + var model = Fix.define({ + name: 1, + arr: [{ + n: 'a' + }, { + n: 0 + }] + }); + var Computed = BI.inherit(Fix.VM, { + computed: { + b: function () { + return this.name + 1 + }, + c: function () { + return this.arr[1].n + this.b + } } - } -}); + }) -Demo.Fix = BI.inherit(BI.Widget, { - _store: function () { - return new Demo.Store(); - }, - watch: { - "b&&c||b": function () { - debugger; + var Store = BI.inherit(Fix.VM, { + _init: function () { + this.comp = new Computed(model).model; + }, + computed: { + b: function () { + return this.comp.c + 1 + }, + c: function () { + return this.comp.arr[1].n & 1; + } + }, + actions: { + run: function () { + this.comp.name++; + this.comp.arr[1].n++; + } } - }, - mounted: function () { + }); - this.store.run() - } -}); + Demo.Fix = BI.inherit(BI.Widget, { + _store: function () { + return new Store(); + }, + watch: { + "b&&(c||b)": function () { + this.button.setText(this.model.b) + } + }, + render: function () { + var self = this; + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.button", + ref: function () { + self.button = this; + }, + handler: function () { + self.store.run() + }, + text: this.model.b + } + }] + } + }, + mounted: function () { + + + } + }); + + BI.shortcut("demo.fix", Demo.Fix); +}());;(function(){ + var model = Fix.define({ + name: "原始属性", + arr: [{ + n: 'a' + }, { + n: 'b' + }] + }); + + var Store = BI.inherit(Fix.VM, { + _init: function () { + }, + computed: { + b: function () { + return model.name + '-计算属性' + } + }, + actions: { + run: function () { + model.name = "这是改变后的属性"; + } + } + }); + + Demo.Fix = BI.inherit(BI.Widget, { + _store: function () { + return new Store(); + }, + watch: { + b: function () { + this.button.setText(this.model.b) + } + }, + render: function () { + var self = this; + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.button", + ref: function () { + self.button = this; + }, + handler: function () { + self.store.run() + }, + text: this.model.b + } + }] + } + }, + mounted: function () { + + + } + }); + + BI.shortcut("demo.fix3", Demo.Fix); +}());;(function () { + var model = Fix.define({ + name: "原始属性", + arr: [{ + n: 'a' + }, { + n: 0 + }] + }); + + Demo.Fix = BI.inherit(BI.Widget, { + _store: function () { + return model; + }, + watch: { + "name||arr.1.n": function () { + this.button.setText(this.model.name + "-" + this.model.arr[1].n) + } + }, + render: function () { + var self = this; + var cnt = 0; + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.button", + ref: function () { + self.button = this; + }, + handler: function () { + if (cnt & 1) { + self.model.name += 1; + } else { + self.model.arr[1].n += 1; + } + cnt++; + }, + text: this.model.name + "-" + this.model.arr[1].n + } + }] + } + }, + mounted: function () { + + + } + }); -BI.shortcut("demo.fix", Demo.Fix);Demo.Main = BI.inherit(BI.Widget, { + BI.shortcut("demo.fix4", Demo.Fix); +}());Demo.Main = BI.inherit(BI.Widget, { props: { baseCls: "demo-main bi-background" }, diff --git a/dist/fix/fix.js b/dist/fix/fix.js index 3b1cacddd..02a0b693b 100644 --- a/dist/fix/fix.js +++ b/dist/fix/fix.js @@ -974,7 +974,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons cb.call(vm); fns = exps.slice(); nextTick(function () { - complete = true; + complete = false; }); } }, options);