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'
...@@ -54,4 +54,4 @@ angular.service('persistencejs', function() { ...@@ -54,4 +54,4 @@ angular.service('persistencejs', function() {
}); });
}, },
}; };
}); });
\ No newline at end of file
...@@ -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;
}
...@@ -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){
...@@ -251,4 +251,4 @@ $(function(){ ...@@ -251,4 +251,4 @@ $(function(){
}) })
}); });
\ No newline at end of file
...@@ -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();
...@@ -149,4 +149,4 @@ jQuery(function($){ ...@@ -149,4 +149,4 @@ jQuery(function($){
window.TodoApp = App.init(); window.TodoApp = App.init();
}); });
\ No newline at end of file
...@@ -186,14 +186,14 @@ ...@@ -186,14 +186,14 @@
// 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() { app.run(); }); $(function() { app.run(); });
})(jQuery); })(jQuery);
\ No newline at end of file
(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`.
...@@ -444,4 +444,4 @@ function LocalStorageSync(key) { ...@@ -444,4 +444,4 @@ function LocalStorageSync(key) {
// in motion and bring our todo list into existence. // in motion and bring our todo list into existence.
new TodoAppView(); new TodoAppView();
}); });
\ No newline at end of file
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