-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat(Store/Effects): Make toPayload type safe #161
Conversation
Nice job figuring out the |
@bfricka Thanks! I hope it is OK for the project--I wasn't thrilled with having to add another Interface. I'm also kind of surprised that it worked--I thought that |
I think we would rather just deprecate |
@MikeRyanDev Because it has been in ngrx for some time, and because the example app encourages its use, I'd say we should be more careful about removing it and forcing all users to adapt. Asking users to pay for a serious mistake by adapting is one thing; this is a trivial utility function that arguably doesn't hurt the library overall. On the other hand, because it IS a utility function, it is really easy for a user to reimplement it and just change their import statements. If you don't decide to deprecate and remove this, this PR, or something like it, should be merged; because In the balance, I could go either way, but lean slightly toward deprecation, with a caveat: Deprecating in 5 and removing in 6, unless you plan to release 5 almost immediately, is unfair to the users who may be moving to ngrx today. I'd say you should deprecate in 4.1 (compatible with semver) and remove in 5, and release 4.1 without delay. |
I agree w/ everything @karptonite just said :) |
@MikeRyanDev so you guys are basically aiming to actions without payloads? where everything should be in the app state and retrieved from it to make a state transition? |
@jotatoledo I'm pretty sure that is not what he is going for. Removing |
@MikeRyanDev any further thoughts on this? If you still think that the best option is to deprecate |
@karptonite I'm not quite sure I understand the need for the ActionWithPayload interface. Imho, that's something to be left to the user. Same goes for toPayload. In the least it could probably be a separate helper-project, but not part of core... |
@yngvebn yes, I lean toward deprecating toPayload. But if it won't be deprecated, it might as well be type safe, and, as I wrote a couple comments above, there is no need for the extra interface. |
@karptonite Let's merge in a deprecation PR instead. |
Just in case someone is missing map(action => action.payload), // this the same as toPayload(),
switchMap(payload => this.myService.fetch(payload.blah)), do the following: switchMap(({payload}) => this.myService.fetch(payload.blah)), |
This is a followup for PR #157, and should probably replace it.
It makes the
toPayload()
function type safe, such that it infers the type of the payload, as long as either the type is specified whenofType
is called, or the newofClass
method (see #160, assuming it is merged) is used to filter the action.It still requires the addition of the ActionWithPayload interface, but the user shouldn't have to declare their actions with that interface (although it might be best to do so)--it should be able to be inferred.