Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
uniqueSet race condition
* uniqueSet uses transaction to prevent race condition - #207
  • Loading branch information
Scott Prue committed Jul 25, 2017
commit 463e034f70679540f18f63f98733e3e621a5521b
3 changes: 3 additions & 0 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#### Enhancements/Fixes
* Return correct promise from `firebase.auth().signOut()` - [#152](https://github.com/prescottprue/react-redux-firebase/issues/152)
* Removed `browser` field from `package.json` so that webpack will point to `main` field - [#128](https://github.com/prescottprue/react-redux-firebase/issues/128)
* Fix `uniqueSet` race condition - [#207](https://github.com/prescottprue/react-redux-firebase/issues/207)
* improved testing of `firebaseConnect` HOC

## Future Minor Versions (`v1.6.0 - v1.*.*`)

Expand All @@ -65,6 +67,7 @@
* Setting that allows for `waitForPopulate` to be turned off (i.e. return populated data as in becomes available). As of `v1.4.0-rc.2`, populate only sets `isLoaded` to true after all children are loaded, `waitForPopulate` would make this optional - [#121](https://github.com/prescottprue/react-redux-firebase/issues/121)
* Integration for [`react-native-google-signin`](https://github.com/devfd/react-native-google-signin) to simplify react-native authentication implementation
* Nested populates - [#85](https://github.com/prescottprue/react-redux-firebase/issues/85)
* Renaming a file on upload (currently does not work due to HTML 5 File element being read only)

#### Enhancements/Fixes
*None Yet Planned*
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux-firebase",
"version": "1.5.0-rc.2",
"version": "1.5.0-rc.3",
"description": "Redux integration for Firebase. Comes with a Higher Order Component for use with React.",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
18 changes: 10 additions & 8 deletions src/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ export default (fbConfig, otherConfig) => next =>
/**
* @private
* @description Sets data to Firebase only if the path does not already
* exist, otherwise it rejects.
* exist, otherwise it rejects. Internally uses a Firebase transaction to
* prevent a race condition between seperate clients calling uniqueSet.
* @param {String} path - Path to location on Firebase which to set
* @param {Object|String|Boolean|Number} value - Value to write to Firebase
* @param {Function} onComplete - Function to run on complete (`not required`)
Expand All @@ -298,14 +299,15 @@ export default (fbConfig, otherConfig) => next =>
*/
const uniqueSet = (path, value, onComplete) =>
rootRef.child(path)
.once('value')
.then(snap => {
if (snap.val && snap.val() !== null) {
const err = new Error('Path already exists.')
if (onComplete) onComplete(err)
return Promise.reject(err)
.transaction(d => d === null ? value : undefined)
.then(({ commited, snapshot }) => {
if (!commited) {
const newError = new Error('Path already exists.')
if (onComplete) onComplete(newError)
return Promise.reject(newError)
}
return rootRef.child(path).set(value, onComplete)
if (onComplete) onComplete(snapshot)
return snapshot
})

/**
Expand Down