inherit-model

1.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i inherit-model

Weekly Downloads

1

Version

1.1.0

License

MIT

Last publish

Collaborators

  • grant