Reputation: 21
Is it possible, that angular signals (and derived computes) ignore some fast value changes? I have websocket and each message from ws is written into signal, but in one moment can come more than hundred messages and signal or effect does not react on this amount of messages and/or react on every let's say 20th message. I'm not sure, but Ang. v18 was OK, but it dramatically changed at v19. Does anybody met this problem? Thanks for your replies or advice
this.__webSocket.onmessage = (event: MessageEvent) => {
try {
const {deserializer} = this.__config;
deserializer && this.__messagesSg.set(deserializer(event)); // <-- this line
undefined !== this.__errorSg() && this.__errorSg.set(undefined);
} catch (error: unknown) {
void Promise.resolve().then(() => {
this.__errorSg.set(error);
});
}
};
Upvotes: 2
Views: 90
Reputation: 57986
The effect runs lazily, after bundling the signal changes, if there are multiple updates in between.
This is more efficient, since rarely do we need a call trigger for intermediate updates of a signal.
Effects do not execute synchronously with the set (see the section on glitch-free execution below), but are scheduled and resolved by the framework. The exact timing of effects is unspecified.
If you find this behavior not suitable. Call the effect callback, directly after the set
method, this should achieve the immediate update behavior.
someCallback() {
this.someSignal.set([ .... large array ]);
// execute effect logic below.
}
Upvotes: 1