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
constcounter=signal(0);constdoubleCounter=computed(()=>counter.value*2)console.log(doubleCounter.peek())// print undefined, computed callback was not executed due to laziness.console.log(doubleCounter.value)// print 0counter.value=2console.log(doubleCounter.peek())// print 0, again, a stale value from last update is returned due to laziness.
this can be fixed by refreshing the internal signal's value before peek() into it.
this feels like a peek() with side-effects ... are we sure that's desired?
if you mean a peek() can trigger an immediate evaluation, I tried @preact/signals-core and it does the same.
That feels natural to me since peek() is essentially trying to access the value, do you think of other scenarios.
dunno ... these days I am more keen to use something like this instead https://github.com/WebReflection/alien-signals#readme so if you think that's expected/desired and both alien-signals and preact signals work the same ... works for me.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
computed.peekis not returning the latest value.this can be fixed by refreshing the internal signal's value before
peek()into it.