Browse Source

Composition API

es6
guy 4 years ago
parent
commit
b9b518df7d
  1. 21
      dist/fix/fix.compact.ie.js
  2. 23
      dist/fix/fix.compact.js
  3. 38
      src/core/widget.js

21
dist/fix/fix.compact.ie.js vendored

@ -101,6 +101,26 @@
return result; return result;
}; };
BI.watch = function (watch, handler) {
if (BI.Widget.current) {
if (BI.isKey(watch)) {
var key = watch;
watch = {};
watch[key] = handler;
}
for (var key in watch) {
var handler = watch[key];
if (BI.isArray(handler)) {
for (var i = 0; i < handler.length; i++) {
BI.Widget.current._watchers.push(createWatcher(BI.Widget.current, key, handler[i]));
}
} else {
BI.Widget.current._watchers.push(createWatcher(BI.Widget.current, key, handler));
}
}
}
};
_.each(["populate", "addItems", "prependItems"], function (name) { _.each(["populate", "addItems", "prependItems"], function (name) {
var old = BI.Loader.prototype[name]; var old = BI.Loader.prototype[name];
BI.Loader.prototype[name] = function () { BI.Loader.prototype[name] = function () {
@ -324,5 +344,4 @@
return _.cloneDeep(obj); return _.cloneDeep(obj);
} }
} }
BI.watch = Fix.watch;
}()); }());

23
dist/fix/fix.compact.js vendored

@ -13,7 +13,7 @@
} }
} }
function createWatcher(vm, keyOrFn, cb, options) { function createWatcher (vm, keyOrFn, cb, options) {
if (BI.isPlainObject(cb)) { if (BI.isPlainObject(cb)) {
options = cb; options = cb;
cb = cb.handler; cb = cb.handler;
@ -110,6 +110,26 @@
return result; return result;
}; };
BI.watch = function (watch, handler) {
if (BI.Widget.current) {
if (BI.isKey(watch)) {
var key = watch;
watch = {};
watch[key] = handler;
}
for (var key in watch) {
var handler = watch[key];
if (BI.isArray(handler)) {
for (var i = 0; i < handler.length; i++) {
BI.Widget.current._watchers.push(createWatcher(BI.Widget.current, key, handler[i]));
}
} else {
BI.Widget.current._watchers.push(createWatcher(BI.Widget.current, key, handler));
}
}
}
};
_.each(["populate", "addItems", "prependItems"], function (name) { _.each(["populate", "addItems", "prependItems"], function (name) {
var old = BI.Loader.prototype[name]; var old = BI.Loader.prototype[name];
BI.Loader.prototype[name] = function () { BI.Loader.prototype[name] = function () {
@ -280,5 +300,4 @@
return Fix.toJSON(ob); return Fix.toJSON(ob);
}; };
} }
BI.watch = Fix.watch;
}()); }());

38
src/core/widget.js

@ -164,6 +164,11 @@
_initElement: function () { _initElement: function () {
var self = this; var self = this;
var els = this.render && this.render(); var els = this.render && this.render();
if (!els) {
pushTarget(this);
els = this.setup && this.setup();
popTarget();
}
if (BI.isPlainObject(els)) { if (BI.isPlainObject(els)) {
els = [els]; els = [els];
} }
@ -492,6 +497,39 @@
this.purgeListeners(); this.purgeListeners();
} }
}); });
var context = null;
var contextStack = [];
function pushTarget (_context) {
if (context) contextStack.push(context);
BI.Widget.current = context = _context;
}
function popTarget () {
BI.Widget.current = context = contextStack.pop();
}
BI.onBeforeMount = function (beforeMount) {
if (context) {
context.beforeMount = beforeMount;
}
};
BI.onMounted = function (mounted) {
if (context) {
context.mounted = mounted;
}
};
BI.onBeforeUnmount = function (beforeDestroy) {
if (context) {
context.beforeDestroy = beforeDestroy;
}
};
BI.onUnmounted = function (destroyed) {
if (context) {
context.destroyed = destroyed;
}
};
BI.Widget.registerRenderEngine = function (engine) { BI.Widget.registerRenderEngine = function (engine) {
BI.Widget._renderEngine = engine; BI.Widget._renderEngine = engine;
}; };

Loading…
Cancel
Save