Hash Accessor
Defines accessors to map class properties to a hash / object.
Creates getter and setter for given properties to map against a given hash.
You can use HashAccessor when using data objects (like from an API) within classes without the hassle of synchronizing classes' properties with data hashes.
You can define a mapping for each property in each class that is automatically applied every time you access the decorated properties.
Basic Usage
; console.loguser1.email; // => 'john@conclurer.com' user1.fullName = 'The Doctor';console.loguser1.data; // => 'The Doctor'
How to use it
- Use
@DeclareHash()
to decorate an object and define setters and getters for the properties hash - Use
@Accessor()
for each property withing the decorated object to store in the object's hash. You can also supply a custom key for each@Accessor()
to synchronize the property with.
protected prop1: any; // will be linked with key 'prop1' protected prop2: any; // will be linked with key 'otherKey'
Installation
Run
npm install --save hash-accessor