You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
createNotifier is great when you want to imperatively notify an effect or linked signal.
The missing part is when you have multiple signals that when any gets changed you want to notify without using an effect.
It allows better encapsulation as you can pass the notifier signal as parameter without knowing why it changed (imperatively or by linked signals).
This allows for example a function with state that needs to get reset on certain scenarios to accept a reset notifier which will reset the state using a linked signal.
That notifier might be invoked by an outside signal or imperatively - but the function only knows it got notified.
Currently you need to pass a Signal<unknown> for reset and also add a reset function for imperative reset. Or create a notifier and computed for notifier and other signal and pass it.
API could be: createLinkedNotifier([signalA, signalB, signalC]) and you can still notify imperatively.
The text was updated successfully, but these errors were encountered:
constsignalA=signal(1);constsignalB=signal('test');constnotifier=createLinkedNotifier([signalA,signalB]);effect(()=>{notifier.listen();console.log('signalA changed or signalB changed or notified imperatively!');});signalA.set(5);// Notified!// Later...signalB.set('hello');// Notified!// Later...notifier.notify();// Notified!
This will allow passing notifier as parameter and invoke a change either imperatively like now or through a signal that was passed to createLinkedNotifier.
I can provide initial implementation too.
createNotifier
is great when you want to imperatively notify an effect or linked signal.The missing part is when you have multiple signals that when any gets changed you want to notify without using an effect.
It allows better encapsulation as you can pass the notifier signal as parameter without knowing why it changed (imperatively or by linked signals).
This allows for example a function with state that needs to get reset on certain scenarios to accept a reset notifier which will reset the state using a linked signal.
That notifier might be invoked by an outside signal or imperatively - but the function only knows it got notified.
Currently you need to pass a
Signal<unknown>
for reset and also add a reset function for imperative reset. Or create a notifier and computed for notifier and other signal and pass it.API could be:
createLinkedNotifier([signalA, signalB, signalC])
and you can still notify imperatively.The text was updated successfully, but these errors were encountered: