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

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.2.03,280latest

Version History

VersionDownloads (Last 7 Days)Published
0.2.03,280
0.1.32
0.1.20
0.1.12
0.1.00
0.0.62,875
0.0.50
0.0.40
0.0.30

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