Skip to content
This repository was archived by the owner on Nov 29, 2019. It is now read-only.
/ browser-storage Public archive

just simple browser storage with namespace support

License

Notifications You must be signed in to change notification settings

dudiq/browser-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Browser-storage adapter

just simple browser storage with namespace support. Adapter for localStorage, sessionStorage in browser

##how to use:

 //bind to local-storage
 var myLocalStorage = JrMakeStorage('prefix', 'local-storage', window.localStorage);
 
 //bind to session-storage
 var mySessionStorage = JrMakeStorage('prefix', 'session-storage', window.sessionStorage);
 
 myLocalStorage('myKey', 'myWord'); - set single key
 myLocalStorage.remove('myKey); - remove single key
 myLocalStorage.clear(); - remove all keys
 myLocalStorage.setPrefix(); - set prefix to this plugin localStorage keys
 myLocalStorage.map(cb, opt) - walk in stored keys
 
 myLocalStorage.on(cb) - bind callback data changes on other tab with current domain
 myLocalStorage.off(cb) - unbind callback

event structures and data:
 evData = {
              key: key,
              newValue: newValue,
              type: type
          }
 //type have two values:
 
     myLocalStorage.EVENT_TAB // fires when in current tab value is changed
     myLocalStorage.EVENT_STORAGE // fires when other tab is changed value
          

... somewhere in far far code ...

    var MY_KEY = 'myKey';
    var myFirstVal = myLocalStorage('myKey') // return 'myWord'
    
    myLocalStorage.on(function(evData){
        // fired when data changed
        if (evData.key == MY_KEY) {
            var firedVal = evData.newValue; // return 'myWord'
        }
    }) 

licence: MIT, dudiq 2017

About

just simple browser storage with namespace support

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published