guy 7 years ago
parent
commit
4fe455b28b
  1. 2
      dist/fix/fix.compact.js
  2. 118
      dist/fix/fix.js

2
dist/fix/fix.compact.js vendored

@ -21,7 +21,7 @@
if (typeof handler === 'string') { if (typeof handler === 'string') {
handler = vm[handler] handler = vm[handler]
} }
return Fix.VM.prototype.$watch.call(vm, keyOrFn, handler, options) return Fix.watch(vm, keyOrFn, handler, options)
} }
var _init = BI.Widget.prototype._init; var _init = BI.Widget.prototype._init;

118
dist/fix/fix.js vendored

@ -868,17 +868,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
} }
} }
function createWatcher(vm, keyOrFn, handler, options) {
if (isPlainObject(handler)) {
options = handler;
handler = handler.handler;
}
if (typeof handler === 'string') {
handler = vm[handler];
}
return vm.$watch(keyOrFn, handler, options);
}
var falsy$1; var falsy$1;
var operators = { var operators = {
'||': falsy$1, '||': falsy$1,
@ -898,59 +887,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
} }
return new Function('return ' + expr)(); return new Function('return ' + expr)();
} }
function watch(vm, expOrFn, cb, options) {
var VM = function () {
function VM(model) {
_classCallCheck(this, VM);
var vm = this;
if (model instanceof Observer || model instanceof VM) {
model = model.model;
}
if (_.has(model, '__ob__')) {
this.$$model = model;
} else {
this.options = model || {};
}
var keys = _.keys(this.$$model).concat(_.keys(this.computed));
var props = {};
var _loop = function _loop(i, len) {
var key = keys[i];
if (!(key in $$skipArray)) {
props[key] = {
enumerable: true,
configurable: true,
get: function get() {
return key in vm.$$computed ? vm.$$computed[key] : vm.$$model[key];
},
set: function set(val) {
if (!vm.$$model || !(key in vm.$$model)) {
return;
}
return vm.$$model[key] = val;
}
};
}
};
for (var i = 0, len = keys.length; i < len; i++) {
_loop(i, len);
}
this.model = createViewModel$1({}, props);
this.$$model && (this.model.__ob__ = this.$$model.__ob__);
initComputed(this, this.computed);
initMethods(this, this.actions);
this._init();
if (this.$$model) {
return this.model;
}
}
VM.prototype.$watch = function $watch(expOrFn, cb, options) {
var vm = this;
if (isPlainObject(cb)) { if (isPlainObject(cb)) {
return createWatcher(vm, expOrFn, cb, options); options = cb;
cb = cb.handler;
}
if (typeof cb === 'string') {
cb = vm[cb];
} }
options = options || {}; options = options || {};
options.user = true; options.user = true;
@ -1023,7 +966,55 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}); });
}); });
return watchers; return watchers;
}
var VM = function () {
function VM(model) {
_classCallCheck(this, VM);
var vm = this;
if (model instanceof Observer || model instanceof VM) {
model = model.model;
}
if (_.has(model, '__ob__')) {
this.$$model = model;
} else {
this.options = model || {};
}
var keys = _.keys(this.$$model).concat(_.keys(this.computed));
var props = {};
var _loop = function _loop(i, len) {
var key = keys[i];
if (!(key in $$skipArray)) {
props[key] = {
enumerable: true,
configurable: true,
get: function get() {
return key in vm.$$computed ? vm.$$computed[key] : vm.$$model[key];
},
set: function set(val) {
if (!vm.$$model || !(key in vm.$$model)) {
return;
}
return vm.$$model[key] = val;
}
}; };
}
};
for (var i = 0, len = keys.length; i < len; i++) {
_loop(i, len);
}
this.model = createViewModel$1({}, props);
this.$$model && (this.model.__ob__ = this.$$model.__ob__);
initComputed(this, this.computed);
initMethods(this, this.actions);
this._init();
if (this.$$model) {
return this.model;
}
}
VM.prototype._init = function _init() {}; VM.prototype._init = function _init() {};
@ -1044,6 +1035,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.watch = watch;
exports.VM = VM; exports.VM = VM;
exports.observerState = observerState; exports.observerState = observerState;
exports.Observer = Observer; exports.Observer = Observer;

Loading…
Cancel
Save