Skip to content

Commit 2fc118f

Browse files
committed
v2.0.0-beta.10 (#291)
* bugfix(auth): `auth.isLoaded` set to `true` on `AUTH_EMPTY_CHANGE` action dispatch - #290 * feat(storage): customizable file name with `uploadFile` and `uploadFiles` through `name` option (can be String or Function) - #285 * bugfix(query): `remove` dispatches `REMOVE` action type with associated reducer case - #257 * feat(query): `remove` accepts an options object as third argument * feat(query): `remove` now has `dispatchAction` option for disabling dispatch of new `REMOVE` action type * feat(query): `dispatchRemoveAction` config option add for global control of dispatching when calling `remove`
1 parent fb8cda6 commit 2fc118f

File tree

16 files changed

+317
-93
lines changed

16 files changed

+317
-93
lines changed

docs/api/constants.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Object containing all action types
2727

2828
- `START` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/START`
2929
- `SET` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/SET`
30+
- `REMOVE` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/REMOVE`
3031
- `MERGE` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/MERGE`
3132
- `SET_PROFILE` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/SET_PROFILE`
3233
- `LOGIN` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/LOGIN`
@@ -88,15 +89,19 @@ Default configuration options
8889
`'userSessions'`. If a function is passed, the arguments are: `(currentUser, firebase)`.
8990
- `enableLogging` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `false` Whether or not firebase
9091
database logging is enabled.
91-
- `preserveOnLougout` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** `null` Data parameters to preserve when
92+
- `preserveOnLogout` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** `null` Data parameters to preserve when
9293
logging out.
9394
- `updateProfileOnLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to update
9495
user profile when logging in.
9596
- `resetBeforeLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to reset auth
96-
and profile when logging in (see issue #254 for more details).
97+
and profile when logging in (see issue
98+
[#254](https://github.com/prescottprue/react-redux-firebase/issues/254)
99+
for more details).
97100
- `enableRedirectHandling` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to enable
98101
redirect handling. This must be disabled if environment is not http/https
99102
such as with react-native.
103+
- `onAuthStateChanged` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** `null` Function that runs when
104+
auth state changes.
100105
- `enableEmptyAuthChanges` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `false` Whether or not to enable
101106
empty auth changes. When set to true, `onAuthStateChanged` will be fired with,
102107
empty auth changes such as `undefined` on initialization
@@ -110,13 +115,16 @@ Default configuration options
110115
the data path. For example role parameter on profile populated from 'roles'
111116
root. True will call SET_PROFILE as well as a SET action with the role that
112117
is loaded (places it in data/roles).
113-
- `dispatchOnUnsetListener` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `false` Whether or not to
118+
- `dispatchOnUnsetListener` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to
114119
dispatch UNSET_LISTENER when disabling listeners for a specific path. USE WITH CAUTION
115120
Setting this to true allows an action to be called that removes data
116121
from redux (which might not always be expected).
122+
- `dispatchRemoveAction` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to
123+
dispatch REMOVE action when calling `remove`.
117124
- `firebaseStateName` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** 'firebase' Assumed name of Firebase
118125
state (name given when passing reducer to combineReducers). Used in
119-
firebaseAuthIsReady promise (see #264).
126+
firebaseAuthIsReady promise (see
127+
[#264](https://github.com/prescottprue/react-redux-firebase/issues/264)).
120128
- `attachAuthIsReady` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to attach
121129
firebaseAuthIsReady to store. authIsLoaded can be imported and used
122130
directly instead based on preference.

docs/api/enhancer.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ along side applyMiddleware.
3232
profile when logging in. (default: `false`)
3333
- `config.resetBeforeLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to empty profile
3434
and auth state on login
35+
- `config.perserveOnLogout` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** Data parameters to perserve when
36+
logging out. (default: `null`)
3537
- `config.enableRedirectHandling` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to enable
3638
auth redirect handling listener. (default: `true`)
3739
- `config.onAuthStateChanged` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function run when auth state

docs/api/firebaseInstance.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ Removes data from Firebase at a given path.
165165

166166
- `path` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Path to location on Firebase which to remove
167167
- `onComplete` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function to run on complete (`not required`)
168+
- `options`
168169

169170
**Examples**
170171

@@ -225,6 +226,8 @@ its metadata in Firebase Database
225226
- `file` **File** File object to upload (usually first element from
226227
array output of select-file or a drag/drop `onDrop`)
227228
- `dbPath` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Database path to place uploaded file metadata
229+
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options
230+
- `options.name` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of the file
228231

229232
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Containing the File object
230233

@@ -239,6 +242,8 @@ to store their metadata in Firebase Database
239242
- `files` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array of File objects to upload (usually from
240243
a select-file or a drag/drop `onDrop`)
241244
- `dbPath` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Database path to place uploaded files metadata.
245+
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Options
246+
- `options.name` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of the file
242247

243248
Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Containing an array of File objects
244249

docs/storage.md

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,67 +8,74 @@ For Examples of how to use these methods, please visit the [recipes section](/do
88

99
Upload an array of files to a location on Firebase storage. This includes the option to also write meta data for the object to Firebase database.
1010

11-
Available on `this.props.firebase` and `getFirebase`.
11+
Available on `props.firebase` if using `firebaseConnect` HOC or using `getFirebase`.
1212

1313
#### Parameters
14-
- `path` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Path within Firebase Storage at which to upload File.
15-
- `files` **[Blob](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Array of File Blobs to upload to Firebase Storage.
16-
- `databasePath` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Path within Firebase Database at which to write files metadata.
14+
- `path` [**String**][string-url] - Path within Firebase Storage at which to upload File.
15+
- `files` [**Array**][array-url] - Array of File Blobs to upload to Firebase Storage.
16+
- `databasePath` [**String**][string-url] - Path within Firebase Database at which to write files metadata.
17+
- `options` [**Object**][object-url] - Options for upload
18+
- `options.name` [**String**][string-url] | [**Function**][function-url] - Name of file or function that returns the name of the file. If a function is passed the argument syntax is `(file, internalFirebase, uploadConfig)` where `file` is the file object (`file.name` is used as default if no name option is passed).
19+
20+
##### Returns
21+
[**Promise**][promise-url] Resolves with an array of [`uploadFile` promises results (described below)](#uploadFile).
1722

1823
### uploadFile
1924

2025
Upload a single file to a location.
2126

22-
Available on `this.props.firebase` and `getFirebase`.
27+
Available on `props.firebase` if using `firebaseConnect` HOC or using `getFirebase`.
2328

2429
#### Parameters
25-
- `path` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Path within Firebase Storage at which to upload File.
26-
- `file` **[Blob](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** File Blob to upload to Firebase Storage.
27-
- `databasePath` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Path within Firebase Database at which to write file metadata.
30+
- `path` [**String**][string-url] - Path within Firebase Storage at which to upload File.
31+
- `file` [**Blob**][blob-url] - File Blob to upload to Firebase Storage.
32+
- `databasePath` [**String**][string-url] - Path within Firebase Database at which to write file metadata.
33+
- `options` [**Object**][object-url] - Options for upload
34+
- `options.name` [**String**][string-url] | [**Function**][function-url] - Name of file or function that returns the name of the file. If a function is passed the argument syntax is `(file, internalFirebase, uploadConfig)` where `file` is the file object (`file.name` is used as default if no name option is passed).
35+
36+
##### Returns
37+
[**Promise**][promise-url] Resolves with an object containing `uploadTaskSnaphot` which is the [**firebase.storage.UploadTaskSnaphot**][upload-task-snapshot-url] returned from the `storageRef.put` call which happens internally. If `databasePath` is provided `snapshot`, `key`, `File`, and `metaDataSnapshot` parameters are also included.
2838

2939
#### Examples
3040

3141
##### [Dropzone File Upload/Delete](/docs/recipes/upload.html#file-dragdrop-upload-with-delete)
3242

3343
### deleteFile
3444

35-
Delete a file from Firebase storage.
45+
Delete a file from Firebase storage with the option to remove metadata from real time database.
3646

37-
Available on `this.props.firebase` and `getFirebase`.
47+
Available on `props.firebase` if using `firebaseConnect` HOC or using `getFirebase`.
3848

3949
#### Parameters
40-
- `path` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Path within Firebase Storage of File to delete.
41-
- `databasePath` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Path within Firebase Database from which to remove File metadata.
50+
- `path` [**String**][string-url] - Path within Firebase Storage of File to delete.
51+
- `databasePath` [**String**][string-url] - Path within Firebase Database from which to remove File metadata.
52+
53+
##### Returns
54+
[**Promise**][promise-url]
4255

4356
#### Example
4457

4558
```javascript
46-
import React, { Component } from 'react'
59+
import React from 'react'
4760
import PropTypes from 'prop-types'
4861
import { firebaseConnect } from 'react-redux-firebase'
4962

50-
@firebaseConnect()
51-
export default class Uploader extends Component {
52-
static propTypes = {
53-
firebase: PropTypes.shape({
54-
deleteFile: PropTypes.func.isRequired
55-
})
56-
}
57-
58-
render() {
59-
const { deleteFile } = this.props;
60-
61-
return (
62-
<div>
63-
<h1>Example File Delete</h1>
64-
<span>Deletes `index.txt` from storage</span>
65-
<button onClick={() => deleteFile('index.txt')}>
66-
Delete
67-
</button>
68-
</div>
69-
)
70-
}
63+
const Uploader = ({ deleteFile }) =>
64+
<div>
65+
<h1>Example File Delete</h1>
66+
<span>Deletes `index.txt` from storage</span>
67+
<button onClick={() => deleteFile('index.txt')}>
68+
Delete
69+
</button>
70+
</div>
71+
72+
Uploader.propTypes = {
73+
firebase: PropTypes.shape({ // comes from firebaseConnect
74+
deleteFile: PropTypes.func.isRequired
75+
})
7176
}
77+
78+
export default firebaseConnect()(Uploader)
7279
```
7380

7481
### Other Storage Methods
@@ -84,31 +91,39 @@ import React, { Component } from 'react'
8491
import PropTypes from 'prop-types'
8592
import { firebaseConnect } from 'react-redux-firebase'
8693

87-
@firebaseConnect()
88-
export default class Uploader extends Component {
94+
class Uploader extends Component {
8995
static propTypes = {
9096
firebase: PropTypes.object
9197
}
9298

93-
render() {
99+
addTestFile = () => {
94100
const { firebase: { storage } } = this.props;
101+
const storageRef = storage().ref()
102+
const fileRef = storageRef.child('test.txt')
103+
return fileRef.putString('Some File Contents')
104+
.then(snap => console.log('upload successful', snap))
105+
.catch(err => console.error('error uploading file', err))
106+
}
95107

96-
const addTestFile = () => {
97-
const storageRef = storage().ref()
98-
const fileRef = storageRef.child('test.txt')
99-
fileRef.putString('Some File Contents')
100-
.then(snap => console.log('upload successful', snap))
101-
.catch(err => console.error('error uploading file', err))
102-
}
103-
108+
render() {
104109
return (
105110
<div>
106111
<h1>Example Upload</h1>
107-
<button onClick={addTestFile}>
112+
<button onClick={this.addTestFile}>
108113
Upload Example File
109114
</button>
110115
</div>
111116
)
112117
}
113118
}
119+
120+
export default firebaseConnect()(Uploader)
114121
```
122+
123+
[promise-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
124+
[string-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String
125+
[array-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
126+
[object-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
127+
[function-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
128+
[blob-url]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Blob
129+
[upload-task-snapshot-url]:https://firebase.google.com/docs/reference/js/firebase.storage.UploadTaskSnapshot

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-redux-firebase",
3-
"version": "2.0.0-beta.9",
3+
"version": "2.0.0-beta.10",
44
"description": "Redux integration for Firebase. Comes with a Higher Order Component for use with React.",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/actions/auth.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const setupPresence = (dispatch, firebase) => {
148148
}
149149
const ref = firebase.database().ref()
150150
const { config: { presence, sessions }, authUid } = firebase._
151-
let amOnline = ref.child('.info/connected')
151+
let amOnline = firebase.database().ref('.info/connected')
152152
let onlineRef = ref.child(isFunction(presence) ? presence(firebase.auth().currentUser, firebase) : presence).child(authUid)
153153
let sessionsRef = isFunction(sessions) ? sessions(firebase.auth().currentUser, firebase) : sessions
154154
if (sessionsRef) {

src/actions/query.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isFunction } from 'lodash'
12
import { actionTypes } from '../constants'
23
import {
34
orderedFromSnapshot,
@@ -172,11 +173,42 @@ export const watchEvents = (firebase, dispatch, events) =>
172173
/**
173174
* @description Remove watchers from a list of events
174175
* @param {Object} firebase - Internal firebase object
176+
* @param {Function} dispatch - Action dispatch function
175177
* @param {Array} events - List of events for which to remove watchers
176178
*/
177179
export const unWatchEvents = (firebase, dispatch, events) =>
178180
events.forEach(event =>
179181
unWatchEvent(firebase, dispatch, event)
180182
)
181183

182-
export default { watchEvents, unWatchEvents }
184+
/**
185+
* @description Add watchers to a list of events
186+
* @param {Object} firebase - Internal firebase object
187+
* @param {Function} dispatch - Action dispatch function
188+
* @param {String} path - Path of ref to be removed
189+
* @param {Function} onComplete - Callback function that is called when removal is
190+
* @param {Object} [options={}] - Configuration for removal
191+
* @param {Boolean} [options.dispatchAction=true] - Whether or not to dispatch
192+
* REMOVE action
193+
* @return {Promise} Resolves with path
194+
*/
195+
export const remove = (firebase, dispatch, path, onComplete, options = {}) => {
196+
const { dispatchAction = true } = options
197+
const { dispatchRemoveAction } = firebase._.config
198+
return firebase.database().ref(path).remove()
199+
.then(() => {
200+
if (dispatchRemoveAction && dispatchAction) {
201+
dispatch({ type: actionTypes.REMOVE, path })
202+
}
203+
if (isFunction(onComplete)) {
204+
onComplete()
205+
}
206+
return path
207+
})
208+
.catch((err) => {
209+
dispatch({ type: actionTypes.ERROR, payload: err })
210+
return Promise.reject(err)
211+
})
212+
}
213+
214+
export default { watchEvents, unWatchEvents, remove }

0 commit comments

Comments
 (0)