guy 7 years ago
parent
commit
53426900ab
  1. 5
      demo/js/fix-2.0/demo.js
  2. 5
      dist/demo.js
  3. 53
      dist/fix/fix.js

5
demo/js/fix-2.0/demo.js

@ -24,6 +24,9 @@ Demo.Store = BI.inherit(Fix.VM, {
computed: {
b: function () {
return this.comp.c + 1
},
c: function () {
return this.comp.name
}
},
actions: {
@ -39,7 +42,7 @@ Demo.Fix = BI.inherit(BI.Widget, {
return new Demo.Store();
},
watch: {
b: function () {
"b&&c||b": function () {
debugger;
}
},

5
dist/demo.js vendored

@ -10096,6 +10096,9 @@ Demo.Store = BI.inherit(Fix.VM, {
computed: {
b: function () {
return this.comp.c + 1
},
c: function () {
return this.comp.name
}
},
actions: {
@ -10111,7 +10114,7 @@ Demo.Fix = BI.inherit(BI.Widget, {
return new Demo.Store();
},
watch: {
b: function () {
"b&&c||b": function () {
debugger;
}
},

53
dist/fix/fix.js vendored

@ -875,6 +875,18 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
return vm.$watch(keyOrFn, handler, options);
}
function runBinaryFunction(binarys) {
var expr = '';
for (var i = 0, len = binarys.length; i < len; i++) {
if (_.isBoolean(binarys[i]) || binarys[i] === '||' || binarys[i] === '&&' || binarys[i] === '(' || binarys[i] === ')') {
expr += binarys[i];
} else {
expr += 'false';
}
}
return new Function('return ' + expr)();
}
var VM = function () {
function VM(model) {
_classCallCheck(this, VM);
@ -927,13 +939,42 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}
options = options || {};
options.user = true;
var watcher = new Watcher(vm.model, expOrFn, _.bind(cb, vm), options);
if (options.immediate) {
cb.call(vm, watcher.value);
var exps = void 0;
if (_.isFunction(expOrFn) || (exps = expOrFn.match(/[a-zA-Z0-9_.]+|[|][|]|[&][&]|[(]|[)]/g)) && exps.length === 1) {
var watcher = new Watcher(vm.model, expOrFn, _.bind(cb, vm), options);
if (options.immediate) {
cb.call(vm, watcher.value);
}
return function unwatchFn() {
watcher.teardown();
};
}
return function unwatchFn() {
watcher.teardown();
};
var watchers = [];
var fns = exps.slice();
var complete = false;
_.each(exps, function (exp, i) {
if (exp === '||' || exp === '&&' || exp === '(' || exp === ')') {
return;
}
var watcher = new Watcher(vm.model, exp, function () {
if (complete === true) {
return;
}
fns[i] = true;
if (runBinaryFunction(fns)) {
complete = true;
cb.call(vm);
fns = exps.slice();
nextTick(function () {
complete = true;
});
}
}, options);
watchers.push(function unwatchFn() {
watcher.teardown();
});
});
return watchers;
};
VM.prototype._init = function _init() {};

Loading…
Cancel
Save