devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
56 lines (55 loc) • 2 kB
JavaScript
/**
* DevExtreme (core/component_registrator.js)
* Version: 18.2.18
* Build date: Tue Oct 18 2022
*
* Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
;
var $ = require("./renderer");
var callbacks = require("./component_registrator_callbacks");
var errors = require("./errors");
var publicComponentUtils = require("./utils/public_component");
var registerComponent = function(name, namespace, componentClass) {
if (!componentClass) {
componentClass = namespace
} else {
namespace[name] = componentClass
}
publicComponentUtils.name(componentClass, name);
callbacks.fire(name, componentClass)
};
var registerRendererComponent = function(name, componentClass) {
$.fn[name] = function(options) {
var result, isMemberInvoke = "string" === typeof options;
if (isMemberInvoke) {
var memberName = options,
memberArgs = [].slice.call(arguments).slice(1);
this.each(function() {
var instance = componentClass.getInstance(this);
if (!instance) {
throw errors.Error("E0009", name)
}
var member = instance[memberName],
memberValue = member.apply(instance, memberArgs);
if (void 0 === result) {
result = memberValue
}
})
} else {
this.each(function() {
var instance = componentClass.getInstance(this);
if (instance) {
instance.option(options)
} else {
new componentClass(this, options)
}
});
result = this
}
return result
}
};
callbacks.add(registerRendererComponent);
module.exports = registerComponent;