node package manager
Painless code sharing. npm Orgs help your team discover, share, and reuse code. Create a free org »

lilmodel

lilmodel

A li'l backbone-ish model object.

Browser usage

load dist/lilobj.js or dist/lilobj.min.js in you browser and call it like this:

(function () {
 
  var model = require('lilmodel').model;
 
  var beer = model.extend({
 
    defaults: {
      sizeInLiters: 0.5,
    },
 
    rules: {
      type: ['required', 'string']
      sizeInLiters: ['required', 'number', ['gte', 0.2]]
    }
 
  });
 
  var dunkel = beer.create({
    type: 'lager',
  });
 
  dunkel.save(function (err) {
    //callback from sync  
  });
 
}());

Node usage

install the module with: npm install lilmodel

var beer = model.extend({
 
  defaults: {
    sizeInLiters: 0.5,
  },
 
  rules: {
    type: ['required', 'string']
    sizeInLiters: ['required', 'number', ['gte', 0.2]]
  }
 
});
 
var dunkel = beer.create({
  type: 'lager',
});
 
dunkel.save(function (err) {
  //callback from sync  
});

Documentation

syncr(syncMethod)

model.extend(config)

model.create(properties)

model.validate()

model.save(callback, context)

model.fetch(callback, context)

model.destroy(callback, context)

model.serialize()

collection.extend(config)

collection.create(propertiesList)

collection.validate()

collection.add(properties)

collection.remove(query)

collection.get(query)

collection.find(query, callback, context)

collection.serialize()

License

Copyright (c) 2012 August Hovland Licensed under the MIT license.