realar-project / realar

5 kB Advanced state manager for React

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

low: add signal combine

betula opened this issue · comments

const a = value(0);

const s = signal.combine(a, () => a.val + 1); // readonly

s.watch(
  ([a, a_plus_one]) => console.log(a, a_plus_one)
);

// And I think it's possible to make `value.combine`
// Should be detected changes in each value and if some of them changed, fire changes outside

const v = value.combine(a, () => a.val + 1); // readonly
const value_combine = (...args) => {
  const sels = args.map((fn) => sel(fn)[0]);
  return selector(() => sels.map(s => s()));
}

Will be perfect. I should check new typescript tuples, and update typescript for vscode.

value.combine(a, b, (a, b) => ({ a, b}));

or make value.combine.view

value.combine.view([a, b], (a,b) => ({ a, b })) // Perfect!

One more example

 export const allReady = ready.from(
   signal.combine(backReady, frontReady).flow.filter(([back, front]) => (
     back && front
   ))
 );

"value.combine" added in 0.6.0
"signal.combine" declined