Skip to content

Commit

Permalink
more docs for quickstart
Browse files Browse the repository at this point in the history
  • Loading branch information
brianleroux committed Jul 19, 2011
1 parent bbb5e19 commit c0dbfd8
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions doc/sugar.md
Expand Up @@ -6,24 +6,32 @@ 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.
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__.

aquarium.save([{key:'shark'}, {key:'whale'}], 'console.log(record)');

:::JavaScript
aquarium.sava([{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 js 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`).
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`).


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


this functionality exends throughout the library for any method.


:::JavaScript
var store = new Lawnchair(function() {

this.save({key:'nitobi'}, function(obj) {
Expand All @@ -35,31 +43,48 @@ this functionality exends throughout the library for any method.
// 0
})
})


chaining supported
---

ah chaining, how mid 2000's


:::JavaScript
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.


:::JavaScript
var people = new Lawnchair();


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

var people = Lawnchair();

:::JavaScript
var people = Lawnchair()


probably not surprisingly the `Lawnchair` constructor optionally accepts a callback!


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


it also optionally accepts a config obj for terse callback param injection.


:::JavaScript
var people = Lawnchair({name:'people', record:'person'}, function () {
this.save({key:'joni'}, 'console.log(person)')
Expand All @@ -68,10 +93,14 @@ it also optionally accepts a config obj for terse callback param injection.
this.all('console.log(people)')
// [{key:'joni'}]
})


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


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

0 comments on commit c0dbfd8

Please sign in to comment.