Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
67f3384
Return file snapshot on upload (#88)
urbantumbleweed Mar 24, 2017
5edc780
feat(react-native): react-native and boilerplate support (#90)
prescottprue Mar 24, 2017
2d1bbb7
Added XMLHttpRequest to tests (to fix firebase auth issue)
Mar 24, 2017
0ffacb0
react-native complete example started.
Mar 24, 2017
224de4e
Firebase showing up in react-native example.
Mar 24, 2017
78f3ed4
Home now displays auth in a string.
Mar 25, 2017
2b2f429
react-native now working with firebase js library
prescottprue Mar 25, 2017
cc0ad58
Switched to ReactNative instead of rn
prescottprue Mar 25, 2017
d65aa2f
Version v1.4.0-beta (#97)
prescottprue Mar 26, 2017
04039a2
Version v1.4.0 Beta 2 (#100)
prescottprue Mar 28, 2017
5042759
Version v1.4.0 Beta 3 (#101)
prescottprue Mar 28, 2017
27d64e7
Merge branch 'master' into v1.4.0
prescottprue Mar 30, 2017
acd14f9
Merge branch 'master' into v1.4.0
Apr 1, 2017
c960361
Version 1.4.0 Beta 4 (#105)
prescottprue Apr 3, 2017
459c222
Version v1.4.0 Release Candidate 1 (#110)
prescottprue Apr 5, 2017
23bb32a
Form utils added to example.
prescottprue Apr 10, 2017
bc64cf5
Roadmap updated with info on nested populates and updateProfile method.
Apr 15, 2017
b3c87bd
Merge branch 'master' into v1.4.0
Apr 15, 2017
d4b86d1
Server side rendering notes added.
Apr 26, 2017
d7943f5
Merge branch 'master' into v1.4.0
May 5, 2017
36de200
Support for custom auth parameters added.
May 5, 2017
6b2826c
Merge branch 'master' into v1.4.0
May 5, 2017
e478d03
notParsed query parameter. isLoaded returns true issue (#121)
May 5, 2017
85e968e
Use prop-types package instead of the bundled prop-types (#122)
petetnt May 5, 2017
7dbe7b2
key: true lists support for profileParamsToPopulate (#123)
fej-snikduj May 5, 2017
ff11deb
Fixed typos in material-example
May 6, 2017
e89e381
Fixed the last of the "react" typos within material example.
May 6, 2017
3655517
Firebase updated to v3.9.0. More material example updates.
prescottprue May 6, 2017
4e629a9
Lint removed.
prescottprue May 6, 2017
e53dc19
More lint removal from material-ui example.
prescottprue May 6, 2017
caa9bd4
Added message to clarify home container.
prescottprue May 6, 2017
c964724
Not populated delete working in material-ui example
prescottprue May 6, 2017
c92a563
Pull request template updated. Roadmap updated with react-native-fire…
prescottprue May 16, 2017
90489f6
SSR and Auth sections added to recipes. Roadmap updated for coming v1…
prescottprue May 16, 2017
4404433
Merge branch 'master' into v1.4.0
prescottprue May 16, 2017
12df1e8
Auth Recipes cleaned up.
prescottprue May 16, 2017
b49e98f
Version v1.4.0-rc.3 (#128) (#134)
prescottprue May 16, 2017
d86b06d
Exposing Firebase messaging added to roadmap for v1.5.0.
May 16, 2017
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
Prev Previous commit
Next Next commit
Version v1.4.0 Beta 2 (#100)
* fix using with yarn - `.npmignore` file removed so that `.yarn.lock` file will not be included in npm release (only files listed in package file `files` property)
* `pushWithMeta`, `setWithMeta`, and `updateWithMeta` methods added - write to firebase with createdAt/updatedAt and createdBy/updatedBy
  • Loading branch information
prescottprue authored Mar 28, 2017
commit 04039a250a6551649a06cc019d4230236ca527c0
6 changes: 0 additions & 6 deletions .npmignore

This file was deleted.

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.4.0-beta",
"version": "1.4.0-beta.2",
"description": "Redux integration for Firebase. Comes with a Higher Order Component for use with React.",
"browser": "dist/react-redux-firebase.js",
"main": "lib/index.js",
Expand Down
64 changes: 64 additions & 0 deletions src/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as firebase from 'firebase'
// import 'firebase/auth'
// import 'firebase/database'
// import 'firebase/storage'
import { isObject } from 'lodash'
import { defaultConfig } from './constants'
import { validateConfig } from './utils'
import { authActions, queryActions, storageActions } from './actions'
Expand Down Expand Up @@ -108,6 +109,30 @@ export default (fbConfig, otherConfig) => next =>
configurable: true
})

/**
* @private
* @description Calls a method and attaches meta to value object
* @param {String} method - Method to run with meta attached
* @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
* @return {Promise} Containing reference snapshot
*/
const withMeta = (method, path, value, onComplete) => {
if (isObject(value)) {
const prefix = method === 'update' ? 'updated' : 'created'
const dataWithMeta = {
...value,
[`${prefix}At`]: firebase.database.ServerValue.TIMESTAMP
}
if (instance.auth().currentUser) {
dataWithMeta[`${prefix}By`] = instance.auth().currentUser.uid
}
return rootRef.child(path)[method](dataWithMeta, onComplete)
}
return rootRef.child(path)[method](value, onComplete)
}

/**
* @description Sets data to Firebase.
* @param {String} path - Path to location on Firebase which to set
Expand All @@ -127,6 +152,19 @@ export default (fbConfig, otherConfig) => next =>
const set = (path, value, onComplete) =>
rootRef.child(path).set(value, onComplete)

/**
* @description Sets data to Firebase along with meta data. Currently,
* this includes createdAt and createdBy. *Warning* using this function
* may have unintented consequences (setting createdAt even if data already
* exists)
* @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`)
* @return {Promise} Containing reference snapshot
*/
const setWithMeta = (path, value, onComplete) =>
withMeta('set', path, value, onComplete)

/**
* @description Pushes data to Firebase.
* @param {String} path - Path to location on Firebase which to push
Expand All @@ -146,6 +184,17 @@ export default (fbConfig, otherConfig) => next =>
const push = (path, value, onComplete) =>
rootRef.child(path).push(value, onComplete)

/**
* @description Pushes data to Firebase along with meta data. Currently,
* this includes createdAt and createdBy.
* @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`)
* @return {Promise} Containing reference snapshot
*/
const pushWithMeta = (path, value, onComplete) =>
withMeta('push', path, value, onComplete)

/**
* @description Updates data on Firebase and sends new data.
* @param {String} path - Path to location on Firebase which to update
Expand All @@ -165,6 +214,18 @@ export default (fbConfig, otherConfig) => next =>
const update = (path, value, onComplete) =>
rootRef.child(path).update(value, onComplete)

/**
* @description Updates data on Firebase along with meta. *Warning*
* using this function may have unintented consequences (setting
* createdAt even if data already exists)
* @param {String} path - Path to location on Firebase which to update
* @param {Object|String|Boolean|Number} value - Value to update to Firebase
* @param {Function} onComplete - Function to run on complete (`not required`)
* @return {Promise} Containing reference snapshot
*/
const updateWithMeta = (path, value, onComplete) =>
withMeta('update', path, value, onComplete)

/**
* @description Removes data from Firebase at a given path.
* @param {String} path - Path to location on Firebase which to remove
Expand Down Expand Up @@ -352,10 +413,13 @@ export default (fbConfig, otherConfig) => next =>
firebase.helpers = {
ref: path => firebase.database().ref(path),
set,
setWithMeta,
uniqueSet,
push,
pushWithMeta,
remove,
update,
updateWithMeta,
login,
logout,
uploadFile,
Expand Down
28 changes: 27 additions & 1 deletion tests/unit/compose.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ const reducer = sinon.spy()
const generateCreateStore = (params) =>
compose(composeFunc(
params ? omit(fbConfig, params) : fbConfig,
{ userProfile: 'users', enableLogging: false, enableRedirectHandling: false }
{
userProfile: 'users',
enableLogging: false,
enableRedirectHandling: false
}
))(createStore)
const helpers = generateCreateStore()(reducer).firebase.helpers

Expand Down Expand Up @@ -37,14 +41,36 @@ describe('Compose', () => {
helpers.set('test', {some: 'asdf'})
)

describe('setWithMeta', () => {
it('accepts object', () =>
helpers.setWithMeta('test', {some: 'asdf'})
)
it('does not attach meta to string', () =>
// TODO: confirm that data set actually does not include meta
helpers.setWithMeta('test', 'asdd')
)
})

describe('push', () =>
helpers.push('test', {some: 'asdf'})
)

describe('pushWithMeta', () => {
it('accepts object', () =>
helpers.pushWithMeta('test', {some: 'asdf'})
)
})

describe('update', () =>
helpers.update('test', {some: 'asdf'})
)

describe('updateWithMeta', () => {
it('accepts object', () =>
helpers.updateWithMeta('test', {some: 'asdf'})
)
})

describe('uniqueSet', () =>{
// remove test root after test are complete
after(() =>
Expand Down