in lib/builder/ContainerBuilder.js [35:114]
var ContainerBuilder = function () {
function ContainerBuilder() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
_classCallCheck(this, ContainerBuilder);
this._registrations = [];
this._defaultOptions = options;
this._factory = _ReactDomFactory2.default;
}
/**
* Register new component asynchronously
* @param {Function} operator - function that returns a promise that resolves a React Component
* @returns {Registration}
*/
_createClass(ContainerBuilder, [{
key: 'registerAsync',
value: function registerAsync(operator) {
var registration = new _Registration2.default(operator);
if (this._defaultOptions) {
registration.withOptions(this._defaultOptions);
}
this._registrations.push(registration);
return registration;
}
/**
* Register new component
* @param {object} component - a React Component to register
* @returns {Registration}
*/
}, {
key: 'register',
value: function register(component) {
return this.registerAsync(function () {
return Promise.resolve(component);
});
}
/**
* Set the container factory
* @param {Object} factory - The factory
*/
}, {
key: 'build',
/**
* Build the container
* @returns {Container}
*/
value: function build() {
return new _Container2.default(this._factory, this._registrations.reduce(function (acc, registration) {
if (!registration.key) {
_Logger2.default.error('RHE11', 'Missing key for registration.');
return acc;
}
if (acc[registration.key]) {
_Logger2.default.warn('RHW12', 'Duplicate key', registration.key);
}
acc[registration.key] = registration;
return acc;
}, {}));
}
}, {
key: 'factory',
set: function set(factory) {
this._factory = factory;
}
}]);
return ContainerBuilder;
}();