Skip to content

Facade for the Chrome local storage api that allows synchronous access to locally stored values.

License

Notifications You must be signed in to change notification settings

idelairre/ConstantFox

Repository files navigation

ConstantsFox

Utility for TumblrFox that synchronously accesses stored values. Automatically detects JS environment and adapts storage strategy. Emits change, initialization, and reset events.

Functions very similarly to a Backbone model.

Examples

const constants = new Constants({
  dat: 'boi',
  ohShit: 'whaddup'
});

constants.get('dat') // return 'boi'
constants.get('ohShit') // returns 'whaddup'

constants.get({ dat: '', ohShit: '' }) // returns { dat: 'boi', ohShit: 'whaddup' }
constants.get({ dat: '', ohShit: '', isTheWorst: 'meme' }) returns { dat: 'boi', ohShit: 'whaddup', isTheWorst: 'meme' }
constants.get('isTheWorst') // returns 'meme';

const constants = new Constants();

for (let i = 0; i < 11; i += 1) {
  constants.set('i', i);
}

constants.previous(i); // returns 9

// a few hours later...

const constants = new Constants({
  i: 0
});

constants.get('i') // returns 10
constants.previous('i') // returns 0

ConstantsFox is meant to be as simple as possible. It is legal (for now) to directly access stored members. Just don't write to them unless you want things to get funky.

const constants = new Constants({
  wut: 'i dunno'
});

constants.wut // return 'i dunno'

Dependency Status devDependency Status

About

Facade for the Chrome local storage api that allows synchronous access to locally stored values.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published