Skip to content
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(entity): add 'setOne' method #2410

Merged
merged 3 commits into from
Feb 27, 2020
Merged

Conversation

dmytro-gokun
Copy link
Contributor

@dmytro-gokun dmytro-gokun commented Feb 24, 2020

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[] Bugfix
[X] Feature
[] Code style update (formatting, local variables)
[] Refactoring (no functional changes, no api changes)
[] Build related changes
[] CI related changes
[] Documentation content changes
[] Other... Please describe:

What is the current behavior?

Closes #2369

Does this PR introduce a breaking change?

[] Yes
[X] No

@ngrxbot
Copy link
Collaborator

ngrxbot commented Feb 24, 2020

Preview docs changes for 1d05fa5 at https://previews.ngrx.io/pr2410-1d05fa5/

const updatedBook = {
id: TheGreatGatsby.id,
title: 'A New Hope',
description: undefined,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please remove the description altogether? With description: undefined even upsertOne would behave the same way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove it, that is not a problem. But that is the only way to test if 'setOne' actually behaves in a way different from 'upsertOne'. I mean, without this 'undefined' the test does not make much sense. Does it?

Copy link
Member

@alex-okrushko alex-okrushko Feb 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually does make more sense without that property. You can make a comment to be very explicit that we are updating the the entity that doesn't have that property and toEqual does the deep equality check.
With the test as-is even adapter.upsertOne(updatedBook, withOne) would pass.

I see that this PR is merged, I'd suggest to have a follow-up PR to adjust this test behavoir.

Copy link
Contributor Author

@dmytro-gokun dmytro-gokun Feb 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, we might have a misunderstanding here... Do you think we need to:

  1. remove line 429;
    or
  2. remove description property from the Book interface altogether?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the line from 429 and replace with /* description property is not provided */

it('should let you replace an entity in the state with setOne()', () => {
const withOne = adapter.addOne(
TheGreatGatsby,
adapter.addOne(AnimalFarm, adapter.addOne(AClockworkOrange, state))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
adapter.addOne(AnimalFarm, adapter.addOne(AClockworkOrange, state))
state

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understand this. The reason I'm adding three books to the collection here is to test that sorted adapter preserves the correct sorting order after a 'setOne' call. If I only have one book in the collection that is not checked anymore. Do you think that is okay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yea, that makes sense! Perhaps rename the withOne variable then tho

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. That's a copy&paste error :(. Should be fixed now.

docs/entity/adapter.md Outdated Show resolved Hide resolved
@brandonroberts brandonroberts merged commit 4b4bb85 into ngrx:master Feb 27, 2020
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.

@ngrx/entity add setOne (replaceOne?) method
5 participants