Created
March 20, 2012 12:45
-
-
Save tshm/2134907 to your computer and use it in GitHub Desktop.
Revisions
-
tshm revised this gist
Apr 12, 2012 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,5 @@ /* [MIT licensed](http://en.wikipedia.org/wiki/MIT_License) */ // custom agilityjs adapter for localstorage (function($$, console) { -
tshm revised this gist
Apr 12, 2012 . 1 changed file with 44 additions and 32 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,32 +1,44 @@ /* [MIT licensed](http://en.wikipedia.org/wiki/MIT_License) (c) [Toshihide Shimayama](http://github.com/tshm/todomvc/) */ // custom agilityjs adapter for localstorage (function($$, console) { 'use strict'; $$.adapter.localStorage = function(_params) { var storageKey = (this._data.persist.baseUrl || '') + this._data.persist.collection, storageStr = localStorage[storageKey], items = (storageStr ? JSON.parse(storageStr) : {}); // if ('GET' === _params.type) { if (undefined !== _params.id) { // normal get if ('object' === typeof items[_params.id]) { _params.success(items[_params.id]); } else { _params.error(); } } else { // gather call _params.success(items); } } else if ('DELETE' === _params.type) { delete items[_params.id]; localStorage[storageKey] = JSON.stringify(items); } else if ('PUT' === _params.type || 'POST' === _params.type) { if (undefined === _params.id) { _params.id = (new Date()).getTime(); _params.data.id = _params.id; } items[_params.id] = _params.data; //_params.success({id:_params.id}); localStorage[storageKey] = JSON.stringify(items); } else { _params.error(); } _params.complete(); }; })(window.agility, window.console); -
tshm revised this gist
Mar 20, 2012 . 1 changed file with 32 additions and 34 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,34 +1,32 @@ // custom agility adapter for localStorage $$.adapter.localStorage = function(_params) { var key = (this._data.persist.baseUrl || '') + this._data.persist.collection; var value = localStorage[key]; var items = (value && value.length > 0 ? JSON.parse(value) : []); switch (_params.type) { case 'GET': if (_params.id) { // normal get if (items[_params.id]) { _params.success(items[_params.id]); } else { _params.error(); } } else { // gather call _params.success(items); } break; case 'DELETE': _params.data = undefined; // continue into POST case case 'PUT': // continue into POST case case 'POST': if (!_params.id) { _params.id = items.length; _params.data.id = _params.id; } items[_params.id] = _params.data; //_params.success({id:_params.id}); localStorage[key] = JSON.stringify(items); break; } _params.complete(); }; -
tshm created this gist
Mar 20, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ // custom agility adapter for localStorage $$.adapter.localStorage = function(_params) { var key = (this._data.persist.baseUrl || '') + this._data.persist.collection; var value = localStorage[key]; var items = (value && value.length > 0 ? JSON.parse(value) : []); console.log(_params, items); switch (_params.type) { case 'GET': if (_params.id) { // normal get if (items[_params.id]) { _params.success(items[_params.id]); } else { _params.error(); } } else { // gather call console.log(items); _params.success(items); } break; case 'DELETE': _params.data = undefined; // continue into POST case case 'PUT': // continue into POST case case 'POST': if (!_params.id) { _params.id = items.length; _params.data.id = _params.id; } items[_params.id] = _params.data; //_params.success({id:_params.id}); localStorage[key] = JSON.stringify(items); break; } _params.complete(); }