in resources/todomvc/vanilla-examples/javascript-es6-webpack/src/store.js [83:112]
save(updateData, callback, id) {
const data = JSON.parse(memoryStorage[this._dbName]);
const { todos } = data;
// If an ID was actually given, find the item and update each property
if (id) {
for (let i = 0; i < todos.length; i++) {
if (todos[i].id === id) {
for (let key in updateData)
todos[i][key] = updateData[key];
break;
}
}
memoryStorage[this._dbName] = JSON.stringify(data);
if (callback)
callback(JSON.parse(memoryStorage[this._dbName]).todos);
} else {
// Generate an ID
updateData.id = uniqueID++;
todos.push(updateData);
memoryStorage[this._dbName] = JSON.stringify(data);
if (callback)
callback([updateData]);
}
}