proposal-signals icon indicating copy to clipboard operation
proposal-signals copied to clipboard

Intermediate values ​​are ignored, which may not be what we want (immediate effects)

Open neuronetio opened this issue 7 months ago • 2 comments

import { Signal } from "signal-polyfill";
import { effect } from "./effect.js";

function heavyComputation() {
  console.log("Heavy computation");
}

const LoadingProgressBarVisible = new Signal.State(false);

effect(() => {
  const show = LoadingProgressBarVisible.get();
  console.log("show", show);
});

LoadingProgressBarVisible.set(true); // ignored
heavyComputation();
LoadingProgressBarVisible.set(false);

// result: progress bar will not be displayed
// show false
// Heavy computation
// show false

I know that this problem can be solved differently (this is just an example), but there may be situations in which intermediate values ​​will also be important and it would be nice if it was possible to read them somewhere and, above all, perform some effect immediately (knowing that it will not be subject to the glitch-free rule). At the moment, I do not see a possibility to do something like this using the effect in the current form of signals.

I understand that the whole concept is that effects and computed are delegated to the very end (glitch-free graph topology) but a problem similar to the one presented above will surely appear at some point so maybe it would be good to have some tool that will solve this problem.

neuronetio avatar May 05 '25 13:05 neuronetio

I think the proposal should reconsider seeing the lossy behaviour as a feature. There are many use-cases for Signals outside of UI updates, e.g. streaming, logging, fast consequent calculations, see: https://github.com/buiapp/reaktiv, https://www.angulararchitects.io/blog/streaming-resources-for-a-chat-with-web-sockets-messages-in-a-glitch-free-world/

buiapp avatar Jun 04 '25 09:06 buiapp

I wonder what you all think about the Signals vs. https://github.com/benlesh/w3c-observable breakdown should be. I was operating under the understanding that Observables would be a better solution for cases where you need to capture each intermediate value. I think one of the original goals of this project was to standardize around the existing popular Signals libraries.

jkup avatar Jul 14 '25 13:07 jkup