Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (63 sloc) 1.49 KB

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.