@rhumaric/data-proxy
v0.3.0
Published
Template for NodeJS projects
Downloads
5
Readme
data-proxy
An experiment to create a proxy over one or many Object that:
- reads the property from the first object with it
- allow computed properties.
Usage
const {chainOfResponisibility, compute} = require('@rhumaric/data-proxy');
const proxy = chainOfResponsibility([
{
fileName: 'an/article--fr.md'
},
{
defaultLocale: 'en',
supportedLocales: compute(data => [data.defaultLocale, 'fr']),
locale: compute(data => getLocale(data.fileName)),
}
])
Possible future implementation
- [ ] Implement
has
handler - [ ] Implement
set
handler (on first object with property, or on injected new object first of the list) - [ ] Try out some memoisation?
- [ ] See if the concept could be genericised into some proxy builder
- [ ] Indexing of first source for each property
Possible other proxies usefulness
- [ ] caching of read values (nice for heavy computed operations, or values coming from deep down the source list). Bonus for uncaching when
set
ing. Extra bonus for uncaching computed properties (track which properties are accessed and use as a key for the cache? will there be a gain though, the key computation sound heavy?) - [ ]
change
events when setting value. Bonus for only triggering when the value actually change. Other bonus for having awillChange
that can be cancelled? - [ ] JSON proxy: delay
require
ing of JSON until the values are actually needed