-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(signal-slice): simplify api to deal with typing issues #361
Conversation
I didn't use this due to its experimental-ness and questionability in general. I would say this is a fair change. #363 looks like a fair alternative.
I have been enjoying the dedicated One idea that is probably overkill but it seems adjacent to #363: some |
Thanks for the feedback! I do agree that it's nice to have the
I think given the I'm not sure I'm completely following your idea with also having an I suppose if you have both effect(() => {
mySignalSlice.someSelector();
}); vs effect(() => {
mySignal();
}); |
I wrote that response barely out of bed so to be honest I don't know exactly what I was getting at either. I think I was just looking at the other PR's alternative Overall, the way you define those options now I agree it's worth dropping. And I discussed this PR today with a coworker and they also agreed that dropping the |
Hello @joshuamorony |
@eneajaho do we consider the removal of APIs marked as experimental as breaking?
|
Oh, okay. cc @nartc |
BREAKING CHANGE: experimental actionEffects API has been removed from signalSlice
bbc69bb
to
39d84de
Compare
@eneajaho I figure it's probably useful to include the breaking change message either way, so I've edited the commit with the message |
@nartc I'll double check using the anonymous function for passing the config works as expected, and if so I'll update this PR to remove the deprecation of Then I'll put up a separate PR for making the breaking API change from Will mark this as draft for now and ping when this one is ready |
@nartc nevermind, I was mistaken about the API change, the issue persists anyway (and I'm pretty sure there is no simple way to get around the type inference issue). We can proceed with the original plan of removing actionEffects + deprecating effects. EDIT: in case we want to dig this up again in the future, this tweet contains context for the underlying issue: https://x.com/Nartc1410/status/1800574473097371946 and Matt Pocock also wrote an article about it: https://www.totaltypescript.com/property-order-matters |
Hello everyone and thank you for a great repo full of amazing tools ! Quick question, is there a roadmap for the release of this PR and #363 ? Thanks again ;) |
From my end this is all good and should ready to be merged (there haven't been any changes since Chau's previous review). After this is merged I will update/check/review #363 but that should also be ready to go. |
TLDR: This removes
actionEffects
entirely (this has always been marked as experimental) and adds a deprecation warning foreffects
(which was marked as stable)Both the
effects
andactionEffects
configurations introduce a great deal of typing complexity, some of these issues are (likely) fundamentally unsolvable without making the utility more complex. I think it makes sense to keepsignalSlice
as a simple utility, rather than having it scope creep into a full state management library.effects
was really only ever for convenience/style anyway, andactionEffects
is of questionable value.The convenience of the
effects
configuration is in my opinion not worth the complexity/issues it introduces.The
actionEffects
configuration was added as a way to trigger a side effect as the result of some source/actionSource emitting without needing to introduce new values into the state signal (which would then allow creating side effects using the standard Angulareffect
to react to these values being set in the signal)However, the current implementation is not a total solution anyway, because if your
actionEffect
requires some value to be passed in it will mean theactionSource
needs to emit that value, which means that it would still need to be added to the state signal anyway (because emissions from action sources are treated as partials that update the state). AnactionEffect
really only achieves its purpose for situations where you want to react to some action without needing to pass any values.Overall, I think the
actionEffect
API is not a full solution in the first place and it also introduces a lot of complexity which is why I favour removing it.This does make side effects for "events" a little more difficult, however it is still possible to do by setting version values into the state signal via action sources and then using standard signal effects, e.g:
The
actionSource
you want to create a side effect for would just need to increment the relevant property in the state signal.It may be a good idea to revisit alternatives in the future (e.g. maybe we can just add something that automatically does this "versioning" behind the scenes and exposes it to react to (edit: I've put up a PR for this: #363)), but in any case I think that
actionEffects
is not a good API and makes the typing too complex.