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
const exchangeRate = signal(0,
// Callback triggered when the signal begins to observe something.
() => {
const timer = setTimeout(async () => {
// Fetch the current exchange rate (of type number) using a request (fetch).
const currentExchangeRate: number = await fetch( .... );
// Set the exchange rate signal's value to the current rate.
exchangeRate.value = currentExchangeRate
});
// Callback triggered when the signal stops observing something.
return () => {
// Clear the timer.
clearInterval(timer);
};
}
);
interfaceSignalOptions<T>{// Custom comparison function between old and new value. Default: Object.is.// The signal is passed in as the this value for context.equals?: (this: Signal<T>,t: T,t2: T)=>boolean;// Callback called when isWatched becomes true, if it was previously false[Signal.subtle.watched]?: (this: Signal<T>)=>void;// Callback called whenever isWatched becomes false, if it was previously true[Signal.subtle.unwatched]?: (this: Signal<T>)=>void;}
watched and unwatched can be used, for example, to start (or stop) observing a foreign data source on demand, only when the signal is actually being used.
This callback could behave like this:
For example, MobX implements it like this:
https://mobx.js.org/lazy-observables.html
The text was updated successfully, but these errors were encountered: