Skip to content

adds equals:true#2688

Open
titoBouzout wants to merge 1 commit intosolidjs:nextfrom
titoBouzout:equals-true-0429-jm0we
Open

adds equals:true#2688
titoBouzout wants to merge 1 commit intosolidjs:nextfrom
titoBouzout:equals-true-0429-jm0we

Conversation

@titoBouzout
Copy link
Copy Markdown
Contributor

Summary

Theres createMemo(() => props.value, { equals: false })
This PR adds the reverse, createMemo(() => props.value, { equals: true }), which effectively stops the memo from updating.

Its done by creating a new function isAlwaysEqual similar to the current isEqual, and using it when equals:true.

The motivation, is having a core way to stop things from being reactive (similar to how things can be declared overly reactive with equals: false ).

It kills the need for a createOnce.

const initial = createMemo(() => count(), {equals: true})
return <div data-initial={initial()} data-current={count()}/>

Disclaimer, made it with claude.

Claude attempted to unlink the computation from recompute() function, possibly an optimization, but made it back off from that as I would prefer you do these optimizations yourself.

How did you test this change?

added tests
pnpm test

@ryansolid
Copy link
Copy Markdown
Member

I'm not sure this is necessary.. this is to save writing { equals: () => true }. However this does encode a different semantic meaning. I suppose equals false does as well if you take createMemo to literally mean its a memo. But if you take it to mean a derived computation then the decision to bypass(or provide) default equality seems reasonable. This just never notifies and sits there and recomputes over and over.

What you really want I think is:

const initial = createMemo(() => untrack(count));

Which will not create the dependency unless its originally async, then when it resolves it will have the updated value.

I guess the setter writes is the one exception for why you would override equality but I'm not really following generally. Like isn't untrack the core way we stop stuff from being reactive?

@titoBouzout
Copy link
Copy Markdown
Contributor Author

That sounds reasonable, but its incredible verbose

const initial = createMemo(() => untrack(() => props.count ));

Having it as equals: true would be intuitive (the opposite of equals:false) and easier to write

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants