diff --git a/www/todo/inner.js b/www/todo/inner.js index 6e6bcf297..748467360 100644 --- a/www/todo/inner.js +++ b/www/todo/inner.js @@ -96,6 +96,7 @@ define([ }; var addTaskUI = function (el, animate) { + if (!el) { return; } var $taskDiv = $('
', { 'class': 'cp-app-todo-task' }); diff --git a/www/todo/todo.js b/www/todo/todo.js index 07b9962cc..8c68774dd 100644 --- a/www/todo/todo.js +++ b/www/todo/todo.js @@ -39,6 +39,24 @@ define([ if (typeof(proxy.data) !== 'object') { proxy.data = {}; } if (!Array.isArray(proxy.order)) { proxy.order = []; } if (typeof(proxy.type) !== 'string') { proxy.type = 'todo'; } + + // if a key exists in order, but there is no data for it... + // remove that key + var i = proxy.order.length - 1; + for (;i >= 0; i--) { + if (typeof(proxy.data[proxy.order[i]]) === 'undefined') { + console.log('removing todo entry with no data at [%s]', i); + proxy.order.splice(i, 1); + } + } + + // if you have data, but it's not in the order array... + // add it to the order array... + Object.keys(proxy.data).forEach(function (key) { + if (proxy.order.indexOf(key) > -1) { return; } + console.log("restoring entry with missing key"); + proxy.order.unshift(key); + }); }; /* add (id, obj) push id to order, add object to data */