entity-cache.js
entity-cache.js manages your JavaScript objects in caches.
Features
- Makes sure that there is only one instance of every unique entity (identified by an id property)
- Recursively updates existing entities with new data
- Properties, which do not exist in the updated data object, will not be updated
- Automatically resolves entity dependencies by foreign keys using other entity-caches
- If entity dependencies do not exists while an entity is added to the cache, the dependencies will be resolved as soon as these become available
- Provides events if new entities are added to a cache or entities are removed from a cache
- Supports and coded in TypeScript
Installation
npm install entity-cache-js --save
Examples
Initialize an entity-cache
var entityCacheJs = ; { thispersonId = personId; thismotherId = motherId; thisfatherId = fatherId; thisfirstName = firstName; thislastName = lastName; thisaddress = address;} var personCache = 'person' Person 'personId'; personCache;personCache;
Add an entity instance to the cache
personCache;personCache;personCache;
Use entities
var johnDoe = personCache; //use mother referenceconsole; //prints Julia //iterate over all entitiesforvar i in personCacheentities console;
Update existing entity
console; //prints 12345 personCache; console; //prints 98765
Bugs
There may be still a few bugs. Please report them!
License
MIT