Skip to content

Commit

Permalink
Version v1.1.5 (#30)
Browse files Browse the repository at this point in the history
* `ref` is now a function in compose (Addresses #28)
* test added to confirm that `ref` is exposed correctly
* Peer Dependencies updated to include `react-redux` `^5.0.0` and ` redux` `^3.6.0`
  • Loading branch information
prescottprue committed Jan 11, 2017
1 parent 493a034 commit 0263b0b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
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": "1.1.4",
"version": "1.1.5",
"description": "Redux integration for Firebase. Comes with a Higher Order Component for use with React.",
"main": "dist/index.js",
"module": "src/index.js",
Expand Down Expand Up @@ -53,8 +53,8 @@
},
"peerDependencies": {
"react": "^0.14.6 || ^15.0.0",
"react-redux": "^4.0.6",
"redux": "^3.0.5"
"react-redux": "^4.0.6 || ^5.0.0",
"redux": "^3.0.5 || ^3.6.0"
},
"devDependencies": {
"babel-cli": "^6.18.0",
Expand Down
16 changes: 8 additions & 8 deletions src/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default (config, otherConfig) => next =>
Firebase.database.enableLogging(configs.enableLogging)
}

const ref = Firebase.database().ref()
const rootRef = Firebase.database().ref()

const firebase = Object.defineProperty(Firebase, '_', {
value: {
Expand All @@ -88,16 +88,16 @@ export default (config, otherConfig) => next =>
})

const set = (path, value, onComplete) =>
ref.child(path).set(value, onComplete)
rootRef.child(path).set(value, onComplete)

const push = (path, value, onComplete) =>
ref.child(path).push(value, onComplete)
rootRef.child(path).push(value, onComplete)

const update = (path, value, onComplete) =>
ref.child(path).update(value, onComplete)
rootRef.child(path).update(value, onComplete)

const remove = (path, onComplete) =>
ref.child(path).remove(onComplete)
rootRef.child(path).remove(onComplete)

const uploadFile = (path, file, dbPath) =>
storageActions.uploadFile(dispatch, firebase, { path, file, dbPath })
Expand All @@ -109,15 +109,15 @@ export default (config, otherConfig) => next =>
storageActions.deleteFile(dispatch, firebase, { path, dbPath })

const uniqueSet = (path, value, onComplete) =>
ref.child(path)
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)
}
return ref.child(path).set(value, onComplete)
return rootRef.child(path).set(value, onComplete)
})

const watchEvent = (type, path) =>
Expand All @@ -139,7 +139,7 @@ export default (config, otherConfig) => next =>
authActions.resetPassword(dispatch, firebase, credentials)

firebase.helpers = {
ref: Firebase.database().ref,
ref: path => Firebase.database().ref(path),
set,
uniqueSet,
push,
Expand Down
9 changes: 9 additions & 0 deletions test/unit/compose.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ describe('Compose', () => {
})

describe('helpers', () => {
describe('ref', () => {
it('exists', () => {
expect(helpers.ref('test')).to.be.an.object
})
it('has child', () => {
expect(helpers.ref('test').child('asdf')).to.be.an.object
})
})

describe('set', () =>
helpers.set('test', {some: 'asdf'})
)
Expand Down

0 comments on commit 0263b0b

Please sign in to comment.