idelairre / ConstantFox

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

License:MIT License


Languages

Language:JavaScript 50.8%Language:HTML 49.2%