save(updateData, callback, id){
        const data = JSON.parse(this.memoryStorage[this._dbName]);
        let todos = data.todos;
        const len = todos.length;

        // If an ID was actually given, find the item and update each property
        if (id) {
            for (let i = 0; i < len; i++) {
                if (todos[i].id === id) {
                    for (let key in updateData) {
                        todos[i][key] = updateData[key];
                    }
                    break;
                }
            }

            this.memoryStorage[this._dbName] = JSON.stringify(data);

            if (callback) {
                callback.call(this, JSON.parse(this.memoryStorage[this._dbName]).todos);
            }
        } else {
            // Generate an ID
            updateData.id = uniqueID++;

            todos.push(updateData);
            this.memoryStorage[this._dbName] = JSON.stringify(data);

            if (callback) {
                callback.call(this, [updateData]);
            }
        }
    }
/**
     * Will save the given data to the DB. If no item exists it will create a new
     * item, otherwise it'll simply update an existing item's properties
     *
     * @param {object} updateData The data to save back into the DB
     * @param {function} callback The callback to fire after saving
     * @param {number} id An optional param to enter an ID of an item to update
     */
Will save the given data to the DB. If no item exists it will create a new
item, otherwise it'll simply update an existing item's properties

@param {object} updateData The data to save back into the DB
@param {function} callback The callback to fire after saving
@param {number} id An optional param to enter an ID of an item to update
Will save the given data to the DB . If no item exists it will create a new item otherwise it ' ll simply update an existing item ' s properties @param { object } updateData The data to save back into the DB @param { function } callback The callback to fire after saving @param { number } id An optional param to enter an ID of an item to update
save(updateData, callback, id){
        const data = JSON.parse(this.memoryStorage[this._dbName]);
        let todos = data.todos;
        const len = todos.length;
        if (id) {
            for (let i = 0; i < len; i++) {
                if (todos[i].id === id) {
                    for (let key in updateData) {
                        todos[i][key] = updateData[key];
                    }
                    break;
                }
            }
            this.memoryStorage[this._dbName] = JSON.stringify(data);
            if (callback) {
                callback.call(this, JSON.parse(this.memoryStorage[this._dbName]).todos);
            }
        } else {
            updateData.id = uniqueID++;
            todos.push(updateData);
            this.memoryStorage[this._dbName] = JSON.stringify(data);
            if (callback) {
                callback.call(this, [updateData]);
            }
        }
    }
save ( updateData , callback , id ) { const data = JSON . parse ( this . memoryStorage [ this . _dbName ] ) ; let todos = data . todos ; const len = todos . length ; if ( id ) { for ( let i = 0 ; i < len ; i ++ ) { if ( todos [ i ] . id === id ) { for ( let key in updateData ) { todos [ i ] [ key ] = updateData [ key ] ; } break ; } } this . memoryStorage [ this . _dbName ] = JSON . stringify ( data ) ; if ( callback ) { callback . call ( this , JSON . parse ( this . memoryStorage [ this . _dbName ] ) . todos ) ; } } else { updateData . id = uniqueID ++ ; todos . push ( updateData ) ; this . memoryStorage [ this . _dbName ] = JSON . stringify ( data ) ; if ( callback ) { callback . call ( this , [ updateData ] ) ; } } }
Will save the given data to the DB.
Will save the given data to the DB .
// If an ID was actually given, find the item and update each property // Generate an ID