diff --git a/dist/fix/fix.compact.ie.js b/dist/fix/fix.compact.ie.js index 5891bfdd6e..f0de3da580 100644 --- a/dist/fix/fix.compact.ie.js +++ b/dist/fix/fix.compact.ie.js @@ -101,6 +101,26 @@ 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) { var old = BI.Loader.prototype[name]; BI.Loader.prototype[name] = function () { @@ -324,5 +344,4 @@ return _.cloneDeep(obj); } } - BI.watch = Fix.watch; }()); diff --git a/dist/fix/fix.compact.js b/dist/fix/fix.compact.js index 6025117c00..97c209e22d 100644 --- a/dist/fix/fix.compact.js +++ b/dist/fix/fix.compact.js @@ -13,7 +13,7 @@ } } - function createWatcher(vm, keyOrFn, cb, options) { + function createWatcher (vm, keyOrFn, cb, options) { if (BI.isPlainObject(cb)) { options = cb; cb = cb.handler; @@ -110,6 +110,26 @@ 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) { var old = BI.Loader.prototype[name]; BI.Loader.prototype[name] = function () { @@ -280,5 +300,4 @@ return Fix.toJSON(ob); }; } - BI.watch = Fix.watch; }()); diff --git a/src/core/widget.js b/src/core/widget.js index 78d5e76468..12556ff136 100644 --- a/src/core/widget.js +++ b/src/core/widget.js @@ -164,6 +164,11 @@ _initElement: function () { var self = this; var els = this.render && this.render(); + if (!els) { + pushTarget(this); + els = this.setup && this.setup(); + popTarget(); + } if (BI.isPlainObject(els)) { els = [els]; } @@ -492,6 +497,39 @@ 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._renderEngine = engine; };