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
constClock=resource(({ on })=>{constnow=cell(Date.now());constinterval=setInterval(()=>now.current=Date.now(),1000);on.cleanup(()=>clearInterval(interval));returnnow.current;})
vs
constClock=resource(({ on })=>{constnow=cell(Date.now());constinterval=setInterval(()=>now.current=Date.now(),1000);on.cleanup(()=>clearInterval(interval));return()=>now.current;})
The reason:
because the tracked data (.current), would be immediately consumed in the resource() body, the whole thing would be torn down when the clock updates (create a new interval each second). By using a function, only the function invalidates, you retain state, and keep the interval.
The text was updated successfully, but these errors were encountered:
Example:
vs
The reason:
.current
), would be immediately consumed in theresource()
body, the whole thing would be torn down when the clock updates (create a new interval each second). By using a function, only the function invalidates, you retain state, and keep the interval.The text was updated successfully, but these errors were encountered: