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

🐛Fix bind data when start and end are the same #21566

Merged
merged 5 commits into from
Mar 26, 2019

Conversation

cvializ
Copy link
Contributor

@cvializ cvializ commented Mar 25, 2019

Fixes #20727


/** @const */
this['end'] = dates[dates.length - 1];
this['end'] = map(dates[dates.length - 1]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we verify that dates.length > 0 anywhere? Also, why did the original cause a circular reference error?

Copy link
Contributor Author

@cvializ cvializ Mar 26, 2019

Choose a reason for hiding this comment

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

For your first question, getBindDates_ always takes at least one date, so the array will always have length 1 as currently written. But it could be good defensive programming practice to add a dev assert.
For your second question, when Bind attempts to deepMerge the new state with the old state, the deepMerge function marks objects in the new state as seen as it iterates through the state tree. If there is an object reference assigned to 2 properties of the new state object, it gets marked as seen and is encountered again, emitting the error. Not sure if this is WAI, but it's easy to work around.

amphtml/src/utils/object.js

Lines 105 to 107 in 391a431

if (seen.includes(s)) {
throw new Error('Source object has a circular reference.');
}

Copy link
Contributor

@cathyxz cathyxz left a comment

Choose a reason for hiding this comment

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

Got it. Thanks for the clarifications!

@cvializ cvializ merged commit a4b95a4 into ampproject:master Mar 26, 2019
@cvializ
Copy link
Contributor Author

cvializ commented Mar 26, 2019

Thanks for the review!!

fstanis pushed a commit to fstanis/amphtml that referenced this pull request Mar 26, 2019
* Fix bind data when start and end are the same

* Use standard for loop instead to avoid complexity

* Fix circular reference error from bind

* Use isSameOrAfter

* Fix missing externs
@cvializ cvializ mentioned this pull request Apr 2, 2019
@cvializ cvializ deleted the fix/date-range branch April 2, 2019 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants