1.0.4 • Published 6 years ago

@sugarcoated/fondant-dictionary v1.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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.