Git Product home page Git Product logo

store's Introduction

A feature-filled and friendly way to take advantage of localStorage and sessionStorage (JSON, namespacing, extensions, etc).

Download: store2.min.js or store2.js
NPM: npm install store2
NuGet: Install-Package store2

Build Status npm version npm

Documentation

The main store function can handle set, get, transact, setAll, getAll, each, and clear actions directly. Respectively, these are called like so:

store(key, data);                 // sets stringified data under key
store(key);                       // gets and parses data stored under key
store(key, fn[, alt]);            // run transaction function on/with data stored under key
store({key: data, key2: data2});  // sets all key/data pairs in the object
store();                          // gets all stored key/data pairs as an object
store((key, data)=>{ });          // calls function for each key/data in storage, return false to exit
store(false);                     // clears all items from storage

Parameters in [brackets] are optional. There are also more explicit and versatile functions available:

store.set(key, data[, overwrite]); // === store(key, data);
store.setAll(data[, overwrite]);   // === store({key: data, key2: data});
store.get(key[, alt]);             // === store(key);
store.getAll([fillObj]);           // === store();
store.transact(key, fn[, alt]);    // === store(key, fn[, alt]);
store.clear();                     // === store(false);
store.has(key);                    // returns true or false
store.remove(key[, alt]);          // removes key and its data, then returns the data or alt, if none
store.each(fn[, fill]);            // === store(fn); optional call arg will be 3rd fn arg (e.g. for gathering values)
store.add(key, data[, replacer]);  // concats, merges, or adds new value into existing one
store.keys([fillList]);            // returns array of keys
store.size();                      // number of keys, not length of data
store.clearAll();                  // clears *ALL* areas (but still namespace sensitive)

Passing in false for the optional overwrite parameters will cause set actions to be skipped if the storage already has a value for that key. All set action methods return the previous value for that key, by default. If overwrite is false and there is a previous value, the unused new value will be returned.

Functions passed to transact will receive the current value for that key as an argument or a passed alternate if there is none. When the passed function is completed, transact will save the returned value under the specified key. If the function returns undefined, the original value will be saved. This makes it easy for transact functions to change internal properties in a persistent way:

store.transact(key, function(obj) {
    obj.changed = 'newValue';// this change will be persisted
});

Functions passed to each will receive the key as first argument and current value as the second; if a fill parameter is specified, it's value will be the third argument for every call (few should ever need a fill parameter). If the function returns false at any point during the iteration, the loop will exit early and not continue on to the next key/value pair.

store.each(function(key, value) {
    console.log(key, '->', value);
    if (key === 'stopLoop') {
        return false;// this will cause each to stop calling this function
    }
});

All retrieval functions which take an optional alt parameter can also use that parameter to specify a "reviver" function. These receive each key and value (yes, nested ones too) as arguments and allow you to provide an alternate means of parsing that string. This is particularly useful for rich objects like Date types. See MDN's JSON.parse docs for more information and examples. Alternately, you can set a global reviver to the store._.revive property to handle all get, getAll, remove, and transact calls.

Likewise, setter functions which take an optional overwrite parameter can also use that parameter to accept a "replacer" function that receives each key and value (yes, nested ones too) as arguments and allow you to provide an alternate means of stringifying the values. This is particularly useful for rich objects like Map or Set. See MDN's JSON.stringify docs for more information and examples. Alternately, you can set a global replacer to the store._.replace property to handle all set, setAll, add, and transact calls.

For getAll and keys, there is the option to pass in the object or list, respectively, that you want the results to be added to. This is instead of an empty list. There are only a few special cases where you are likely to need or want this, in general, most users should ignore these optional parameters. These both use the second, optional argument each function, which is also a niche feature. The value argument is passed as the second arg to the callback function (in place of the data associated with the current key) and is returned at the end. Again, most users should not need this feature. All of these use the browser's localStorage (aka "local"). Using sessionStorage merely requires calling the same functions on store.session:

store.session("addMeTo", "sessionStorage");
store.local({lots: 'of', data: 'altogether'});// store.local === store :)

There is also a store API automatically available for keeping non-persistent information, meant only to last until page reload.

store.page("until","reload");

All the specific get, set, etc. functions are available on store.session, store.local, and store.page, as well as any other storage facility registered via store.area(name, customStorageObject) by an extension, where customStorageObject must implement the Storage interface. This is how store.old.js extends store.js to support older versions of IE and Firefox.

If you want to put stored data from different pages or areas f your site into separate namespaces, the store.namespace(ns) function is your friend:

var cart = store.namespace('cart');
cart('total', 23.25);// stores in localStorage as 'cart.total'
console.log(store('cart.total') == cart('total'));// logs true
console.log(store.cart.getAll());// logs {total: 23.25}
cart.session('group', 'toys');// stores in sessionStorage as 'cart.group'

The namespace provides the same exact API as store but silently adds/removes the namespace prefix as needed. It also makes the namespaced API accessible directly via store[namespace] (e.g. store.cart) as long as it does not conflict with an existing part of the store API.

The 'namespace' function is one of three "extra" functions that are also part of the "store API":

store.namespace(prefix);// returns a new store API that prefixes all key-based functions
store.isFake([force]);// test or set whether localStorage/sessionStorage or an in-memory, 'fake' storage is used

store.namespace can also take extra params to only create the namespace in the called-on storage area, and to pass in an alternate namespace delimiter for advanced use-cases (e.g. store.page.namespace("subpage", true, ":")).

If localStorage or sessionStorage are unavailable, they will be faked to prevent errors, but data stored will NOT persist beyond the life of the current document/page. Use the store.old.js extension to add persistent backing for the store API in ancient browsers.

isFake(true|false) is particularly useful to force use of a temporary, fake storage in testing situations, to prevent cluttering actual storage.

Extensions

These mostly could use further documentation and abuse...er...testing. Contributions are welcome! In particular, any ES6 user interested in making these importable in ES6 would be appreciated.

Beta - Stable and definitely useful

  • store.old.js - Add working localStorage and sessionStorage polyfills for ancient browsers
  • store.overflow.js - Fall back to fake storage on quota errors
  • store.cache.js - To make data expire, pass a number of seconds as the overwrite (third) param on set() calls
  • store.on.js - Superior storage event handling (per key, per namespace, etc in IE9+)
  • store.array.js - Easy, powerful array functions for any and all data (e.g. store.push(key, v1, v2)).
  • store.dom.js - Declarative, persistent DOM element content via store.
  • store.cookie.js - Support for a cookie as a storage area: store.cookie('num',1) to make sharing with backend easier.

Alpha - Either incomplete or unstable or both

  • store.quota.js - Register callbacks to handle (and even cancel) quota errors
  • store.measure.js - Experimental extension for measuring space used and available (needs work)
  • store.onlyreal.js - When only fake storage is available, silently fail instead of faking it.
  • store.dot.js - Creates accessors for keys (e.g. store.foo == store.get('foo'))
  • store.deep.js - Allow retrieval of properties from within stored objects (e.g. store.get('key.property'))
  • store.async.js - Adds store.async duplicate to each store and namespace that performs functions asynchronously and returns a Promise that resolves when complete.
  • store.cookies.js - Support managing all cookies as a storage area with the store API (e.g. store.cookies.get('user'))

Write Your Own Extension

To write your own extension, you can use or carefully override internal functions exposed as store._. In particular, the store._.fn(fnName, fn) method is available to automatically add your new function to every instance of the store interface (e.g. store, store.session and all existing and future namespaces). Take care using this, as it will override existing methods. Here is a simple example:

(function(_) {
    _.fn('falsy', function(key) {
        return !this.get(key);
    });
    _.fn('truthy', function(key) {
        return !this.falsy(key);
    });
})(store._);

This extension would be used like so:

store('foo', 1);
store.falsy('foo'); // returns false

store.session('bar', 'one');
store.session.truthy('bar'); // return true;

const widgetStore = store.namespace('widget');
widgetStore.falsy('state'); // returns true

Release History

  • 2010-02-10 v0.1 (extraction from esha.js)
  • 2010-05-25 v1.0 (internal release)
  • 2013-04-09 v2.0.3 (public) - First GitHub release
  • 2013-04-20 v2.1.0 (public) - Drops flawed/confusing/unused key(i) method, fixes extension problems.
  • 2013-04-30 v2.1.1 (public) - Browserify (and friends) support (module.exports = store)
  • 2013-05-30 v2.1.2 (public) - Component support (old component.json is now bower.json)
  • 2014-03-10 v2.1.6 (public) - AMD support and Component improvements
  • 2015-02-02 v2.2.0 (public) - Change store.cache.js to use seconds, not minutes.
  • 2015-05-05 v2.2.1 (public) - node.js compatibility
  • 2015-05-08 v2.2.2 (public) - Always expose global to allow extensions to always work.
  • 2015-05-22 v2.3.0 (public) - Use fake storage for Safari private mode (instead of letting quota exceptions go)
  • 2015-10-27 v2.3.2 (public) - Add source map
  • 2017-01-04 v2.4.0 (public) - Add store.transact(key, fn[, alt])
  • 2017-01-09 v2.5.0 (public) - Update for issue #34; new extensions (array, dot, and deep); only expose global in non-AMD/CommonJS environments (PR #35)
  • 2017-08-09 v2.5.2 (public) - Fix clear() in fake storage (thx to Martin Kluska)
  • 2018-01-18 v2.5.11 (public) - Add index.d.ts in root to provide TypeScript support
  • 2018-01-23 v2.6.0 (public) - Support each(fn,value), getAll(fillObj), and keys(fillList) to support some advanced/corner cases
  • 2018-11-15 v2.7.1 (public) - Add add(key, data) for common case of saving a combination of existing and new data. Fix issue #60.
  • 2019-07-23 v2.8.0 (public) - Add store(fn) shortcut for store.each, copy properties when inheriting, and make store.each(fn, fill) always send fill as 3rd arg instead of replacing values.
  • 2019-08-21 v2.9.0 (public) - Add store.remove(key, alt) to match behavior of store.get(key, alt) (Issue #68)
  • 2019-09-27 v2.10.0 (public) - Add store.page to provide page scope storage to complement local and session scope storage. (Issue #69)
  • 2020-03-23 [v2.11.0][] (public) - Add store.get(key, reviveFn) and ```store._.revive`` to support parsing for rich types (e.g. Date)
  • 2020-04-14 v2.11.1 (public) - Fix falsey alt value support in store.get(key, alt)
  • 2020-05-11 v2.11.2 (public) - Fix missing TS declaration of new page scope storage.
  • 2020-08-12 v2.12.0 (public) - PRs for better Storage typing, better testKey, and dev dependency updates.
  • 2021-12-16 v2.13.1 (public) - Add store.set(key, value, replacerFn), store._replace, and isFake([force]) to support stringifying rich types and easier testing. And cookie-based extensions for using store backed by a single 'store' cookie or store API for all cookies.
  • 2022-03-14 v2.13.2 (public) - Restore missing TS declaration of store.area(id[, area])
  • 2022-05-11 v2.14.0 (public) - Allow namespace delimiter to be changed via store._.nsdelim
  • 2022-07-14 v2.14.1 (public) - Fix change to set that broke store.cache.js, and allow namespace delimiter to be passed to namespace(name, thisAreaOnly, delim) for a single namespace, to avoid conflicts.
  • 2022-07-18 v2.14.2 (public) - Fix typo in index.d.ts typings.
  • 2024-02-14 v2.14.3 (public) - Cut license options to just MIT, also removed Bower and Component support since those are long dead.

store's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

store's Issues

How to import store.on?

First, thanks for this awesome lib..!

I'm using store2 on vue.js without problems, but now I want to import store.on, how to do it?

import Storage from 'store2' // WORKS!

// Uncaught TypeError: Cannot read property '_' of undefined
import StoreOn from 'store2/src/store.on'

So, why not include extensions via "ES6 Destructuring and Module imports"? It could be nice do this:

import Storage, {StoreOn, StoreOverflow, StoreQuota} from 'store2'

Thanks

is store asynchronous?

When I do store.get(key) ... it return undefined even though that key has a value... any help with that? When I do await store.get(key) it still doesn't work. Kindly advise.

How to import store.on in Node?

I know a similar question was posted a few years ago but I’m not sure that the OP was referring to importing in Node.js. How should that be done for store.on? Can someone post a simple example? I’m getting an error saying that the ‘on’ method does not exist. Thank you.

How to achieve permanent storage on NodeJS?

Once we restart a NodeJS application using store2, it loses all the stored values.

How can we have permanent storage on NodeJS with this lib?

Should this be on the docs?

Observable available in store2?

Hi,
Sorry for my bad englisch before ... :)
Currently we evaluate whether we could use store2 in our projects.

For better understanding our requirements:
The pages in our applications are based on multiple web-apps based on Vue.js, React or Vanilla, etc ... at same time.

We need a store for our application states.
My question is:
Is there a functionallity in your library to use "Observables" that any applications will triggert automatically by changes where variables from the store are used?

[EDIT]
Another improvement will be to have promises that I can sure that my value is updatet successful in my store like this:

window.store.transact('test', (obj) => {
    obj.test++;
}).then((updatedValue) => {
    window.EventEmitter3.emit("button.clicked", window.store('test'));
    // or ...
    window.EventEmitter3.emit("button.clicked", updatedValue);
);

... same fpr set() or setAll() ...

If I am blind or do not understand your documentation then "sorry" so far. :)

Best regards,
Mario

install for component vs bower

Just saw this on the component wiki, looks excellent and definitely something I can use. I am glad it spares me the work of rolling my own.

But your component.json is in Bower's format I think, not component's... in the newer versions of Bower, it looks like component.json is deprecated in favor of bower.json to avoid this conflict.

If you want I can send you a pull request with component's component.json, and your component.json renamed to bower.json.

Use number as key

When I use number to get value, it go to the wrong way.

e.g.
var cache = store.namespace('test')
cache(1, true)
console.log(cache(1))

In the store function, it just charge the string type, but sometimes the key will be number.
Should I pull request to solve this issue?

Is there a way to write plugins (custom methods) for this?

Is there a way to write plugins (custom methods) for this? The Marcus Westin version did but I'm trying to switch to your store package.

I have this code in my plugin for Marcus' package and I want to move it over.

window.store.addPlugin(() => {
    return {
        pull (_, key) {
            const value = this.get(key);
            this.remove(key);
            return value;
        },
        has (_, key) {
            return (typeof this.get(key) !== 'undefined');
        }
    };
});

Take personal opinion out of library

In src/store2.js there's an attempt to set a key/value pair of: '_safariPrivate':'sucks', it'd be better if this was changed to something banal that didn't carry opinion.

Fake Storage question

I have 2 questions:

1 - I think that if the browser does not support local storage, it falls back to a memory based storage? Can I prevent that from happening? (I may store large amount of info there and I do not want it to cause any slowness in browser. So, I would like to know if local or session storage is enabled on user's browser b4 attempting to save anything).

2 - How do I know if localStorage or sessionStorage is supported? What would be equivalent to store2.isLocalStorageSupported() and store2.isSessionStorageSupported()? Are they store.isFake() and store.session.isFake(), respectively?

Thanks!

Add store.one() method to store.on.js

I'm finding myself needing to attach an event handler to a key's change event only once. I'm used to jQuery's .one() method and am emulating it right now with:

function myStoreOne(key, fn)
{
    var handler = function(e){
        store.off(key, handler); // unbind to prevent future events.
        return fn.call(this, e);
    };
    store.on(key, handler); // bind to the event.
}

Would be nice to be able to just call store.one(key, fn) instead.

Error in ie calling store.session()

First of all, great job =)

I'm using this lib with direct import from html and calling the command store.session() on ie results in error.
The error is on this function:
key: function(area, i){ return area.key(i); }

I still don't know why ie does not support this but I changed the code to fix this problem to me as follow:
key: function(area, i){ try { return area.key(i); } catch (e) { return Object.keys(area)[i]; } }

Hope this can help you somehow

Thanks

Request for memStorage

Please consider adding support for a temporary (dies on page reloads) memory storage object (dubbed it 'memStorage' :)).
This way, store would become the go-to state repository library for any app and any scenario, be it vanilla or otherwise. Redux no more.
Thanks!

cant able to import store2 version 2.5.5 in *.ts file in angular 2

Installed npm store2 2.5.5 version in my angular 2 solution.
using the command npm install store2

When i tired to import the store2 in required *.ts file as below
import * as store from 'store2';
Getting error as
"node_modules/store2/store.d.ts' is not a module." when trying to run the solution

Any help will be appreciated.

How to achieve similar features like Object.assign?

First: store(key,{id:1,name:'John'})
I get: {"id":1,"name":"John"}
Then: store(key,{age:40})
I get: {"age":40}
How can I expect to get: {"id":1,"name":"John","age":40}
Thanks!

(I translated these into English with Tencent Mr. Translator :))

Incompatible IE

I'm not compatible with IE browsers. Am I using the wrong way?

store.on.js extension not triggering events

Hi! First of all thank you for taking the time to create store, the API seems very well thought out. It looks like a perfect fit for my project (especially since it supports namespacing) but I seem to run into some problems when I try to use store.on.js with this simple code:

<script src="src/store2.js"></script>
<script src="src/store.on.js"></script>
<script>
	store.on('foo', function(){ console.log('event'); });
</script>

I get TypeError: this._out is not a function at store.on.js:25:21 in console as soon as I open a second tab with the same code. Debugging shows that this refers to window which seems to be a problem, I tried using an arrow function on line 24 to preserve this binding to store like this var listener = (e) => { unfortunately opening two tabs and runing store.set('foo', 'bar') in console does not trigger the event in another tab.

I am not a frontend dev so I might be doing something wrong, would you mind having a look?

make default value configurable

At least getAll and keys have internal _and argument of each method

I currently call getAll() on empty localStorage and I want to get some exception/rejection or null because I cannot check {} without ugly workarounds and extra libraries

I can propose PR with followed API backward-compatible updates:

  • getAll(default = [])
  • keys(default = [])
  • rename _and to default

Suggestion: use a different name

Not really that important, but you could use a different name everywhere (e.g. "ngstore", "storeplus" or even "store2" on bower, too) to avoid the name clash on npm.

Example with addClass, removeClass and toggleClass

Would you be so kind provide some simple examples for saving a class and toggling a class please?
like some basic JQuey functions addClass, removeClass and toggleClass.

Or even better if there is pure JS example for those type of common usage?

Enhancement for store.get

Would you consider integrating a pull request that allows for set-ting the alt value of a store.get call in the case the requested key does not exist in the store? As far as I can tell this is currently not possible (in a single call). This enhancement would mean adding a an extra parameter store.get(key[, alt][, write]);.

Not supporting cross-tabs

Hi,

Currently it is only supporting same page/tab, but not working in multiple tabs for same pages/application. Now days, it is a basic use case that users would open same app on multiple tabs.

Please update me if this can be accommodated.

Thanks

`remove` has different signature than `get`

First of all, thanks for the great library! It's wildly useful.

I was using get(key, {}) to default to an object, and then I realized that I needed to "pull" the key, so I switched to using remove(key, {}), but found that remove doesn't accept the optional alt second argument.

Is that intentional? It would be quite helpful for me if those signatures were the same.

Thanks!

Support AMD

If you are willing I could create a AMD integration as well.

Minified and SourceMap

Hi,

This library is great!
I'm using BOWER repository to download my front-end modules, and fortunately you already supply a minified version but not its SourceMap. Can you provide that too?

some error in stringify function

var _ = {
stringify: function(d) {
return d === undefined || typeof d === "function" ? d+'' : JSON.stringify(d);
}
}
if typeof d === 'string', d will be stringifyed again
for example, store.local.set(key, value) // key = 'test', value = '{test: 1}'
then value in localstorage will be "{"test":1}"

It seems not support IE ?

Hi nbubna,
Thanks for your awesome store lib, Can It support IE8+?

I use the latest code, write a test, but it seems not work on IE8,IE10.
It show the error as below:
"1.global failure (1, 0, 1)Rerun0 ms1.对象不支持此属性或方法Source: http://localhost:63342/storeExample/js/store.array.js:43
2.global failure (1, 0, 1)Rerun0 ms1.对象不支持此属性或方法Source: http://localhost:63342/storeExample/js/store.dom.js:65
3.localValue (0, 1, 1)Rerun1 mstest local store pass
4.global failure (1, 0, 1)Rerun0 ms1.类不能支持 Automation 操作Source: http://localhost:63342/storeExample/js/store.overflow.js:27 "

The test html code is as below:

<script src="libs/qunit/qunit.js"></script> <script type="text/javascript" src="js/store2.js"/> <script type="text/javascript" src="js/libs/jquery/jquery.js"/> <script src="js/store.bind.js"></script> <script src="js/store.cache.js"></script> <script src="js/store.old.js"></script> <script src="js/store.overflow.js"></script> <script src="js/store.quota.js"></script> <script src="js/store.measure.js"></script> <script src="js/store.array.js"></script> <script src="js/store.dot.js"></script> <script src="js/store.deep.js"></script> <script src="js/store.quota.js"></script> <script src="js/store.dom.js"></script> <title>test store</title> <script type="text/javascript"> function test() { // console.log(store.session); // store.set("localKey","localValue"); // alert(store2); testLocalStore(); testSession(); testNamespaceLocal(); testNamespaceSession();
    }
    function testLocalStore() {
        store.local("localKey","localValue");
        QUnit.test("localValue",function (assert) {
            assert.equal(store.get("localKey"),"localValue","test local store pass");
        });
    }
   function testSession() {
        store.session("sessionKey","sessionValue");
       //console.log(JSON.stringify(store));
       QUnit.test("store.session",function (assert) {
           assert.equal(store.session.get("sessionKey"),"sessionValue","test session value pass");

// assert.equal(store('cart.total') ,23.25);
})
}
function testNamespaceSession() {
var apple = store.namespace('com.sw.mft',false);
apple.session("nssessionKey","nssessionValue");
// console.log(apple.toString());
// console.log(apple.getAll().toString());
// console.log(store["apple"]);
QUnit.test("store.testNamespaceSession",function (assert) {
assert.equal(store["com.sw.mft"].session.get("nssessionKey"),"nssessionValue","test session value pass");
// assert.equal(store('cart.total') ,23.25);
})
}
function testNamespaceLocal() {
var cart = store.namespace('cart');
cart('total', 23.25);
cart('group', 'toys');
QUnit.test("namespace",function (assert) {
assert.equal(store.cart.get("group"),"toys","test namespace local value pass");
assert.equal(store('cart.total') ,23.25);
})
}
test();
</script>

NuGet Update

Is it possible to get the NuGet package updated to 2.3? It's showing 2.1 right now. Thanks!

[question] Asynchronous read/write support?

The documentation doesn't specify how this module manages asynchronous read/write (e.g., chrome.storage.local).

Also is there a way to specify a hierarchy of storage fallback options within the module?

Initialization fails if localStorage is not available

store.js fails to initialize if localStorage is not available, but sessionStorage is.

I request a change so that store.session is initialized separately from store(.local). Each would only be initialized if the required storage facility (local/session) is available.

Normally both local and session storage are available, but I have run into valid scenarios with IE10 in 32 bit mode on Windows 8 where session storage is available and local storage is not.

Example naive fix:
(line 202->)

var store;
if (typeof(window.localStorage) === 'object') {
    store = _.Store('local', window.localStorage);
    store.local = store;// for completeness

    // safely setup store.session (throws exception in FF for file:/// urls)
    store.area("session", (function () { try { return sessionStorage; } catch (e) { } })());
} else {
    store = _.Store('session', window.sessionStorage);
    store.session = store;// for completeness
}
store._ = _;// for extenders and debuggers...
window.store = store;

persistent local storage for different namespaces?

Hi,
First of all, I would like to express my heart-felt congratiude for your creation of such a brilliant tool!
I am having a problem and would like some help.
I am trying to store two different categories of things data:

  1. a list of passages, with the title of the passage as key, and the text body as value
  2. a list of sentences, keyword as key, sentences as value
    I would like the two stores to be persistent so that the next time a user launches the browser, the passages and the sentences are still there, and can be retrieved.
    I tried to use:
    var passage_store = new store.namespace('passages')
    var sentence_store = new store.namespace('sentences')
    But they are not persistent because, I guess, each time the browser launches, a new instance of store is created which is not the same as the previous launch of the browser.

As long as I can keep the stores separate and persitent, whatever technique, be it namespace or whatever, is alright.

Any help is greatly appreciated,and thank you in advance.
best regards
Jim

app.js in /dist

what is this file for and why don't you explain anywhere its purpose?

get() method does not return empty string as alt value

get() method does not return empty string as alternative value

To reproduce:

const expectedVal = '';
const actualVal = store2.get('inexistent_key', '');
console.log({
	expectedVal,
	actualVal,
	isOk: expectedVal === actualVal
});

P.S. Great library, Thank you.

dist not distributed in npm

22 days ago you updated the package.json to point to "dist/store2.js", but the dist directory isn't included in the npm module

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.