value: function _apply()

in lib/Bootstrapper.js [88:151]


		value: function _apply(nodes) {
			var _this = this;

			var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;

			// const factory = container.domFactory();
			// const id = container.id();
			var resolveQueue = [];

			// Iterate over component elements in the dom

			var _loop = function _loop(i) {
				var ele = nodes[i];

				// Ignore elements that have already been connected
				if (_Habitat2.default.hasHabitat(ele)) {
					return 'continue';
				}

				// Resolve components using promises
				var componentName = ele.getAttribute(_this.componentSelector);
				resolveQueue.push(_this.__container__.resolve(componentName, _this).then(function (registration) {
					// This is an expensive operation so only do on non prod builds
					if (process.env.NODE_ENV !== 'production') {
						if (ele.querySelector('[' + _this.componentSelector + ']')) {
							_Logger2.default.warn('RHW08', 'Component should not contain any nested components.', ele);
						}
					}

					// Generate props
					var props = _Habitat2.default.parseProps(ele);
					if (registration.meta.defaultProps) {
						props = Object.assign({}, registration.meta.defaultProps, props);
					}

					// Options
					var options = registration.meta.options || {};

					// Inject the component
					_this.__container__.factory.inject(registration.component, props, _Habitat2.default.create(ele, _this.__container__.id, options));
				}).catch(function (err) {
					_Logger2.default.error('RHW01', 'Cannot resolve component "' + componentName + '" for element.', err, ele);
				}));
			};

			for (var i = 0; i < nodes.length; ++i) {
				var _ret = _loop(i);

				if (_ret === 'continue') continue;
			}

			// Trigger callback when all promises are finished
			// regardless if some fail
			Promise.all(resolveQueue.map(function (p) {
				return p.catch(function (e) {
					return e;
				});
			})).then(function () {
				_callback(cb);
			}).catch(function (err) {
				// We should never get here.. if we do this is a bug
				throw err;
			});
		}