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

Refactor systemTag changes to stop directly mutating note object #1615

Merged
merged 1 commit into from
Oct 2, 2019

Conversation

dmsnell
Copy link
Member

@dmsnell dmsnell commented Oct 2, 2019

See #1614

As part of a broader effort to resolve data-flow issues in the app this PR is a
first step in removing direct mutation where transactional atomic updates
should be occurring.

It's not clear if the existing code is the source of existing defects in the software
and this is part of why the code is problematic; we have created inherent
concurrency flaws that open up extremely-difficult-to-reproduce bugs.

Resolving this may or may not resolve any existing bugs but it will definitely
help guard us from introducing new ones.


Replaces #1611
Replaces #1613

Previously we have been directly mutating the note object in the action
creator when toggling a note's pinned status, markdown status, publish
status, and trash status.

This mutation can lead to concurrency defects which expose themselves as
inconsistent UI state. This breaks our Redux model which assumes that
all UI updates happen atomically.

In this patch we're building a new note object when toggling these
system tags in order to maintain our consistency.

At the same time I have removed the thunks from the action creators
since they weren't doing anything and didn't need to exist. This
shouldn't have a noticeable impact on the application.

Previously we have been directly mutating the note object in the action
creator when toggling a note's pinned status, markdown status, publish
status, and trash status.

This mutation can lead to concurrency defects which expose themselves as
inconsistent UI state. This breaks our Redux model which assumes that
all UI updates happen atomically.

In this patch we're building a new note object when toggling these
system tags in order to maintain our consistency.

At the same time I have removed the thunks from the action creators
since they weren't doing anything and didn't need to exist. This
shouldn't have a noticeable impact on the application.
Copy link
Contributor

@belcherj belcherj left a comment

Choose a reason for hiding this comment

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

Code looks good testing works well

} = note;
const hasTagAlready = systemTags.includes(systemTag);

return hasTagAlready !== shouldHaveTag
Copy link
Contributor

Choose a reason for hiding this comment

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

This took me a while to parse. No idea how it could be any simpler but it took me some time to figure out what was going on.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I don't know the best phrasing. This was the simplest I got.

if ( noteIsAlreadyInAStateWhereThePresenceOrAbsenceOfTheTagMatchesTheExpectationOnceThisFunctionEnds )
const tagIsAlreadyInNote = systemTags.includes(systemTag);
const shouldAddTagToNote = ?

In my previous work at least there was convention that should_ indicates a desire to enact the thing and that it's boolean. Here in JS land we only have a single type any so the language doesn't help us out like it does in statically-typed languages.

Any recommendation or just noting that it's something that could be better some how?

@dmsnell dmsnell merged commit 987714f into develop Oct 2, 2019
@dmsnell dmsnell deleted the refactor/remove-mutation-systemTags branch October 3, 2019 03:24
@loremattei loremattei modified the milestones: 1.10, 1.9 Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debt Tech debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants