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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: switch to new context API #40

Merged
merged 3 commits into from
Mar 9, 2019

Conversation

peternoordijk
Copy link
Contributor

@peternoordijk peternoordijk commented Feb 9, 2019

This PR switches this library so that it uses the new context API. Aside from that nothing really changes. However this switch required quite a lot of changes.

I'm not sure if we have to make a version change when releasing this code. I think this change will be breaking for React < 16.3 .

Why do we need this change?

Aside from the obvious technical debt I also got some code for React hooks coming in. The only problem with that is that those hooks depend on the useContext function, which in turn needs this change.

// Upcoming hook example

const {
  snapshot, error, isLoading, data,
} = useDatabase()
  .collection('users')
  .where('foo', '==', bar)
  .onSnapshot();

I got the hooks code working already, I just need some more unit tests. Once that's done you'll see another PR incoming 馃槃 (I just created a PR: it's #41 )

@peternoordijk
Copy link
Contributor Author

Oh I guess I need some more coverage...

@codecov
Copy link

codecov bot commented Feb 9, 2019

Codecov Report

Merging #40 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #40   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           6      6           
  Lines          88     90    +2     
  Branches       18     19    +1     
=====================================
+ Hits           88     90    +2
Impacted Files Coverage 螖
src/FirestoreDocument.js 100% <100%> (酶) 猬嗭笍
src/FirestoreProvider.js 100% <100%> (酶) 猬嗭笍
src/Firestore.js 100% <100%> (酶) 猬嗭笍
src/withFirestore.js 100% <100%> (酶) 猬嗭笍
src/FirestoreCollection.js 100% <100%> (酶) 猬嗭笍

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 9b00fdf...d811cdc. Read the comment docs.

@peternoordijk peternoordijk mentioned this pull request Feb 9, 2019
@peternoordijk
Copy link
Contributor Author

I just checked... I think we will have to change the React peer dependency:

- "react": ">=15"
+ "react": ">=16.3" 

What is the usual strategy for this? How to release such a change?

@peternoordijk
Copy link
Contributor Author

@green-arrow What do you think of this pull request?

@@ -1,7 +1,8 @@
{
"name": "react-firestore",
"version": "0.0.0-semantically-released",
"description": "React components to fetch data from firestore using render props",
"description":
Copy link
Owner

Choose a reason for hiding this comment

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

@peternoordijk - Overall, it seems like not much changed in this file but the formatting got changed a decent amount. Do you have a formatter set up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah-- yes, I do. It's just VSCode with format on save. I guess I should've turned that off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@green-arrow just to be clear: do you want me to change this back? 馃槃

Copy link
Owner

Choose a reason for hiding this comment

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

@peternoordijk - Yeah, that would be awesome 馃槃 Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@green-arrow no problem :) By the way I remember now what caused this change: yarn was doing all this formatting automatically 馃檮

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@green-arrow Hold on! This formatting is not done by yarn! This formatting happens in some git pre commit hook. Does that by any chance sound familiar to you? I'm very sure it happens in there because I was fixing the formatting using Vim this time, and just before committing it's changing right back.

Copy link
Owner

Choose a reason for hiding this comment

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

@peternoordijk - no worries then! Thanks for looking into it!

render() {
return this.props.children;
return (
<FirestoreContext.Provider value={{ firestoreDatabase, firestoreCache }}>
Copy link
Owner

Choose a reason for hiding this comment

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

@peternoordijk - We should change this to value={this.state}, so that we don't cause a re-render of all consumers whenever this component updates.

Here is some clarification on this from the react docs: https://reactjs.org/docs/context.html#caveats

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! I will make a commit later today with this change.

@green-arrow
Copy link
Owner

@peternoordijk - Thanks for this PR, and apologies for the delay. I just had a couple comments on it, but it looks great!

As for your question around peer dependencies, we'll need to bump it in package.json and make sure the commit message reflects this as a breaking change so semantic release bumps the major version.

If you could take care of the review comments and bumping the peer dependency, I'll make sure to author the commit message correctly so a major version is released.

Thanks again for all your work on this!

@peternoordijk
Copy link
Contributor Author

@green-arrow no worries! I will later today post a new commit with the change. Thanks for looking into the PR!

@green-arrow green-arrow merged commit 5f4d581 into green-arrow:master Mar 9, 2019
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.

None yet

2 participants