examples/todomvc/js/models/store.js
function (updateData, callback, id) {
        
        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;
            }
          }

          flush();
          callback.call(undefined, data.todos);
        } else {
          // Generate an ID
          updateData.id = new Date().getTime();

          todos.push(updateData);
          flush();
          callback.call(undefined, [updateData]);
        }
      }
function (updateData, callback, id) {
        
        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;
            }
          }

          flush();
          callback.call(undefined, data.todos);
        } else {
          // Generate an ID
          updateData.id = new Date().getTime();

          todos.push(updateData);
          flush();
          callback.call(undefined, [updateData]);
        }
      }
function ( updateData , callback , id ) { 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 ; } } flush ( ) ; callback . call ( undefined , data . todos ) ; } else { // Generate an ID updateData . id = new Date ( ) . getTime ( ) ; todos . push ( updateData ) ; flush ( ) ; callback . call ( undefined , [ 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