deep-computed
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

deep-computed

Iterates over plain objects and arrays and transforms functions to computed properties

Use

If an object or array has a function as a value, it will be wrapped by Object.defineProperty and its getter will pass the root object to it as an argument to resolve the value of the function. For example,

import { deepComputed, Computed } from "./deepComputed";
 
type MyType = {
  cool: number;
  dude: number;
  deep: {
    ly: {
      nested: {
        coolAndDude: number;
      };
    };
  };
};
 
const obj: Computed<MyType> = {
  cool: 123,
  dude: 456,
  deep: {
    ly: {
      nested: {
        coolAndDude: ({ cool, dude }) => cool + dude
      }
    }
  }
};
 
const next = deepComputed(obj);
 
console.log(next.deep.ly.nested.coolAndDude);
// => 579

Install

yarn install deep-computed

Readme

Keywords

none

Package Sidebar

Install

npm i deep-computed

Weekly Downloads

6,159

Version

0.2.0

License

MIT

Unpacked Size

8.35 kB

Total Files

10

Last publish

Collaborators

  • garbles