guy 7 years ago
parent
commit
b79093fc65
  1. 5
      demo/js/config/fix.js
  2. 49
      demo/js/fix-2.0/state.js
  3. 55
      dist/demo.js
  4. 25
      dist/fix/fix.js

5
demo/js/config/fix.js

@ -91,6 +91,11 @@ Demo.FIX_CONFIG = [{
}, { }, {
id: 72, id: 72,
pId: 7, pId: 7,
text: "state属性",
value: "demo.fix6"
}, {
id: 78,
pId: 7,
text: "计算属性", text: "计算属性",
value: "demo.fix2" value: "demo.fix2"
}, { }, {

49
demo/js/fix-2.0/state.js

@ -0,0 +1,49 @@
;(function () {
var State = BI.inherit(Fix.VM, {
state: function () {
return {
name: "原始属性"
}
},
computed: {
b: function () {
return this.model.name + "-计算属性"
}
}
})
Demo.Fix = BI.inherit(BI.Widget, {
_store: function () {
return new State();
},
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.fix6", Demo.Fix);
}());

55
dist/demo.js vendored

@ -5257,6 +5257,11 @@ Demo.FIX_CONFIG = [{
}, { }, {
id: 72, id: 72,
pId: 7, pId: 7,
text: "state属性",
value: "demo.fix6"
}, {
id: 78,
pId: 7,
text: "计算属性", text: "计算属性",
value: "demo.fix2" value: "demo.fix2"
}, { }, {
@ -10640,7 +10645,55 @@ BI.shortcut("demo.tmp", Demo.Func);
}); });
BI.shortcut("demo.fix_scene_fine_index_update", Demo.FixSceneFineIndexUpdate); BI.shortcut("demo.fix_scene_fine_index_update", Demo.FixSceneFineIndexUpdate);
})();;(function(){ })();;(function () {
var State = BI.inherit(Fix.VM, {
state: function () {
return {
name: "原始属性"
}
},
computed: {
b: function () {
return this.model.name + "-计算属性"
}
}
})
Demo.Fix = BI.inherit(BI.Widget, {
_store: function () {
return new State();
},
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.fix6", Demo.Fix);
}());;(function(){
var model = Fix.define({ var model = Fix.define({
name: "原始属性", name: "原始属性",
arr: [{ arr: [{

25
dist/fix/fix.js vendored

@ -820,6 +820,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
var computedWatcherOptions = { lazy: true }; var computedWatcherOptions = { lazy: true };
function initState(vm, state) {
vm.$$state = observe(state).model;
}
function initComputed(vm, computed) { function initComputed(vm, computed) {
var watchers = vm._computedWatchers = {}; var watchers = vm._computedWatchers = {};
@ -894,7 +898,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
} else { } else {
this.options = model || {}; this.options = model || {};
} }
var keys = _.keys(this.$$model).concat(_.keys(this.computed)); var state = this.state && this.state();
var keys = _.keys(this.$$model).concat(_.keys(state)).concat(_.keys(this.computed));
var props = {}; var props = {};
var _loop = function _loop(i, len) { var _loop = function _loop(i, len) {
@ -904,13 +909,21 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
enumerable: true, enumerable: true,
configurable: true, configurable: true,
get: function get() { get: function get() {
return key in vm.$$computed ? vm.$$computed[key] : vm.$$model[key]; if (key in vm.$$computed) {
return vm.$$computed[key];
}
if (key in vm.$$state) {
return vm.$$state[key];
}
return vm.$$model[key];
}, },
set: function set(val) { set: function set(val) {
if (!vm.$$model || !(key in vm.$$model)) { if (key in vm.$$state) {
return; return vm.$$state[key] = val;
}
if (key in vm.$$model) {
return vm.$$model[key] = val;
} }
return vm.$$model[key] = val;
} }
}; };
} }
@ -921,6 +934,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
} }
this.model = createViewModel$1({}, props); this.model = createViewModel$1({}, props);
this.$$model && (this.model.__ob__ = this.$$model.__ob__); this.$$model && (this.model.__ob__ = this.$$model.__ob__);
state && initState(this, state);
initComputed(this, this.computed); initComputed(this, this.computed);
initMethods(this, this.actions); initMethods(this, this.actions);
this._init(); this._init();
@ -1110,6 +1124,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
exports.define = define; exports.define = define;
exports.version = version; exports.version = version;
exports.$$skipArray = $$skipArray; exports.$$skipArray = $$skipArray;
exports.initState = initState;
exports.VM = VM; exports.VM = VM;
exports.observerState = observerState; exports.observerState = observerState;
exports.Observer = Observer; exports.Observer = Observer;

Loading…
Cancel
Save