helium-sdx
SDx is short for "Source Derivation," and it's a relationship between "source" variables and "deriver" functions. Deriver functions run every time their source dependencies update.
import {Source, derive} from "helium-sdx";
const source = new Source(1);
derive(() => console.log(source.get()));
source.set(2):
Quick Reference Example (QRE)
Here's most of the general functionality
import {
Source, derive, Sourcify, SourceArray,
SourceMap, deriverSwitch, DerivationManager,
awaitSource, DdxSource
} from "helium-sdx";
const source = new Source(1);
const sourceArray = new SourceArray([1, 2, 3]);
const sourceMap = new SourceMap([["a", 1], ["b", 2], ["c", 3]]);
const state = Sourcify({
a: 1,
b: {
c: 3,
d: [1, 2, 3]
}
});
derive(() => {
console.log(
source.get()
+ sourceArray.get(2)
+ sourceMap.get("c")
)
});
derive({
anchor: "NO_ANCHOR",
batching: "fiveSec",
allowEqualValueUpdates: true,
dependenciesNeverChange: true,
fn: () => {
DerivationManager.debugDeriver();
console.log(state.a + state.b.c);
}
});
deriverSwitch({
watch: () => (source.get() + state.a) % 2,
responses: [
{ match: 0, action: () => console.log("even")},
{ test: /1/, action: () => "TRY_NEXT_ACTION"},
{ match: 1, action: () => console.log("odd")}
]
});
const ddxSource = new DdxSource(
() => (source.get() + state.a) % 2
);
derive(() =>
console.log(ddxSource.get() === 0 ? "even" : "odd")
)
derive(() => {
const asyncVal = awaitSource("someId", () =>
new Promise<number>((res) => setTimeout(res, 1500))
);
if (asyncVal === undefined) {
console.log("Waiting for promise to resolve");
} else {
console.log(asyncVal);
}
})
For web app stuff, checkout helium-ui
P.S. I hope something good happens to you today