derived-property
Create a derived property for an object
Install
Install with npm
$ npm install derived-property --save
Usage
var derivedProperty = ; var obj = first: 'Gilad' last: 'Peleg' var displayName = ; // apply the derived propertyObject; console;// => 'Gilad Peleg' // later on..objfirst = 'John';console;// => 'John Peleg'
API
derivedProperty
derivedProperty(options)
Create a derived property. Returns a response
that should be applied using Object.defineProperty(obj, 'property', response)
options
getter
{Function}: Getter function to do the calculation. Gets the values of dependencies as arguments.dependencies
{Array}: Optional list of properties to depend on.cache
{Boolean}: Whether to use the cached result if dependencies haven't changed. Defaults totrue
. Set off for non-pure derived properties (i.e - relies onDate.now()
).getMethod
{Function}: Optional getter method to access the dependencies on the object. Defaults tolodash.result
.compareMethod
{Function}: Optional compare method to check if the dependency has changed. Defaults to===
.
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
Run tests
$ npm test
Related
License
MIT ©Gilad Peleg