Simple JSON Storage

Lawnchair: Simple JSON Storage


mmmm, so good to be bad! if this is wrong I don't wanna be right. etc.

terse callbacks

my favorite feature of lawnchair shamelessly stolen from dojo. lawnchair dynamically generates a function saving you keystrokes. this is standard javascript and won't break anything except possibly douglas crockford's heart.[{key:'shark'}, {key:'whale'}], 'console.log(record)');

You are correct in noticing the magical record parameter in the example above. by default, lawnchair will create either record or records for passed in parameters. you can change these by giving your lawnchair a name and record config in the constructor. you can read more about constructors below.

scoped everything everywhere

like the great magnificent birds of the world the javascript programming language frees us to rebind the current execution scope of an anonamous function to any object. it is a language feature that has found general acceptance (unlike, perhaps, the prototype and various techniques of eval).

var store = new Lawnchair(function() {
    console.log(this === store) 
    // true

this functionality exends throughout the library for any method.

var store = new Lawnchair(function() {{key:'nitobi'}, function(obj) {

        // {key:'nitobi'}

        // 0

chaining supported

ah chaining, how mid 2000's

this.nuke().save({msg:'first post'}) // something annoying about this...

crazy constructors

the new keyworld/operator gets some flack. maybe it deservies it but in any case its here.

var people = new Lawnchair()

or not... you decide. neither is right or wrong and there is no sense in being a dick about it.

var people = Lawnchair()

probably not surprisingly the Lawnchair constructor optionally accepts a callback!

// fuck, async makes me HOT
var people = Lawnchair(function() { /* awesome persistence here */})

The constructor also optionally accepts a configuration object for terse callback named parameter injection. Why yes, I did just make that nonesense up!

var people = Lawnchair({name:'people', record:'person'}, function () {{key:'joni'}, 'console.log(person)')
    // {key:'joni'}

    // [{key:'joni'}]

additionally the ctor callback gets passed the current lawnchair instance which can save bytes and comes in handy for closures

var people = Lawnchair(function (ppl) {
    console.log(ppl === this && this === people)
    // true