Skip to content

Commit

Permalink
Initial v0.1.0 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikael Brassman committed Jun 5, 2013
0 parents commit 4924169
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
############
## OS Specific
############

# Windows image file caches
Thumbs.db

# Folder config file
Desktop.ini

# Mac crap
.DS_Store

#############
## Node Specifics
#############
node_modules
9 changes: 9 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "knockout.persist",
"version": "0.1.0",
"ignore": [
"**/.*",
"node_modules",
"components"
]
}
30 changes: 30 additions & 0 deletions knockout.persist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*! Knockout Persist - v0.1.0 - 2013-06-05
* https://github.com/spoike/knockout.persist
* Copyright (c) 2013 Mikael Brassman; Licensed MIT */
(function(ko) {

// Don't crash on browsers that are missing localStorage
if (typeof (localStorage) === "undefined") { return; }

ko.extenders.persist = function(target, key) {

var initialValue = target();

// Load existing value from localStorage if set
if (key && localStorage.getItem(key) !== null) {
try {
initialValue = JSON.parse(localStorage.getItem(key));
} catch (e) {
}
}
target(initialValue);

// Subscribe to new values and add them to localStorage
target.subscribe(function (newValue) {
localStorage.setItem(key, ko.toJSON(newValue));
});
return target;

};

})(ko);
4 changes: 4 additions & 0 deletions knockout.persist.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*! Knockout Persist - v0.1.0 - 2013-06-05
* https://github.com/spoike/knockout.persist
* Copyright (c) 2013 Mikael Brassman; Licensed MIT */
(function(e){"undefined"!=typeof localStorage&&(e.extenders.persist=function(t,o){var r=t();if(o&&null!==localStorage.getItem(o))try{r=JSON.parse(localStorage.getItem(o))}catch(a){}return t(r),t.subscribe(function(t){localStorage.setItem(o,e.toJSON(t))}),t})})(ko);

0 comments on commit 4924169

Please sign in to comment.