constructor no longer has the option to initialize with a collection of records, use add()

This commit is contained in:
Geoff Doty 2018-04-07 00:17:56 -04:00
parent cccffd3fa4
commit d44346d7be
1 changed files with 7 additions and 2 deletions

View File

@ -21,19 +21,24 @@
* @example * @example
* // create a new record (in-memory) * // create a new record (in-memory)
* let pets = new Record(); * let pets = new Record();
*
* @example
* // create a new record (localStorage)
* let pets = new Record({"store": "pets"});
* *
* @param {array} init - collection to start with * @param {array} init - collection to start with
* @param {object} opts * @param {object} opts
* @param {object} opts.store - localStorage ID to use * @param {object} opts.store - localStorage ID to use
* @param {object} opts.debug - show console logs * @param {object} opts.debug - show console logs
*/ */
constructor(init, opts) { constructor(opts) {
// define options // define options
this.store = (opts || {}).store; this.store = (opts || {}).store;
this.debug = (opts || {}).debug || false; this.debug = (opts || {}).debug || false;
// initialize the collection // initialize the collection
this.records = Array.isArray(init) ? init : []; this.records = [];
// get stored records, merge as needed // get stored records, merge as needed
if(this.store && localStorage) { if(this.store && localStorage) {
this._log("Initializing localStorage for " + this.store); this._log("Initializing localStorage for " + this.store);