Commit 7a773a09 authored by Addy Osmani's avatar Addy Osmani

Merge pull request #41 from boushley/separateStorage

Separate storage fix
parents d3047151 95624f6e
angular.service('persistencejs', function() { angular.service('persistencejs', function() {
persistence.store.websql.config(persistence, 'todo', 'todo database', 5*1024*1024); persistence.store.websql.config(persistence, 'todo-angular-persistence', 'todo database', 5*1024*1024);
var Todo = persistence.define('todo', { var Todo = persistence.define('todo', {
content: 'TEXT', content: 'TEXT',
done: 'BOOL' done: 'BOOL'
......
...@@ -11,7 +11,7 @@ define([ ...@@ -11,7 +11,7 @@ define([
model: Todo, model: Todo,
// Save all of the todo items under the `"todos"` namespace. // Save all of the todo items under the `"todos"` namespace.
localStorage: new Store("todos"), localStorage: new Store("todos-backbone-require"),
// Filter down the list of all todo items that are finished. // Filter down the list of all todo items that are finished.
done: function() { done: function() {
......
...@@ -48,7 +48,7 @@ $(function(){ ...@@ -48,7 +48,7 @@ $(function(){
model: Todo, model: Todo,
// Save all of the todo items under the `"todos"` namespace. // Save all of the todo items under the `"todos"` namespace.
localStorage: new Store("todos"), localStorage: new Store("todos-backbone"),
// Filter down the list of all todo items that are finished. // Filter down the list of all todo items that are finished.
done: function() { done: function() {
......
...@@ -3,6 +3,6 @@ Ext.define('Todo.model.Task', { ...@@ -3,6 +3,6 @@ Ext.define('Todo.model.Task', {
fields: ['id', 'label', {name: 'checked', type: 'boolean'}], fields: ['id', 'label', {name: 'checked', type: 'boolean'}],
proxy: { proxy: {
type: 'localstorage', type: 'localstorage',
id: 'todo' id: 'todos-extjs'
} }
}); });
var localStoreName = 'todos-fidel';
var todoStore = (function() { var todoStore = (function() {
return { return {
get: function() { get: function() {
var d = localStorage.getItem('fidel.todos'); var d = localStorage.getItem(localStoreName);
var todos = {}; var todos = {};
if (d) { if (d) {
d = JSON.parse(d); d = JSON.parse(d);
...@@ -12,7 +13,7 @@ var todoStore = (function() { ...@@ -12,7 +13,7 @@ var todoStore = (function() {
return todos; return todos;
}, },
save: function(todos) { save: function(todos) {
localStorage.setItem('fidel.todos', JSON.stringify(todos)); localStorage.setItem(localStoreName, JSON.stringify(todos));
} }
}; };
})(); })();
......
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0}body{font-family:"Helvetica Neue",helvetica,arial,sans-serif;font-size:14px;line-height:1.4em;background:#eee;color:#333;padding:0;margin:0}#todos{-moz-box-shadow:rgba(0,0,0,0.2) 0 2px 6px 0;-webkit-box-shadow:rgba(0,0,0,0.2) 0 2px 6px 0;-o-box-shadow:rgba(0,0,0,0.2) 0 2px 6px 0;box-shadow:rgba(0,0,0,0.2) 0 2px 6px 0;-moz-border-radius:0 0 5px 5px;-o-border-radius:0 0 5px 5px;-webkit-border-radius:0 0 5px 5px;border-radius:0 0 5px 5px;border-bottom-left-radius:5px;border-bottom-right-radius:5px;background-attachment:scroll;margin:0 auto 40px;width:520px;background-color:white}h1{font-size:36px;font-weight:bold;line-height:1;padding:30px 0 10px;text-align:center}#todos .create{border:1px solid #999;-moz-box-shadow:rgba(0,0,0,0.2) 0 1px 2px 0 inset;-webkit-box-shadow:rgba(0,0,0,0.2) 0 1px 2px 0 inset;-o-box-shadow:rgba(0,0,0,0.2) 0 1px 2px 0 inset;box-shadow:rgba(0,0,0,0.2) 0 1px 2px 0 inset;font-family:inherit;font-size:24px;line-height:1.4em;outline:medium none;padding:6px;width:466px}.content{padding:20px 20px 0}#instructions{color:#777;margin:10px auto;text-align:center;text-shadow:0 1px 0 rgba(255,255,255,0.8);width:520px}#instructions li{list-style-type:none}.create,input.text{font-size:1.4em;width:100%}ul{margin:0;padding:0}.todo{list-style:none;border-bottom:1px solid #ccc;font-size:24px;padding:15px 20px 15px 0;position:relative;margin-left:15px}.todo:hover .todestroy{display:block}#todo-stats{background:none repeat scroll 0 0 #f4fce8;border-bottom-left-radius:5px;border-bottom-right-radius:5px;border-top:1px solid #ededed;color:#555;line-height:36px;margin-top:20px;padding:0 20px}.todo-count .number{color:#555;font-weight:bold}#list{margin-top:20px}.todestroy{background:url(destroy.png) no-repeat scroll center center transparent;cursor:pointer;height:20px;position:absolute;right:0;top:16px;width:20px;display:none;margin-right:20px}.todo-clear{float:right}.todo-clear a{display:block;line-height:20px;text-decoration:none;-moz-border-radius:12px;-webkit-border-radius:12px;-o-border-radius:12px;-ms-border-radius:12px;-khtml-border-radius:12px;border-radius:12px;background:rgba(0,0,0,0.1);color:#555;font-size:11px;margin-top:8px;padding:0 10px 1px;-moz-box-shadow:rgba(0,0,0,0.2) 0 -1px 0 0;-webkit-box-shadow:rgba(0,0,0,0.2) 0 -1px 0 0;-o-box-shadow:rgba(0,0,0,0.2) 0 -1px 0 0;box-shadow:rgba(0,0,0,0.2) 0 -1px 0 0}#credits{color:#999;margin:30px auto;text-align:center;text-shadow:0 1px 0 rgba(255,255,255,0.8);width:520px}#credits a{color:#888}
blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, \ No newline at end of file
font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var,
dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption,
tbody, tfoot, thead, tr, th, td {
margin:0;
padding:0;
}
body {
font-family: "Helvetica Neue", helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.4em;
background: #eeeeee;
color: #333333;
padding: 0px;
margin: 0px;
}
#todos {
-moz-box-shadow: rgba(0, 0, 0, 0.2) 0 2px 6px 0;
-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0 2px 6px 0;
-o-box-shadow: rgba(0, 0, 0, 0.2) 0 2px 6px 0;
box-shadow: rgba(0, 0, 0, 0.2) 0 2px 6px 0;
-moz-border-radius: 0 0 5px 5px;
-o-border-radius: 0 0 5px 5px;
-webkit-border-radius: 0 0 5px 5px;
border-radius: 0 0 5px 5px;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
background-attachment: scroll;
margin: 0 auto 40px;
width: 520px;
background-color: white;
}
h1{
font-size: 36px;
font-weight: bold;
line-height: 1;
padding: 30px 0 10px;
text-align: center;
}
#todos .create {
border: 1px solid #999999;
-moz-box-shadow: rgba(0, 0, 0, 0.2) 0 1px 2px 0 inset;
-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0 1px 2px 0 inset;
-o-box-shadow: rgba(0, 0, 0, 0.2) 0 1px 2px 0 inset;
box-shadow: rgba(0, 0, 0, 0.2) 0 1px 2px 0 inset; font-family: inherit;
font-size: 24px;
line-height: 1.4em;
outline: medium none;
padding: 6px;
width: 466px;
}
.content{
padding: 20px 20px 0;
}
#instructions {
color: #777777;
margin: 10px auto;
text-align: center;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
width: 520px;
}
#instructions li{
list-style-type:none;
}
.create, input.text {
font-size: 1.4em;
width: 100%;
}
ul {
margin: 0px;padding: 0px;
}
.todo {
list-style: none;
border-bottom: 1px solid #CCCCCC;
font-size: 24px;
padding: 15px 20px 15px 0;
position: relative;
margin-left: 15px;
}
.todo:hover .todestroy{
display:block;
}
#todo-stats {
background: none repeat scroll 0 0 #F4FCE8;
border-bottom-left-radius: 5px;
border-bottom-right-radius: 5px;
border-top: 1px solid #EDEDED;
color: #555555;
line-height: 36px;
margin-top: 20px;
padding: 0 20px;
}
.todo-count .number {
color: #555555;
font-weight: bold;
}
#list {
margin-top: 20px;
}
.todestroy {
background: url("destroy.png") no-repeat scroll center center transparent;
cursor: pointer;
height: 20px;
position: absolute;
right: 0;
top: 16px;
width: 20px;
display:none;
margin-right: 20px;
}
.todo-clear {
float: right;
}
.todo-clear a {
display: block;
line-height: 20px;
text-decoration: none;
-moz-border-radius: 12px;
-webkit-border-radius: 12px;
-o-border-radius: 12px;
-ms-border-radius: 12px;
-khtml-border-radius: 12px;
border-radius: 12px;
background: rgba(0, 0, 0, 0.1);
color: #555555;
font-size: 11px;
margin-top: 8px;
padding: 0 10px 1px;
-moz-box-shadow: rgba(0, 0, 0, 0.2) 0 -1px 0 0;
-webkit-box-shadow: rgba(0, 0, 0, 0.2) 0 -1px 0 0;
-o-box-shadow: rgba(0, 0, 0, 0.2) 0 -1px 0 0;
box-shadow: rgba(0, 0, 0, 0.2) 0 -1px 0 0;
}
.todo-clear a:hover, .todo-clear a:focus {
background: rgba(0, 0, 0, 0.15);
}
#todoapp #todo-stats .todo-clear a:active {
position: relative;
top: 1px;
}
#credits {
color: #999999;
margin: 30px auto;
text-align: center;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
width: 520px;
}
#credits a {
color: #888888;
}
steal.css("todo").plugins("jquery/model/list","jquery/controller","jquery/view/ejs","jquery/lang/json").then(function(d){d.Model("Todo",{localStore:function(a){var b=this.shortName,c=d.evalJSON(window.localStorage[b]||(window.localStorage[b]="{}"));if(a.call(this,c)!==false)window.localStorage[b]=d.toJSON(c)},findAll:function(a,b){this.localStore(function(c){instances=[];for(var e in c)instances.push(new this(c[e]));b&&b(instances)})},destroyAll:function(a,b){this.localStore(function(c){d.each(a, steal.css("todo").plugins("jquery/model/list","jquery/controller","jquery/view/ejs","jquery/lang/json").then(function(d){d.Model("Todo",{localStore:function(a){var b=d.evalJSON(window.localStorage["todo-javascriptmvc"]||(window.localStorage["todo-javascriptmvc"]="{}"));if(a.call(this,b)!==false)window.localStorage["todo-javascriptmvc"]=d.toJSON(b)},findAll:function(a,b){this.localStore(function(c){instances=[];for(var e in c)instances.push(new this(c[e]));b&&b(instances)})},destroyAll:function(a,
function(){delete c[this]})});b()},destroy:function(a,b){this.destroyAll(a,b);this.localStore(function(c){delete c[a]})},create:function(a,b){this.localStore(function(c){a.id=a.id||parseInt(1E5*Math.random());c[a.id]=a});b({id:a.id})},update:function(a,b,c){this.localStore(function(e){d.extend(e[a],b)});c({})}},{});d.Model.List("Todo.List",{completed:function(){return this.grep(function(a){return a.complete===true})}});d.Controller("Todos",{init:function(){this.find(".create").val("")[0].focus(); b){this.localStore(function(c){d.each(a,function(){delete c[this]})});b()},destroy:function(a,b){this.destroyAll(a,b);this.localStore(function(c){delete c[a]})},create:function(a,b){this.localStore(function(c){a.id=a.id||parseInt(1E5*Math.random());c[a.id]=a});b({id:a.id})},update:function(a,b,c){this.localStore(function(e){d.extend(e[a],b)});c({})}},{});d.Model.List("Todo.List",{completed:function(){return this.grep(function(a){return a.complete===true})}});d.Controller("Todos",{init:function(){this.find(".create").val("")[0].focus();
this.options.list.findAll()},"{list} add":function(a,b,c){this.find("#list").append("todosEJS",c);this.updateStats()},".create keyup":function(a,b){if(b.keyCode==13){(new Todo({text:a.val(),complete:false})).save(this.callback("created"));a.val("")}},created:function(a){this.options.list.push(a)},".todo-clear click":function(){this.options.list.completed().destroyAll()},".todo .todestroy click":function(a){a.closest(".todo").model().destroy()},"{list} remove":function(a,b,c){c.elements(this.element).slideUp(function(){d(this).remove()}); this.options.list.findAll()},"{list} add":function(a,b,c){this.find("#list").append("todosEJS",c);this.updateStats()},".create keyup":function(a,b){if(b.keyCode==13){(new Todo({text:a.val(),complete:false})).save(this.callback("created"));a.val("")}},created:function(a){this.options.list.push(a)},".todo-clear click":function(){this.options.list.completed().destroyAll()},".todo .todestroy click":function(a){a.closest(".todo").model().destroy()},"{list} remove":function(a,b,c){c.elements(this.element).slideUp(function(){d(this).remove()});
this.updateStats()},".todo [name=complete] change":function(a){a.closest(".todo").model().update({complete:a.is(":checked")})},".todo dblclick":function(a){var b=d("<input name='text' class='text'/>").val(a.model().text);a.html(b);b[0].focus()},".todo [name=text] focusout":function(a){a.closest(".todo").model().update({text:a.val()})},"{list} update":function(a,b,c){c.elements().html("todoEJS",c);this.updateStats()},updateStats:function(){var a=this.options.list,b=a.completed().length;d("#todo-stats").html("statsEJS", this.updateStats()},".todo [name=complete] change":function(a){a.closest(".todo").model().update({complete:a.is(":checked")})},".todo dblclick":function(a){var b=d("<input name='text' class='text'/>").val(a.model().text);a.html(b);b[0].focus()},".todo [name=text] focusout":function(a){a.closest(".todo").model().update({text:a.val()})},"{list} update":function(a,b,c){c.elements().html("todoEJS",c);this.updateStats()},updateStats:function(){var a=this.options.list,b=a.completed().length;d("#todo-stats").html("statsEJS",
{completed:b,total:a.length,remaining:a.length-b})}});d(function(){d("#todos").todos({list:new Todo.List})})}); {completed:b,total:a.length,remaining:a.length-b})}});d(function(){d("#todos").todos({list:new Todo.List})})});
......
...@@ -17,7 +17,7 @@ $.Model('Todo',{ ...@@ -17,7 +17,7 @@ $.Model('Todo',{
* This is unimportant for understanding JavaScriptMVC! * This is unimportant for understanding JavaScriptMVC!
*/ */
localStore: function(cb){ localStore: function(cb){
var name = this.shortName, var name = 'todo-javascriptmvc',
data = $.evalJSON( window.localStorage[name] || (window.localStorage[name] = "{}") ), data = $.evalJSON( window.localStorage[name] || (window.localStorage[name] = "{}") ),
res = cb.call(this, data); res = cb.call(this, data);
if(res !== false){ if(res !== false){
......
...@@ -40,7 +40,7 @@ jQuery(function($){ ...@@ -40,7 +40,7 @@ jQuery(function($){
this.$count = this.$footer.find('.count'); this.$count = this.$footer.find('.count');
this.$clearBtn = this.$footer.find('.clear'); this.$clearBtn = this.$footer.find('.clear');
// localStorage support // localStorage support
this.store = new Store('todoapp'); this.store = new Store('todo-jquery');
this.todos = this.store.get('todos') || []; this.todos = this.store.get('todos') || [];
this.bindEvents(); this.bindEvents();
this.render(); this.render();
......
...@@ -186,12 +186,12 @@ ...@@ -186,12 +186,12 @@
// lists model // lists model
Lists = Object.create(Model); Lists = Object.create(Model);
Lists.name = 'lists'; Lists.name = 'lists-sammyjs';
Lists.init(); Lists.init();
// todos model // todos model
Todos = Object.create(Model); Todos = Object.create(Model);
Todos.name = 'todos'; Todos.name = 'todos-sammyjs';
Todos.init(); Todos.init();
......
(function() { (function() {
var storageName = 'todos-spine';
if (typeof Spine === "undefined" || Spine === null) { if (typeof Spine === "undefined" || Spine === null) {
Spine = require('spine'); Spine = require('spine');
} }
...@@ -10,11 +12,11 @@ ...@@ -10,11 +12,11 @@
saveLocal: function() { saveLocal: function() {
var result; var result;
result = JSON.stringify(this); result = JSON.stringify(this);
return localStorage[this.className] = result; return localStorage[storageName] = result;
}, },
loadLocal: function() { loadLocal: function() {
var result; var result;
result = localStorage[this.className]; result = localStorage[storageName];
return this.refresh(result || [], { return this.refresh(result || [], {
clear: true clear: true
}); });
......
YUI().use('event-focus', 'json', 'model', 'model-list', 'view', function (Y) { YUI().use('event-focus', 'json', 'model', 'model-list', 'view', function (Y) {
var TodoAppView, TodoList, TodoModel, TodoView; var TodoAppView, TodoList, TodoModel, TodoView, localStorageName = 'todos-yuilibrary';
// -- Model -------------------------------------------------------------------- // -- Model --------------------------------------------------------------------
...@@ -12,7 +12,7 @@ var TodoAppView, TodoList, TodoModel, TodoView; ...@@ -12,7 +12,7 @@ var TodoAppView, TodoList, TodoModel, TodoView;
TodoModel = Y.TodoModel = Y.Base.create('todoModel', Y.Model, [], { TodoModel = Y.TodoModel = Y.Base.create('todoModel', Y.Model, [], {
// This tells the Model to use a localStorage sync provider (which we'll // This tells the Model to use a localStorage sync provider (which we'll
// create below) to save and load information about a todo item. // create below) to save and load information about a todo item.
sync: LocalStorageSync('todo'), sync: LocalStorageSync(localStorageName),
// This method will toggle the `done` attribute from `true` to `false`, or // This method will toggle the `done` attribute from `true` to `false`, or
// vice versa. // vice versa.
...@@ -41,7 +41,7 @@ TodoList = Y.TodoList = Y.Base.create('todoList', Y.ModelList, [], { ...@@ -41,7 +41,7 @@ TodoList = Y.TodoList = Y.Base.create('todoList', Y.ModelList, [], {
// This tells the list to use a localStorage sync provider (which we'll // This tells the list to use a localStorage sync provider (which we'll
// create below) to load the list of todo items. // create below) to load the list of todo items.
sync : LocalStorageSync('todo'), sync : LocalStorageSync(localStorageName),
// Returns an array of all models in this list with the `done` attribute // Returns an array of all models in this list with the `done` attribute
// set to `true`. // set to `true`.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment