Linen (line-in) maps API's to bindable objects
, and collections
. At classdojo, we use linen
to abstract our API from front-end, so we don't necessarily depend on any sort of API while developing new components. This allows us to rapidly build prototypes which can be wired up later.
Here's an example person schema:
var linen = ; linen;
To use the schema, simply call the following:
var person = linen //creates a new personexistingPerson = linen; //some ID
Linen works by overriding the bind
method to fetch from any API you have setup, so when you call:
//calls GET /people/someIdexistingPerson;
The existingPerson
will asynchronously call .to(fn)
when it's been loaded from the server. This is useful when data-binding to any sort of UI component, such as rivets.js, or paperclip.js.
Here's another example of data-binding to linen
models:
// GET /people/someId/friendsexistingPerson;
The above examples make it easy to abstract models from any API. To demonstrate this, here's an example of using dummy data
:
var existingPerson = firstName: "Ron" lastName: "Burgundy" friends: firstName: "Brian" lastName: "Fontana" firstName: "Brick" lastName: "Tamland" firstName: "Champ" lastName: "Kind" ; existingPerson; existingPerson;
API
linen()
Returns a new linen instance
linen.addSchema(definition)
adds a new schema
definition
Inspired by mongoose:
linen;
linen.model(schemaName[, modelId ])
returns a new, or existing model