structure icon indicating copy to clipboard operation
structure copied to clipboard

Create a collection class that does coercion on mutation

Open talyssonoc opened this issue 8 years ago • 0 comments

It's still just a proposal, the API have to be discussed, but I think having a Collection class that does coercion of items on mutation would be good:

const { Collection, attributes, items } = require('structure');

const Book = attributes({
  name: String
})(class Book { });

const BooksCollection = items({
  type: Book
})(class BooksCollection extends Collection { });

const books = new BooksCollection();

books.push({ name: 'Elric' });

books; // BooksCollection [ Book { name: 'Elric' } ]

talyssonoc avatar Dec 28 '16 02:12 talyssonoc