realar-project / realar

5 kB Advanced state manager for React
MIT License
45 stars 0 forks source link

low: add signal combine #50

Closed betula closed 3 years ago

betula commented 3 years ago

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
betula commented 3 years ago

const value_combine = (...args) => {
  const sels = args.map((fn) => sel(fn)[0]);
  return selector(() => sels.map(s => s()));
}
betula commented 3 years ago

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!
betula commented 3 years ago

One more example

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

Simple combine added https://github.com/betula/realar/commit/4f007ce1add81e94ab99b93ed98f94dd5718f0a8#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80R332

betula commented 3 years ago

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