@sugarcoated/fondant-dictionary

1.0.4 • Public • Published

Dictionary extends Collection to bring typed Collections to JavaScript's weakly typed enviroment. Built to ignore primitives or convert them into Objects.

API Reference

new Dictionary(type, [initial])

Creates a Dictionary instance.

  • type is the non-primitive constructor symbol reference to mark. For example, if I created a class called Book, then I would pass in Book, not an instance.

  • initial is the initialiser to be passed to the encapsulated Collection, expected as Array.<Array.<String, Book>>.

    class Book {
      constructor (bookName) {
        this.bookName = bookName;
      }
    }
    
    new Dictionary(Book);
    new Dictionary(Book, [['one', new Book('one')]]);
    

For more details on how this constructor works, see Collection#constructor.

.set(name, value)

Overrides Collection's method (which can be read about here).

  • name is expected as a String, identifying the name/key that will identify the particular pair.

  • value is expected as the Object you passed to the constructor initially; for the purpose of example this was Book in our case.

    const myDictionary = new Dictionary(Book);
    
    myDictionary.set('one', new Book('one'));
    

.map(condition, [binding])

Overrides Collection's method (which can be read about here to reset item caches.

Readme

Keywords

Package Sidebar

Install

npm i @sugarcoated/fondant-dictionary

Weekly Downloads

0

Version

1.0.4

License

MIT

Last publish

Collaborators

  • crowes