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

Memoized utils methods for useMap #592

Merged
merged 2 commits into from
Sep 5, 2019

Conversation

Granipouss
Copy link
Contributor

@Granipouss Granipouss commented Sep 5, 2019

Hey guys,

Here is my proposal following the issue #456

All feedbacks are more than welcome

Cheers

@xobotyi xobotyi requested a review from Belco90 September 5, 2019 13:30
Copy link
Contributor

@Belco90 Belco90 left a comment

Choose a reason for hiding this comment

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

You need some additional asserts for checking the callbacks instances. If after adding that the test passes, I'm happy with the implementation :)

utils.set('foo', 'baz');
});

expect(result.current[1]).toBe(utils);
Copy link
Contributor

Choose a reason for hiding this comment

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

You are checking here that utils object is the same instance, but that doesn't mean that returned callbacks are same instances, so you would have to check that utils.get is result.current[1].get and so on.

Copy link
Contributor

Choose a reason for hiding this comment

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

In fact it does mean that internals are the same (due to useMemo instead of bunch of useCallback), but that, more precise check of result.current[1].get wont be excessive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is indeed working just fine, but I guess an additionnal test assertion can make it more visible

Copy link
Contributor

@Belco90 Belco90 left a comment

Choose a reason for hiding this comment

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

Indeed, just reading the implementation you can see how it will the same instance, but better to assert that explicitly so if tomorrow that implementation changes, the test will check for proper callback instance, not just the object.

@xobotyi xobotyi merged commit 4fc2e36 into streamich:master Sep 5, 2019
@Granipouss Granipouss deleted the feat-memoized-useMap branch September 5, 2019 13:53
@streamich
Copy link
Owner

🎉 This PR is included in version 12.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

None yet

4 participants