Skip to content

Collection #142

@dwhieb

Description

@dwhieb
/**
 * A class representing a collection. Each item in the collction will be an instance of the provided Model.
 * @extends Array
 */
class Collection extends Array {

  /**
   * Create a new Collection
   * @param {Function} Model The class to use as the model for each item in the collection
   */
  constructor(Model) {

    super();

    return new Proxy(this, {
      set(target, prop, val, proxy) {

        if (Number.isInteger(Number(prop))) {
          val = new Model(val); // eslint-disable-line no-param-reassign
        }

        return Reflect.set(target, prop, val, proxy);

      },
    });

  }

}

export default Collection;

Metadata

Metadata

Assignees

Labels

coreCore models and utilitiesfeatureChanges that affect the API

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions