Skip to content

fix: Internal Referencing for Increment Dot Notation #1255

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

Merged
merged 5 commits into from
Nov 12, 2020

Conversation

dplewis
Copy link
Member

@dplewis dplewis commented Nov 12, 2020

This PR is building upon #1219, together they solve the following issues.

There was a internal referencing issue that resulted in the increment to happen every time you get the attributes
Lucky this .get returns the proper value so clients aren't affected. (Fixed in this PR).

const obj = new TestObject();
obj.set('objectField', { number: 5 });
obj.increment('objectField.number', 15);
console.log(obj.attributes); // Internally number is 20
console.log(obj.attributes); // Internally number is 35
console.log(obj.attributes); // Internally number is 50

When you save with increment there is an extra attribute returned from _handleSaveResponse (Fixed in #1219)

{
  objectField: { number: 20 },
  createdAt: 2020-11-11T17:35:48.317Z,
  updatedAt: 2020-11-11T17:35:48.337Z,
  'objectField.number': 15 // Has been removed
}

When saving after using increment nested, the full object isn't returned. (Fixed in #1219)

{
  objectField: { number: 20, letter: 'a' }, // Didn't return 'a' before when using increment nested
  createdAt: 2020-11-11T17:35:48.317Z,
  updatedAt: 2020-11-11T17:35:48.337Z,
}
  • Also adds error listener to test server. Useful for catching 'Address in Use` errors.

When merged with the server this will work in beforeSave / afterSaves hooks.

@codecov
Copy link

codecov bot commented Nov 12, 2020

Codecov Report

Merging #1255 (3268681) into master (f443834) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1255   +/-   ##
=======================================
  Coverage   99.98%   99.98%           
=======================================
  Files          57       57           
  Lines        5403     5405    +2     
  Branches     1199     1199           
=======================================
+ Hits         5402     5404    +2     
  Misses          1        1           
Impacted Files Coverage Δ
src/ObjectStateMutations.js 100.00% <100.00%> (ø)
src/ParseObject.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f443834...3268681. Read the comment docs.

Copy link
Member

@davimacedo davimacedo left a comment

Choose a reason for hiding this comment

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

It looks good but I believe you should revert the changes in the package-lock, right?

@dplewis dplewis merged commit 49df2f5 into master Nov 12, 2020
@dplewis dplewis deleted the increment-nested-bug branch November 12, 2020 23:40
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.

2 participants