Skip to content

Commit 5224326

Browse files
authored
v3.0.0-alpha.4 (#597)
* fix(typings): add context providers to typings - #564 * fix(storage): support only firestore when calling upload and writing to db - @dirathea * fix(core): add auth initialization to providers to match v2 store enhancer - #388
1 parent 71dee92 commit 5224326

13 files changed

+155
-78
lines changed

.babelrc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"presets": [
3-
["minify", { "keepFnName": true }],
3+
["minify", {
4+
"mangle": false
5+
}],
46
"@babel/preset-react",
57
["@babel/env", {
68
"targets": {

docs/api/firebaseInstance.md

+5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- [reloadAuth](#reloadauth)
2929
- [linkWithCredential](#linkwithcredential)
3030
- [signInWithPhoneNumber](#signinwithphonenumber)
31+
- [initializeAuth](#initializeauth)
3132
- [ref](#ref)
3233
- [database](#database)
3334
- [storage](#storage)
@@ -456,6 +457,10 @@ authenticates and does profile handling.
456457

457458
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)**
458459

460+
## initializeAuth
461+
462+
Initialize auth to work with build in profile support
463+
459464
## ref
460465

461466
Firebase ref function

docs/api/firestoreConnect.md

+5-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ needing to access a firebase instance created under a different store key.
2323
_Basic_
2424

2525
```javascript
26-
// this.props.firebase set on App component as firebase object with helpers
26+
// props.firebase set on App component as firebase object with helpers
2727
import { createFirestoreConnect } from 'react-redux-firebase'
2828
// create firebase connect that uses another redux store
2929
const firestoreConnect = createFirestoreConnect('anotherStore')
@@ -53,7 +53,7 @@ attempting to use. **Note** Populate is not yet supported.
5353
_Basic_
5454

5555
```javascript
56-
// this.props.firebase set on App component as firebase object with helpers
56+
// props.firebase set on App component as firebase object with helpers
5757
import { firestoreConnect } from 'react-redux-firebase'
5858
export default firestoreConnect()(SomeComponent)
5959
```
@@ -64,13 +64,11 @@ _Basic_
6464
import { connect } from 'react-redux'
6565
import { firestoreConnect } from 'react-redux-firebase'
6666

67-
// pass todos list from redux as this.props.todosList
67+
// pass todos list from redux as props.todosList
6868
export default compose(
69-
firestoreConnect(['todos']), // sync todos collection from Firestore into redux
69+
firestoreConnect(() => ['todos']), // sync todos collection from Firestore into redux
7070
connect((state) => ({
71-
todosList: state.firestore.data.todos,
72-
profile: state.firestore.profile, // pass profile data as this.props.profile
73-
auth: state.firestore.auth // pass auth data as this.props.auth
71+
todosList: state.firestore.data.todos
7472
})
7573
)(SomeComponent)
7674
```

docs/api/withFirebase.md

+24-16
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ needing to access a firebase instance created under a different store key.
2323
_Basic_
2424

2525
```javascript
26-
// this.props.firebase set on App component as firebase object with helpers
26+
// props.firebase set on App component as firebase object with helpers
2727
import { createWithFirebase } from 'react-redux-firebase'
2828

2929
// create withFirebase that uses another redux store
@@ -55,12 +55,15 @@ _Basic_
5555
```javascript
5656
import { withFirebase } from 'react-redux-firebase'
5757

58-
const AddData = ({ firebase: { push } }) =>
59-
<div>
60-
<button onClick={() => push('todos', { done: false, text: 'Sample' })}>
61-
Add Sample Todo
62-
</button>
63-
</div>
58+
function AddData({ firebase: { push } }) {
59+
return (
60+
<div>
61+
<button onClick={() => push('todos', { done: false, text: 'Sample' })}>
62+
Add Sample Todo
63+
</button>
64+
</div>
65+
)
66+
}
6467

6568
export default withFirebase(AddData)
6669
```
@@ -72,15 +75,18 @@ import { compose } from 'redux' // can also come from recompose
7275
import { withHandlers } from 'recompose'
7376
import { withFirebase } from 'react-redux-firebase'
7477

75-
const AddTodo = ({ addTodo }) =>
76-
<div>
77-
<button onClick={addTodo}>
78-
Add Sample Todo
79-
</button>
80-
</div>
81-
82-
export default compose(
83-
withFirebase(AddTodo),
78+
function AddTodo({ addTodo }) {
79+
return (
80+
<div>
81+
<button onClick={addTodo}>
82+
Add Sample Todo
83+
</button>
84+
</div>
85+
)
86+
}
87+
88+
const enhance = compose(
89+
withFirebase,
8490
withHandlers({
8591
addTodo: props => () =>
8692
props.firestore.add(
@@ -89,6 +95,8 @@ export default compose(
8995
)
9096
})
9197
)
98+
99+
export default enhance(AddTodo)
92100
```
93101

94102
Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Which accepts a component to wrap and returns the

docs/api/withFirestore.md

+30-21
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ needing to access a firebase instance created under a different store key.
1616
**Parameters**
1717

1818
- `storeKey` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of redux store which contains
19-
Firebase state (`state.firebase`) (optional, default `'store'`)
19+
Firestore state (`state.firestore`) (optional, default `'store'`)
2020

2121
**Examples**
2222

@@ -50,42 +50,51 @@ from `store.firestore`, which is attached to store by the store enhancer
5050
_Basic_
5151

5252
```javascript
53+
import React from 'react'
5354
import { withFirestore } from 'react-redux-firebase'
5455

55-
const AddTodo = ({ firestore: { add } }) =>
56-
<div>
57-
<button onClick={() => add('todos', { done: false, text: 'Sample' })}>
58-
Add Sample Todo
59-
</button>
60-
</div>
56+
function AddData({ firebase: { add } }) {
57+
return (
58+
<div>
59+
<button onClick={() => add('todos', { done: false, text: 'Sample' })}>
60+
Add Sample Todo
61+
</button>
62+
</div>
63+
)
64+
}
6165

6266
export default withFirestore(AddTodo)
6367
```
6468

6569
_Within HOC Composition_
6670

6771
```javascript
72+
import React from 'react'
6873
import { compose } from 'redux' // can also come from recompose
6974
import { withHandlers } from 'recompose'
7075
import { withFirestore } from 'react-redux-firebase'
7176

72-
const AddTodo = ({ addTodo }) =>
73-
<div>
74-
<button onClick={addTodo}>
75-
Add Sample Todo
76-
</button>
77-
</div>
78-
79-
export default compose(
80-
withFirestore(AddTodo),
77+
function AddTodo({ addTodo }) {
78+
return (
79+
<div>
80+
<button onClick={addTodo}>
81+
Add Sample Todo
82+
</button>
83+
</div>
84+
)
85+
}
86+
87+
const enhance = compose(
88+
withFirestore,
8189
withHandlers({
82-
addTodo: props => () =>
83-
props.firestore.add(
84-
{ collection: 'todos' },
85-
{ done: false, text: 'Sample' }
86-
)
90+
addTodo: props => () => {
91+
const newTodo = { done: false, text: 'Sample' }
92+
return props.firestore.add({ collection: 'todos' }, newTodo)
93+
}
8794
})
8895
)
96+
97+
export default enhance(AddTodo)
8998
```
9099

91100
Returns **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** Which accepts a component to wrap and returns the

index.d.ts

+29-15
Original file line numberDiff line numberDiff line change
@@ -180,32 +180,50 @@ export function populate(
180180
notSetValue?: any
181181
): any
182182

183-
export function reactReduxFirebase(instance: object, otherConfig: any): any
183+
/**
184+
* React Context provider for Firebase instance (with methods wrapped in dispatch). Needed to use HOCs
185+
* like firebaseConnect and withFirebase.
186+
*/
187+
export function ReactReduxFirebaseProvider(props: ReactReduxFirebaseProviderProps): any;
184188

185189
/**
186190
* Props passed to ReactReduFirebaseContext component
187191
*/
188-
export interface ReactReduxFirebaseContextProps {
189-
firebase: object,
190-
config: object,
191-
dispatch: (action) => void
192-
createFirestoreInstance?: (firebase: object, config: object, dispatch: (action) => void) => object
192+
export interface ReactReduxFirebaseProviderProps<T> {
193+
value: T;
194+
firebase: object;
195+
config: object;
196+
dispatch: (action: object) => void;
197+
children?: React.ReactNode;
198+
initalizeAuth?: boolean;
199+
createFirestoreInstance?: (firebase: object, config: object, dispatch: (action: object) => void) => object;
193200
}
194201

195202
/**
196-
* React Context provider for Firebase instance. Needed to use HOCs like firebaseConnect and withFirebase
203+
* React Context for Firebase instance.
197204
*/
198-
export namespace ReactReduxFirebaseContext {
205+
export namespace ReduxFirestoreContext {
199206
const prototype: {}
200207
}
201208

202209
/**
203-
* React Context provider for Firebase instance. Needed to use HOCs like firebaseConnect and withFirebase
210+
* Props passed to ReactReduFirebaseContext component
204211
*/
205-
export namespace ReduxFirestoreContext {
206-
const prototype: {}
212+
export interface ReduxFirestoreProviderProps {
213+
firebase: object;
214+
config: object;
215+
dispatch: (action: object) => void;
216+
createFirestoreInstance: (firebase: object, config: object, dispatch: (action: object) => void) => object;
217+
children?: React.ReactNode;
218+
initalizeAuth?: boolean;
207219
}
208220

221+
/**
222+
* React Context provider for Firestore instance (with methods wrapped in dispatch). Needed to use HOCs
223+
* like firestoreConnect and withFirestore.
224+
*/
225+
export function ReduxFirestoreProvider(props: ReduxFirestoreProviderProps): any;
226+
209227
/**
210228
* React Higher Order Component that passes firebase as a prop (comes from context.store.firebase)
211229
*/
@@ -267,10 +285,6 @@ export namespace fixPath {
267285
const prototype: {}
268286
}
269287

270-
export namespace getFirebase {
271-
const prototype: {}
272-
}
273-
274288
export namespace getVal {
275289
const prototype: {}
276290
}

package-lock.json

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-redux-firebase",
3-
"version": "3.0.0-alpha.3",
3+
"version": "3.0.0-alpha.4",
44
"description": "Redux integration for Firebase. Comes with a Higher Order Components for use with React.",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/ReactReduxFirebaseProvider.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,24 @@ function ReactReduxFirebaseProvider(props = {}) {
1010
config,
1111
dispatch,
1212
firebase,
13+
initializeAuth,
1314
createFirestoreInstance
1415
} = props
1516
const extendedFirebaseInstance = createFirebaseInstance(
1617
firebase,
1718
config,
1819
dispatch
1920
)
21+
// Initialize auth if not disabled
22+
if (initializeAuth) {
23+
extendedFirebaseInstance.initializeAuth()
24+
}
2025
if (createFirestoreInstance) {
2126
return (
2227
<ReactReduxFirebaseContext.Provider value={extendedFirebaseInstance}>
23-
<ReduxFirestoreProvider {...props}>{children}</ReduxFirestoreProvider>
28+
<ReduxFirestoreProvider {...props} initializeAuth={false}>
29+
{children}
30+
</ReduxFirestoreProvider>
2431
</ReactReduxFirebaseContext.Provider>
2532
)
2633
}
@@ -31,11 +38,16 @@ function ReactReduxFirebaseProvider(props = {}) {
3138
)
3239
}
3340

41+
ReactReduxFirebaseProvider.defaultProps = {
42+
initalizeAuth: true
43+
}
44+
3445
ReactReduxFirebaseProvider.propTypes = {
3546
children: PropTypes.node,
3647
config: PropTypes.object.isRequired,
3748
dispatch: PropTypes.func.isRequired,
3849
firebase: PropTypes.object.isRequired,
50+
initializeAuth: PropTypes.bool,
3951
createFirestoreInstance: PropTypes.func
4052
}
4153

0 commit comments

Comments
 (0)