svelte icon indicating copy to clipboard operation
svelte copied to clipboard

Svelte 5: Put `unstate` on `$state` rune?

Open brunnerh opened this issue 1 year ago • 2 comments

Describe the problem

Since unstate is linked to $state, it might make sense to make it a function on $state. unstate is also a bit of an odd/non-word.

Describe the proposed solution

Not sure about the name, maybe one of

$state.remove / $state.removed $state.clear / $state.cleared $state.off

Importance

nice to have

brunnerh avatar Feb 07 '24 12:02 brunnerh

putting this on the milestone in the sense of "we need to decide whether or not we want to do this until 5.0"

dummdidumm avatar Feb 08 '24 13:02 dummdidumm

Domain hack-ish idea: $state.less()

Not-Jayden avatar Feb 10 '24 12:02 Not-Jayden

We decided to keep untrack as a function, given how rare its usage is (and should be).

dummdidumm avatar Apr 06 '24 12:04 dummdidumm

@dummdidumm This was about unstate not untrack, you did see that, right?

brunnerh avatar Apr 06 '24 13:04 brunnerh

Oops sorry - reopening . We haven't decided that one yet, though it may go in the same direction

dummdidumm avatar Apr 06 '24 16:04 dummdidumm

I don't think we need a new rune for this right now. We can always leave it for now make it one later, but doing the reverse it going to be much harder.

trueadm avatar Apr 08 '24 16:04 trueadm

I think the main thing that would appeal to me about making this a rune would be the possibility of doing this without wrapping the expression in a function. E.g., we could have $untrack(foo) instead of untrack(() => foo).

Conduitry avatar Apr 08 '24 16:04 Conduitry

@Conduitry This is for unstate though, which doesn't suffer from that problem.

trueadm avatar Apr 08 '24 16:04 trueadm

Oh, apologies. I can't read. Never mind!

Conduitry avatar Apr 08 '24 16:04 Conduitry

Considering how unstate has been confused with untrack twice here in the same thread, both by major contributers (which is a great example of the oddness of unstate), I think that at least a rename should be considered. I think remove more clearly represents what unstate does ($state.remove(), removeState(), etc.), and I think the word ignore better represents what untrack does ($ignore(), $state.ignore(), ignoreState()).

I also like $state.less() as a possibility since it's shorter and clever.

I was thinking the word removed might better indicate how the function is non-destructive (like toSpliced), however, that might lead developers to expect a clone when they might not get one, i.e. if a non-reactive object is passed.

apokaliptis avatar Apr 13 '24 09:04 apokaliptis

We decided that the confusion over the naming of this function warranted it being a new rune after all.

trueadm avatar Apr 15 '24 15:04 trueadm

I agree with the comment on the PR that $state.clean is not the clearest name. I thought their suggestion of $state.raw or $state.toRaw was reasonable.

benmccann avatar Apr 15 '24 17:04 benmccann