Extends ImmutableJS Records enabling class inheritance
Dependencies
Getting Started
npm install extendable-record --save
Usage
; { return true; } { return true; } // default properties describe the set of properties which can be// set/read. Properties are exposed via getters, so you can use the syntax// var model = new BaseModel();// console.log(model.value);BaseModeldefaultProperties = value: null; { return thisvaluelength; } { return thisvaluelength !== 0; } { return typeof thisvalue === 'string'; } { return this; } // default properties extend and overwrite the properties of// the parent. Here, TextModel instances will always default to '',// but we do have the option of adding extra propertiesTextModeldefaultProperties = value: ''; { return super && /^[^@]+@[^\.]+\.$/; } { return typeof thisvalue === "number"; } { return this; } { return thisunits ? ` ` : thisvalue; } NumberModeldefaultProperties = value: 0 units: null; const bobsEmail = value: 'bob@gmail.com';console; // trueconsole; // falseconsole; // true -- bobsEmail has not been mutated const myBank = units: 'dollars';console; // 0 dollarsconst myBankAfterDreamOfWinningLotto = myBank;console; // 100000000 dollarsconsole; // 0 dollars -- myBank was not mutated :(
Credits
- ImmutableJS for underlying data structures
- npm-starter
- Airbnb for the work they've put into the javascript style guide and into the ESlint package.
License
MIT @ Joe Delgado