Browse Source

Added `options` as a second argument to the `Component.components()` method

pull/3264/head
Artur Arseniev 6 years ago
parent
commit
3199d76ba5
  1. 11
      src/dom_components/model/Component.js

11
src/dom_components/model/Component.js

@ -822,7 +822,7 @@ const Component = Backbone.Model.extend(Styleable).extend(
/** /**
* Add new component children * Add new component children
* @param {Component|String} components Component to add * @param {Component|String} components Component to add
* @param {Object} [opts={}] Options, same as in `model.add()`(from backbone) * @param {Object} [opts={}] Options for the append action
* @return {Array} Array of appended components * @return {Array} Array of appended components
* @example * @example
* someComponent.get('components').length // -> 0 * someComponent.get('components').length // -> 0
@ -832,6 +832,8 @@ const Component = Backbone.Model.extend(Styleable).extend(
* // You can pass components directly * // You can pass components directly
* otherComponent.append(otherComponent2); * otherComponent.append(otherComponent2);
* otherComponent.append([otherComponent3, otherComponent4]); * otherComponent.append([otherComponent3, otherComponent4]);
* // append at specific index (eg. at the beginning)
* someComponent.append(otherComponent, { at: 0 });
*/ */
append(components, opts = {}) { append(components, opts = {}) {
const result = this.components().add(components, opts); const result = this.components().add(components, opts);
@ -842,6 +844,7 @@ const Component = Backbone.Model.extend(Styleable).extend(
* Set new collection if `components` are provided, otherwise the * Set new collection if `components` are provided, otherwise the
* current collection is returned * current collection is returned
* @param {Component|String} [components] Components to set * @param {Component|String} [components] Components to set
* @param {Object} [opts={}] Options, same as in `Component.append()`
* @return {Collection|Array<Component>} * @return {Collection|Array<Component>}
* @example * @example
* // Set new collection * // Set new collection
@ -851,14 +854,14 @@ const Component = Backbone.Model.extend(Styleable).extend(
* console.log(collection.length); * console.log(collection.length);
* // -> 2 * // -> 2
*/ */
components(components) { components(components, opts = {}) {
const coll = this.get('components'); const coll = this.get('components');
if (isUndefined(components)) { if (isUndefined(components)) {
return coll; return coll;
} else { } else {
coll.reset(); coll.reset(null, opts);
return components && this.append(components); return components && this.append(components, opts);
} }
}, },

Loading…
Cancel
Save