inherit-model
A simple Backbone-inspired model wrapper for the `inherit` package
Last updated 6 years ago by granttimmerman .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install inherit-model 
SYNC missed versions from official npm registry.

inherit-model

A simple Backbone-inspired model wrapper for the npm inherit package

Why?

  • Universal getter and setter methods get and set. Don't have 100s of getters and setters.
  • Don't accidentally set properties of classes that aren't defined again. Fields are strict.
  • Simple toJSON.
  • Easy default fields.
  • Keeps things lightweight.

Example

inherit = require 'inherit'
Model = require 'inherit-model'

User = inherit Model,
  __constructor: (params = {}) ->
    # Set the field names permanently
    @fields
      username: undefined
      friendIds: []

    # Call the super class (DON'T FORGET!!!)
    @__base(params)

user = new User username: 'grant'
user.set 'username', 'gdawg'

console.log user.toJSON() # {username: 'gdawg', friendIds: []}

See the tests for more exampless.

Install

npm install inherit-model --save

Current Tags

  • 1.1.0                                ...           latest (6 years ago)

3 Versions

  • 1.1.0                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 3
Dependencies (2)
Dev Dependencies (2)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |