@rhumaric/data-proxy

0.3.0 • Public • Published

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 seting. 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 a willChange that can be cancelled?
  • [ ] JSON proxy: delay requireing of JSON until the values are actually needed

Readme

Keywords

none

Package Sidebar

Install

npm i @rhumaric/data-proxy

Weekly Downloads

3

Version

0.3.0

License

MIT

Unpacked Size

9.77 kB

Total Files

13

Last publish

Collaborators

  • rhumaric