Skip to content

Commit

Permalink
v3.0.0-beta
Browse files Browse the repository at this point in the history
* feat(auth): remove signIn option from createUser (new user is automatically signed in through Firebase SDK) - #513
* docs(perf): document the correct way reference to state.firestore when creating selectors - #614
* chore(deps): update lodash to 4.17.15
  • Loading branch information
Scott Prue committed Sep 3, 2019
1 parent e8e93b8 commit 07bcd58
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 57 deletions.
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* [Integrations](/docs/integrations/README.md)
* [Redux Thunk](/docs/integrations/thunks.md)
* [Redux Form](/docs/integrations/redux-form.md)
* [Reselect](/docs/integrations/reselect.md)
* [Redux Persist](/docs/integrations/redux-persist.md)
* [Redux Saga](/docs/integrations/redux-saga.md)
* [Redux Observable](/docs/integrations/redux-observable.md)
Expand Down
1 change: 0 additions & 1 deletion docs/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ Similar to Firebase's `ref.createUser(credentials)` but with support for automat
* `credentials` [**Object**][object-url]
* `credentials.email` [**String**][string-url] - User's email
* `credentials.password` [**String**][string-url] - User's password
* `credentials.signIn` [**String**][string-url] - Whether or not to sign in when user is signing up (defaults to `true`)
* `profile` [**Object**][object-url]
* `profile.username` [**String**][string-url]
Expand Down
32 changes: 32 additions & 0 deletions docs/integrations/reselect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Reselect

There are a number of reasons to use state selectors, as mentioned in the [relesect docs](https://github.com/reduxjs/reselect):

> * Selectors can compute derived data, allowing Redux to store the minimal possible state.
> * Selectors are efficient. A selector is not recomputed unless one of its arguments changes.
> * Selectors are composable. They can be used as input to other selectors.
For more information, about why this is important, checkout the [motivation for memoized selectors sections of the reselect docs](https://github.com/reduxjs/reselect#motivation-for-memoized-selectors)

## State Selectors

Select only what you need from state in your selectors instead of the whole firebase/firestore state object:

```js
import { createSelector } from 'reselect';
import { connect } from 'react-redux'
import { get, sumBy } from 'lodash'

const netTotalSelector = createSelector(
state => get(state, 'firestore.data.products'),
products => sumBy(products, 'price')
)

connect((state) => ({
netTotal: netTotalSelector(state)
}))(Component)
```

In this case Reselect will memoize the products object. That means that even if there's any update to other parts of redux state (including firebase/firestore), the memoized products object will stay the same until there is an update to the products themselves.

See [issue #614](https://github.com/prescottprue/react-redux-firebase/issues/614) for more info.
23 changes: 17 additions & 6 deletions docs/v3-migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

## What Changed

### Features

* Support `react-redux` v6 and new React Context API - [#581](https://github.com/prescottprue/react-redux-firebase/issues/581). This mean no more `reactReduxFirebase` and `reduxFirestore` store enhancers (instance is passed through the new React context API) - [#581](https://github.com/prescottprue/react-redux-firebase/issues/581)
* React hooks (requires react `^16.8.0`) `useFirebase`, `useFirestore`, `useFirestoreConnect`, and `useFirebaseConnect` - (Tons of work by [@illuminist](https://github.com/illuminist))

### Breaking Changes

* Removed from API:
* `reactReduxFirebase` store enhancer ()
* `getFirebase` (`reactReduxFirebase` enhancer has been removed, which is what attached `store.firebase` to be used by `getFirebase`)
* `createFirebaseConnect` and `createFirestoreConnect` (see [below](#remove-createFirebaseConnect-and-createFirestoreConnect))
* `signIn` option from `createUser` (new user is automatically signed in through Firebase SDK) - #513
* `componentDidMount` used in place of `componentWillMount` for data loading in `firebaseConnect` and `firestoreConnect`
* `getFirebase` no longer part of the API
* `createFirebaseConnect` and `createFirestoreConnect` are no longer part of the API

### Remove createFirebaseConnect and createFirestoreConnect
### Change Snippets

#### Remove createFirebaseConnect and createFirestoreConnect

These are no longer needed since the extended firebase instance is now loaded through react context instead of through `store.firebase`.

Expand All @@ -16,11 +27,11 @@ These are no longer needed since the extended firebase instance is now loaded th
- const firestoreConnect = createFirestoreConnect('otherStoreKey')
```

### Remove Store Enhancer
#### Remove Store Enhancer

Replace store enhancer with `ReactReduxFirebaseProvider`

#### Diff
##### Diff

_RTDB Diff_
```diff
Expand Down Expand Up @@ -82,7 +93,7 @@ const App = () => (
);
```

#### Full Examples
## Code Examples

**`v2.*.*`**

Expand Down
26 changes: 17 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux-firebase",
"version": "3.0.0-alpha.16",
"version": "3.0.0-beta",
"description": "Redux integration for Firebase. Comes with a Higher Order Components for use with React.",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down Expand Up @@ -58,8 +58,8 @@
"redux-react-firebase"
],
"dependencies": {
"hoist-non-react-statics": "^3.2.1",
"lodash": "^4.17.11",
"hoist-non-react-statics": "^3.3.0",
"lodash": "^4.17.15",
"prop-types": "^15.7.2"
},
"peerDependencies": {
Expand Down
41 changes: 6 additions & 35 deletions src/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,13 +605,15 @@ export const logout = (dispatch, firebase) => {
* @param {Function} dispatch - Action dispatch function
* @param {Object} firebase - Internal firebase object
* @param {Object} credentials - Login credentials
* @param {string} credentials.email - Email of user
* @param {string} credentials.password - Password of new user
* @return {Promise}
* @private
*/
export const createUser = (
dispatch,
firebase,
{ email, password, signIn },
{ email, password },
profile
) => {
dispatchLoginError(dispatch, null)
Expand All @@ -625,40 +627,9 @@ export const createUser = (
return firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then(
userData =>
// Login to newly created account if signIn flag is not set to false
firebase.auth().currentUser || (!!signIn && signIn === false)
? createUserProfile(
dispatch,
firebase,
userData,
profile || { email }
)
: login(dispatch, firebase, { email, password })
.then(() =>
createUserProfile(
dispatch,
firebase,
userData,
profile || { email }
)
)
.catch(err => {
if (err) {
switch (err.code) {
case 'auth/user-not-found':
dispatchLoginError(
dispatch,
new Error('The specified user account does not exist.')
)
break
default:
dispatchLoginError(dispatch, err)
}
}
return Promise.reject(err)
})
.then(userData =>
// Login to newly created account flag is not set to false
createUserProfile(dispatch, firebase, userData, profile || { email })
)
.catch(err => {
dispatchLoginError(dispatch, err)
Expand Down
6 changes: 3 additions & 3 deletions src/firestoreConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ export default function firestoreConnect(dataOrFn = []) {
const FirestoreConnectWithContext = props => {
return (
<ReactReduxFirebaseContext.Consumer>
{firebase => (
{_internalFirebase => (
<ReduxFirestoreContext.Consumer>
{firestore => (
<FirestoreConnectWrapped
{...props}
dispatch={firebase.dispatch}
dispatch={_internalFirebase.dispatch}
firestore={firestore}
firebase={firebase}
firebase={_internalFirebase.dispatch}
/>
)}
</ReduxFirestoreContext.Consumer>
Expand Down

0 comments on commit 07bcd58

Please sign in to comment.