structure
structure copied to clipboard
Create a collection class that does coercion on mutation
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' } ]