marko
Version:
UI Components + streaming, async, high performance, HTML templating for Node.js and the browser.
76 lines (58 loc) • 1.92 kB
JavaScript
;var Component = require("../../../runtime/components/Component");
var req = require("@internal/require");
var getComponentForEl =
require("@internal/components-util").U_;
// eslint-disable-next-line no-constant-binary-expression
// expose legacy
require("@internal/components-registry")._i_ = exports;
exports.load = function (typeName) {
return exports.defineWidget(req(typeName));
};
// legacy api
exports.defineComponent = require("../../../runtime/components/legacy/defineComponent-legacy");
exports.defineWidget = require("@internal/components-define-widget-legacy");
exports.defineRenderer = require("../../../runtime/components/legacy/defineRenderer-legacy");
exports.makeRenderable =
exports.renderable = require("../../../runtime/renderable");
// browser only
var Widget = exports.Widget = Component;
exports.getWidgetForEl = exports.get = function (elOrId) {
var el = elOrId;
if (typeof elOrId === "string") {
el = document.getElementById(elOrId);
}
if (el && el.__widget) {
return el.__widget;
}
return getComponentForEl(el);
};
exports.initWidgets =
require("@internal/components-registry").V_;
// monkey patch Widget
if (Widget) {
var WidgetProto = Widget.prototype;
WidgetProto.setProps = function (newInput) {
this._j_ = true;
this._k_(newInput);
};
WidgetProto.rerender = function (newInput) {
if (newInput) {
this.setProps(newInput);
}
this.forceUpdate();
this.update();
};
}
var RenderResult = require("../../../runtime/RenderResult");
RenderResult.prototype.getWidget = function () {
// eslint-disable-next-line no-constant-condition
return this.getWidgets()[0];
};
RenderResult.prototype.getWidgets = function () {
// eslint-disable-next-line no-constant-condition
return RenderResult.prototype.getComponents.
apply(this, arguments).
filter(function (component) {
return component.z_;
});
};