Skip to content

Commit f91ed93

Browse files
authored
v3.0.0-alpha (prescottprue#566)
* feat(HOCs): switch `firestoreConnect` and `firebaseConnect` to use `componentDidMount` over `componentWillMount` - prescottprue#564 * feat(core): New react context API working with HOCs (`firebaseConnect`, `firestoreConnect` `withFirebase`, and `withFirestore`) - prescottprue#581 * feat(core): support `react-redux` v6 by removing usage of `context.store` (used to be added by `Provider` from `react-redux`) * feat(core): Added `ReactReduxFirebaseContext` and `ReduxFirestoreContext` (with associated providers `ReactReduxFirebaseProvider` `ReduxFirestoreProvider` respectively) * fix(core): shrink build sizes considerably by adding `babel-preset-minify` - prescottprue#573 * feat(deps): update `hoist-non-react-statics` to `^3.1.0` * feat(deps): upgrade to `babel^7` * feat(deps): Update to `webpack^4` (along with `webpack-cli`) * feat(deps): update react peer dependency to `^16.4` for new Context API (matches `react-redux`)
1 parent 34b8f08 commit f91ed93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+26019
-4745
lines changed

.babelrc

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"presets": [
3-
"react",
4-
["env", {
3+
"minify",
4+
"@babel/preset-react",
5+
["@babel/env", {
56
"targets": {
67
"chrome": 52,
78
"browsers": ["last 2 versions", "safari >= 7"]
@@ -11,10 +12,7 @@
1112
"plugins": [
1213
"lodash",
1314
"add-module-exports",
14-
"transform-object-rest-spread",
15-
"transform-object-assign",
16-
"transform-class-properties",
17-
"transform-export-extensions"
15+
"@babel/plugin-proposal-class-properties"
1816
],
1917
"env": {
2018
"es": {
@@ -25,8 +23,8 @@
2523
},
2624
"test": {
2725
"plugins": [
28-
"transform-runtime",
29-
"transform-async-to-generator",
26+
"@babel/plugin-transform-runtime",
27+
"@babel/transform-async-to-generator",
3028
["module-resolver", {
3129
"root": ["./src"]
3230
}]

README.md

+100-76
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ Include `reactReduxFirebase` (store enhancer) and `firebaseReducer` (reducer) w
4848
import React from 'react'
4949
import { render } from 'react-dom'
5050
import { Provider } from 'react-redux'
51-
import { createStore, combineReducers, compose } from 'redux'
52-
import { reactReduxFirebase, firebaseReducer } from 'react-redux-firebase'
53-
import firebase from 'firebase'
54-
// import { reduxFirestore, firestoreReducer } from 'redux-firestore' // <- needed if using firestore
51+
import firebase from 'firebase/app'
52+
import 'firebase/auth'
5553
// import 'firebase/firestore' // <- needed if using firestore
5654
// import 'firebase/functions' // <- needed if using httpsCallable
55+
import { createStore, combineReducers, compose } from 'redux'
56+
import { ReactReduxFirebaseProvider, firebaseReducer } from 'react-redux-firebase'
57+
// import { createFirestoreInstance, firestoreReducer } from 'redux-firestore' // <- needed if using firestore
5758

5859
const firebaseConfig = {}
5960

@@ -70,12 +71,6 @@ firebase.initializeApp(firebaseConfig)
7071
// firebase.firestore() // <- needed if using firestore
7172
// firebase.functions() // <- needed if using httpsCallable
7273

73-
// Add reactReduxFirebase enhancer when making store creator
74-
const createStoreWithFirebase = compose(
75-
reactReduxFirebase(firebase, rrfConfig), // firebase instance as first argument
76-
// reduxFirestore(firebase) // <- needed if using firestore
77-
)(createStore)
78-
7974
// Add firebase to reducers
8075
const rootReducer = combineReducers({
8176
firebase: firebaseReducer,
@@ -84,12 +79,21 @@ const rootReducer = combineReducers({
8479

8580
// Create store with reducers and initial state
8681
const initialState = {}
87-
const store = createStoreWithFirebase(rootReducer, initialState)
82+
const store = createStore(rootReducer, initialState)
83+
84+
const rrfProps = {
85+
firebase,
86+
config: rrfConfig,
87+
dispatch: store.dispatch,
88+
// createFirestoreInstance // <- needed if using firestore
89+
}
8890

8991
// Setup react-redux so that connect HOC can be used
9092
const App = () => (
9193
<Provider store={store}>
92-
<Todos />
94+
<ReactReduxFirebaseProvider {...rrfProps}>
95+
<Todos />
96+
</ReactReduxFirebaseProvider>
9397
</Provider>
9498
);
9599

@@ -104,26 +108,30 @@ The Firebase instance can then be grabbed from context within your components (`
104108
import React from 'react'
105109
import PropTypes from 'prop-types'
106110
import { withFirebase } from 'react-redux-firebase'
111+
import { compose, withHandlers } from 'recompose'
107112

108-
const Todos = ({ firebase }) => {
109-
const sampleTodo = { text: 'Sample', done: false }
110-
const pushSample = () => firebase.push('todos', sampleTodo)
113+
function Todos({ firebase, addSampleTodo }) {
111114
return (
112115
<div>
113-
<h1>Todos</h1>
114-
<ul>
115-
{todosList}
116-
</ul>
117-
<input type="text" ref="newTodo" />
118-
<button onClick={pushSample}>
116+
<h1>New Sample Todo</h1>
117+
<button onClick={addSampleTodo}>
119118
Add
120119
</button>
121120
</div>
122121
)
123122
}
124123

125-
export default withFirebase(Todos)
126-
// or firebaseConnect()(Todos)
124+
const enhance = compose(
125+
withFirebase,
126+
withHandlers({
127+
addSampleTodo: props => () => {
128+
const sampleTodo = { text: 'Sample', done: false }
129+
return props.firebase.push('todos', sampleTodo)
130+
}
131+
})
132+
)
133+
134+
export default enhance(Todos)
127135
```
128136

129137
**Load Data (listeners automatically managed on mount/unmount)**
@@ -135,33 +143,30 @@ import { connect } from 'react-redux'
135143
import { compose } from 'redux'
136144
import { firebaseConnect, isLoaded, isEmpty } from 'react-redux-firebase'
137145

138-
const Todos = ({ todos, firebase }) => {
139-
// Build Todos list if todos exist and are loaded
140-
const todosList = !isLoaded(todos)
141-
? 'Loading'
142-
: isEmpty(todos)
143-
? 'Todo list is empty'
144-
: Object.keys(todos).map(
145-
(key, id) => (
146-
<TodoItem key={key} id={id} todo={todos[key]}/>
147-
)
148-
)
146+
function Todos({ todos, firebase }) {
147+
if (!isLoaded(todos)) {
148+
return <div>Loading...</div>
149+
}
150+
if (isEmpty(todos)) {
151+
return <div>Todos List Is Empty</div>
152+
}
149153
return (
150154
<div>
151-
<h1>Todos</h1>
152155
<ul>
153-
{todosList}
156+
{
157+
Object.keys(todos).map(
158+
(key, id) => (
159+
<TodoItem key={key} id={id} todo={todos[key]}/>
160+
)
161+
)
162+
}
154163
</ul>
155-
<input type="text" ref="newTodo" />
156-
<button onClick={this.handleAdd}>
157-
Add
158-
</button>
159164
</div>
160165
)
161166
}
162167

163168
export default compose(
164-
firebaseConnect([
169+
firebaseConnect(() => [
165170
'todos' // { path: '/todos' } // object notation
166171
]),
167172
connect((state) => ({
@@ -179,8 +184,8 @@ It is common to make a detail page that loads a single item instead of a whole l
179184
import React from 'react'
180185
import PropTypes from 'prop-types'
181186
import { connect } from 'react-redux'
182-
import { compose } from 'redux'
183187
import { firebaseConnect, getVal } from 'react-redux-firebase'
188+
import { compose, withHandlers } from 'recompose'
184189

185190
// Component enhancer that loads todo into redux then into the todo prop
186191
const enhance = compose(
@@ -193,21 +198,27 @@ const enhance = compose(
193198
}),
194199
connect(({ firebase }, props) => ({
195200
todo: getVal(firebase, `data/todos/${props.params.todoId}`), // lodash's get can also be used
196-
}))
201+
})),
202+
withHandlers({
203+
updateTodo: props => () => {
204+
return firebase.update(`todos/${params.todoId}`, { done: !todo.isDone })
205+
}
206+
})
197207
)
198208

199-
const Todo = ({ todo, firebase, params }) =>
200-
<div>
201-
<input
202-
name="isDone"
203-
type="checkbox"
204-
checked={todo.isDone}
205-
onChange={() =>
206-
firebase.update(`todos/${params.todoId}`, { done: !todo.isDone })
207-
}
208-
/>
209-
<span>{todo.label}</span>
210-
</div>
209+
function Todo({ todo }) {
210+
return (
211+
<div>
212+
<input
213+
name="isDone"
214+
type="checkbox"
215+
checked={todo.isDone}
216+
onChange={updateTodo}
217+
/>
218+
<span>{todo.label}</span>
219+
</div>
220+
)
221+
}
211222

212223
// Export enhanced component
213224
export default enhance(Todo)
@@ -223,21 +234,38 @@ import { connect } from 'react-redux'
223234
import { compose } from 'redux'
224235
import { withFirebase, isLoaded, isEmpty } from 'react-redux-firebase'
225236

226-
const Todos = ({ firebase }) => {
227-
// Build Todos list if todos exist and are loaded
228-
const todosList = !isLoaded(todos)
229-
? 'Loading'
230-
: isEmpty(todos)
231-
? 'Todo list is empty'
232-
: Object.keys(todos).map(
233-
(key, id) => <TodoItem key={key} id={id} todo={todos[key]}/>
237+
function TodosList({ todos }) {
238+
if (!isLoaded(todos)) {
239+
return <div>Loading...</div>
240+
}
241+
if (isEmpty(todos)) {
242+
return <div>Todos List Is Empty</div>
243+
}
244+
return (
245+
<ul>
246+
{
247+
Object.keys(todos).map((key, id) =>
248+
<TodoItem key={key} id={id} todo={todos[key]}/>
234249
)
250+
}
251+
</ul>
252+
)
253+
}
254+
const withTodosData = compose(
255+
withFirebase, // or firebaseConnect()
256+
connect((state) => ({
257+
todos: state.firebase.data.todos,
258+
// profile: state.firebase.profile // load profile
259+
}))
260+
)
261+
262+
const EnhancedTodosList = withTodosData(TodosList)
263+
264+
function Todos({ firebase }) {
235265
return (
236266
<div>
237267
<h1>Todos</h1>
238-
<ul>
239-
{todosList}
240-
</ul>
268+
<EnhancedTodosList />
241269
<button onClick={() => firebase.watchEvent('value', 'todos')}>
242270
Load Todos
243271
</button>
@@ -246,13 +274,7 @@ const Todos = ({ firebase }) => {
246274
}
247275

248276
// Export enhanced component
249-
export default compose(
250-
withFirebase, // or firebaseConnect()
251-
connect((state) => ({
252-
todos: state.firebase.data.todos,
253-
// profile: state.firebase.profile // load profile
254-
}))
255-
)(Todos)
277+
export default withFirebase(Todos)
256278
```
257279

258280
## Firestore
@@ -336,13 +358,15 @@ Please visit the [FAQ section of the docs](http://docs.react-redux-firebase.com/
336358

337359
Most commonly people consume Redux Firestore as a [CommonJS module](http://webpack.github.io/docs/commonjs.html). This module is what you get when you import redux in a Webpack, Browserify, or a Node environment.
338360

339-
If you don't use a module bundler, it's also fine. The redux-firestore npm package includes precompiled production and development [UMD builds](https://github.com/umdjs/umd) in the [dist folder](https://unpkg.com/redux-firestore@latest/dist/). They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments. For example, you can drop a UMD build as a `<script>` tag on the page. The UMD builds make Redux Firestore available as a `window.ReduxFirestore` global variable.
361+
If you don't use a module bundler, it's also fine. The redux-firestore npm package includes precompiled production and development [UMD builds](https://github.com/umdjs/umd) in the [dist folder](https://unpkg.com/redux-firestore@latest/dist/). They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments. For example, you can drop a UMD build as a `<script>` tag on the page. The UMD builds make Redux Firestore available as a `window.ReactReduxFirebase` global variable.
340362

341363
It can be imported like so:
342364

343365
```html
344366
<script src="../node_modules/react-redux-firebase/dist/react-redux-firebase.min.js"></script>
367+
<script src="../node_modules/redux-firestore/dist/redux-firestore.min.js"></script>
345368
<!-- or through cdn: <script src="https://unpkg.com/react-redux-firebase@latest/dist/react-redux-firebase.min.js"></script> -->
369+
<!-- or through cdn: <script src="https://unpkg.com/redux-firestore@latest/dist/redux-firestore.min.js"></script> -->
346370
<script>console.log('react redux firebase:', window.ReactReduxFirebase)</script>
347371
```
348372

@@ -365,8 +389,8 @@ Thank you to all our backers! 🙏
365389
[npm-downloads-image]: https://img.shields.io/npm/dm/react-redux-firebase.svg?style=flat-square
366390
[quality-image]: http://npm.packagequality.com/shield/react-redux-firebase.svg?style=flat-square
367391
[quality-url]: https://packagequality.com/#?package=react-redux-firebase
368-
[backers]:https://opencollective.com/react-redux-firebase/backers/badge.svg?style=flat-square&color=blue
369-
[become-a-backer]:https://opencollective.com/react-redux-firebase#backer
392+
[backers]: https://opencollective.com/react-redux-firebase/backers/badge.svg?style=flat-square&color=blue
393+
[become-a-backer]: https://opencollective.com/react-redux-firebase#backer
370394
[travis-image]: https://img.shields.io/travis/prescottprue/react-redux-firebase/master.svg?style=flat-square
371395
[travis-url]: https://travis-ci.org/prescottprue/react-redux-firebase
372396
[daviddm-image]: https://img.shields.io/david/prescottprue/react-redux-firebase.svg?style=flat-square

SUMMARY.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
* [Read Me](/README.md)
44
* [Getting Started](/docs/getting_started.md)
5-
* [v2 Migration Guide](/docs/v2-migration-guide.md)
65
* [Auth](/docs/auth.md)
76
* [Queries](/docs/queries.md)
87
* [Firestore](/docs/firestore.md)
@@ -43,11 +42,13 @@
4342
* [listenersReducer](/docs/api/reducers.md#listenersreducer)
4443
* [dataReducer](/docs/api/reducers.md#datareducer)
4544
* [orderedReducer](/docs/api/reducers.md#orderedreducer)
46-
* [reactReduxFirebase](/docs/api/enhancer.md)
4745
* [props.firebase](/docs/api/props-firebase.md)
4846
* [getFirebase](/docs/api/get-firebase.md)
4947
* [firebaseInstance](/docs/api/firebaseInstance.md)
5048
* [helpers](/docs/api/helpers.md)
49+
* Migration Guides
50+
* [v3 Migration Guide](/docs/v3-migration-guide.md)
51+
* [v2 Migration Guide](/docs/v2-migration-guide.md)
5152
* [FAQ](/docs/FAQ.md)
5253
* [Roadmap](/docs/roadmap.md)
5354
* [Contributing](/docs/contributing.md)

bin/api-docs-generate.js

-4
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ const files = [
2222
src: 'createFirebaseInstance.js',
2323
dest: 'firebaseInstance.md'
2424
},
25-
{
26-
src: 'enhancer.js',
27-
dest: 'enhancer.md'
28-
},
2925
{
3026
src: 'helpers.js',
3127
dest: 'helpers.md'

docs/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
* [listenersReducer](/docs/api/reducers.md#listenersreducer)
4444
* [dataReducer](/docs/api/reducers.md#datareducer)
4545
* [orderedReducer](/docs/api/reducers.md#orderedreducer)
46-
* [reactReduxFirebase](/docs/api/enhancer.md)
4746
* [props.firebase](/docs/api/props-firebase.md)
4847
* [getFirebase](/docs/api/get-firebase.md)
4948
* [firebaseInstance](/docs/api/firebaseInstance.md)

0 commit comments

Comments
 (0)