-
-
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
fix(data): make options optional on add with partial #3043
Conversation
Preview docs changes for 34522c3 at https://previews.ngrx.io/pr3043-34522c36/ |
@yharaskrik maybe the intention was to enforce explicitly adding the isOptimistic: false option to an add with a partial and I'm wrong with the fix I've provided. Bu it does seem redundant to me to require the options with at least the isOptimistic: false when add() defaults to isOptimistic false. Open to your thoughts. |
I think I may have messed up, my intention was to say: If options are not provided || isOptimistic: false then |
@yharaskrik what I see is if you provide Looking back a few commits it looks like your intent was to add the ability to use a A bit late to the game here but the original signature of
this required you to be explicit about which fields were optional and simplified the signature with no @e-oz was the issue you ran into an existing piece of code that was working in an earlier version that stopped working on upgrade. Or new code written after upgrading to the latest version? |
@donohoea old (and not even mine) code refused to compile. |
@@ -143,7 +143,7 @@ export class EntityCollectionServiceBase< | |||
*/ | |||
add( | |||
entity: Partial<T>, | |||
options: EntityActionOptions & { isOptimistic: false } | |||
options?: EntityActionOptions & { isOptimistic: false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this change undo that desired behavior that @yharaskrik added? And make it worde because we allow a Partia<T>
now?
I think the problem here, is that TS doesn't see this as an overload.
What about adding another overload where options
is optional and T can't be a partial (the original implementation)?
add(
entity: Partial<T> | T,
options: EntityActionOptions & { isOptimistic: false }
): Observable<T>;
add(entity: T, options?: EntityActionOptions): Observable<T>;
add(entity: T, options?: EntityActionOptions): Observable<T> {
return this.dispatcher.add(entity, options);
}
That way, you can either provide them, leave them out, and when optimistic is false then T
is a partial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right @timdeschryver I was mistakenly seeing the implementation as an overload. My only issue with the solution you suggested is that my expectation as a user would be that this would be acceptable:
this.storyDataService.add(story as Partial<Story>)
Given that isOtimistic: false is the default. But that's not the issue we're trying to solve here and is I believe the strict typing @yharaskrik was aiming for and was accepted earlier so I'll update the PR.
seems like my updates invalidated nx caching on the |
Hey guys, sorry it's been a wild week for me. My intention was to allow a partial to be passed in if optimistic was false but if it was true (or left out, so true by default) then it was not partial. I know some ideas here have been thrown out due to TS not picking it up as an overload. Let me know if you guys need my input on this or if you have it figured out. In regards to the code using some old cache and not compiling. I have no idea how that could have happened and would love to know to prevent it in the future. It all seemed to work last time I spun it up! (A while ago though.) |
@yharaskrik it has nothing to do with the cache. Parameter was optional, now it's required - code can’t be compiled, if parameter is not set. As you see - there is no any old cache. |
@e-oz this is what I was referring to. I understand the parameter was setup wrong. I must have made a mistake I just don't know how it passed everything if it wasn't able to be compiled. |
@yharaskrik I don't think the build error is related to your code or mine, all builds work for me after deleting
|
@donohoea can you rebase to please? |
ec0b781
to
34522c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Works great with 12.2, thanks! |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Closes #3041
What is the new behavior?
Does this PR introduce a breaking change?
Other information