0.1.6 • Published 10 years ago

@frzr/collection v0.1.6

Weekly downloads
12
License
MIT
Repository
github
Last release
10 years ago

collection

FRZR Collection inspired by Backbone.js

installation

// with frzr
npm install frzr

// standalone
npm install @frzr/collection

require

// with frzr
var Collection = require('frzr').Collection

// standalone
var Collection = require('@frzr/collection')

usage

var collection = new Collection(options)

options

  • idAttribute: attribute to use as id
  • index: attributes to index
  • add: triggers when Model is added
  • change: triggers when Model is changed
  • remove: triggers when Model is removed
  • move: triggers when Model is reordered
  • model: custom extended model

Any other parameter will be added as a local attribute

Example

var options = {idAttribute: 'a'}
var CustomModel = Model.extend(options)

var items = [{a: 1, b: 2}, {a: 2, b: 3}]
var options = {
  idAttribute: 'a',
  index: 'b',
  add: add,
  change: change,
  remove: remove,
  model: CustomModel
}

var collection = new Model(options)
collection.reset(items)

function add (model) {
  console.log('added', model)
}
function change (model) {
  console.log('changed', model)
}
function remove (model) {
  console.log('removed', model)
}
collection.reset([{
  a: 2,
  b: 3,
  c: 4
}, {
  a: 3,
  b: 4
}])

// or
var CustomCollection = Collection.extend(settings)
var collection = new CustomCollection(data)

methods

  • get(id): get model by id
  • set(items): set models
  • reset(items): reset models (remove if necessary)
  • unset(id): remove model by id

events

  • add: triggered when Model is added
  • change: triggered when Model is changed
  • move: triggered when Model is reordered
  • remove: triggered when Model is removed
0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago