1.0.2 • Published 8 months ago

object-subscriptions v1.0.2

Weekly downloads
-
License
-
Repository
github
Last release
8 months ago

object-subscriptions

Nested object with mutations and subscribers

Examples

Calculate and Subscribe

import {NestedObjectWithSubscriptions} from "object-subscriptions";

const obj = new NestedObjectWithSubscriptions();

obj.set("aa.bb", 123);
obj.set("cc.dd", 123);

obj.calculate(["aa.bb", "cc.dd"], (a, b) => {
    return a + b;
}, "ee.ff")

obj.subscribe("ee.ff", (value) => {
    console.log("VAL!", value);
});

Custom Separator and Traversal

import {NestedObjectWithSubscriptions} from "object-subscriptions";

const obj = new NestedObjectWithSubscriptions({}, {separator: '/'});

obj.set("aa/bb", 123);
obj.set("cc/dd", 123);

obj.calculate(["aa/bb", "cc/dd"], (a, b) => {
    return a + b;
}, "ee/ff")

obj.subscribe("ee/ff", (value) => {
    console.log("VAL!", value);
});


for(let [pathParts, value] of obj.entries({pathParts: true})) {
    console.log(pathParts, value);
}

Defer execution

import {NestedObjectWithSubscriptions} from "object-subscriptions";

const obj = new NestedObjectWithSubscriptions({}, {separator: '/'});

obj.set("aa/bb", 123);
obj.set("cc/dd", 123);

obj.calculate(["aa/bb", "cc/dd"], (a, b) => {
    return a + b;
}, "ee/ff", {defer: true})

obj.subscribe("ee/ff", (value) => {
    console.log("VAL!", value);
});

for(let [pathParts, value] of obj.entries({pathParts: true})) {
    console.log(pathParts, value);
}

Debounced calculation

import {NestedObjectWithSubscriptions} from "object-subscriptions";

const obj = new NestedObjectWithSubscriptions({}, {separator: '/'});

obj.set("aa/bb", 123);
obj.set("cc/dd", 123);

obj.calculate(["aa/bb", "cc/dd"], (a, b) => {
    return a + b;
}, "ee/ff", {debounce: 100, immediate: false})

obj.subscribe("ee/ff", (value) => {
    console.log("VAL!", value);
});

for(let [pathParts, value] of obj.entries({pathParts: true})) {
    console.log(pathParts, value);
}

Take a slice

import {NestedObjectWithSubscriptions} from "object-subscriptions";

const obj = new NestedObjectWithSubscriptions({}, {separator: '/'});

obj.set("aa/bb", 123);

const child = obj.child("aa");

console.log("VAL!", child.get([]));
1.0.2

8 months ago

1.0.1

9 months ago

1.0.0

10 months ago

0.3.5

12 months ago

0.3.4

12 months ago

0.3.3

12 months ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.0

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.3

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.1

3 years ago