Store.prototype.save = function()

in resources/todomvc/vanilla-examples/javascript-es5/src/store.js [82:109]


    Store.prototype.save = function (updateData, callback, id) {
        var data = JSON.parse(MemoryStorage[this._dbName]);
        var todos = data.todos;

        callback = callback || function () {};

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

                    break;
                }
            }

            MemoryStorage[this._dbName] = JSON.stringify(data);
            callback.call(this, todos);
        } else {
            // Generate an ID
            updateData.id = ID++;

            todos.push(updateData);
            MemoryStorage[this._dbName] = JSON.stringify(data);
            callback.call(this, [updateData]);
        }
    };