Skip to content

Commit

Permalink
v2.0.0 beta.9 (#281)
Browse files Browse the repository at this point in the history
* `reloadAuth` added for reloading auth (calls `firebase.auth().currentUser.reload()`) - #273
* `linkWithCredential` added for linking auth with credential - #268 
* `store.firebaseAuthIsReady` is now added by `reactReduxFirebase` store enhancer - promise that resolves once auth state is ready - #264 
* `authIsReady` promise added for waiting for auth to be ready - #264
* `ordered` always set as `null` instead of `undefined` - fixes possible issue of `isLoaded` not always being correct
* `firebaseStateName` constant - assumed name of firebase state to be used in `authIsReady`
* `attachAuthIsLoaded` constant - boolean for enabling/disabling the
attaching of `firebaseAuthIsReady` to store (`true` by default)
* `yarn.lock` removed - npm5 is faster
* `v2.0.0` branch added to travis config (so v2.0.0 pushes/merges are built)
* `babel-preset-env` used in place of `babel-preset-es2015` (fixes deprecation warning)
  • Loading branch information
prescottprue authored Oct 11, 2017
1 parent c1c98be commit 9a32d8c
Show file tree
Hide file tree
Showing 63 changed files with 27,091 additions and 7,680 deletions.
10 changes: 9 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"presets": ["es2015", "react"],
"presets": [
"react",
["env", {
"targets": {
"chrome": 52,
"browsers": ["last 2 versions", "safari >= 7"]
}
}]
],
"plugins": [
"lodash",
"add-module-exports",
Expand Down
36 changes: 18 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
sudo: false

language: node_js

node_js:
- "6"
- "8"
- 6.11.3 # L.T.S
- 8 # Current

sudo: false
notifications:
# Only send notifications when travis status changes
email:
on_failure: change
on_success: change

addons:
code_climate:
repo_token: $CODE_CLIMATE

cache:
directories:
- node_modules

branches:
only:
- master
- v2.0.0

script:
- npm run lint:fix
- npm run test:cov

cache:
yarn: true
directories:
- node_modules

addons:
code_climate:
repo_token: $CODE_CLIMATE

after_success:
- npm install -g codeclimate-test-reporter
- codeclimate-test-reporter < coverage/lcov.info
- npm run codecov

notifications:
email:
# Only send notifications when travis status changes
on_failure: change
on_success: change
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ npm install --save react-redux-firebase

The above install command will install the `@latest` tag. You may also use the following tags when installing to get different versions:

* `@canary` - Most possible up to date code. Currently, points to active progress with `v2.0.0-*` pre-releases. *Warning:* Syntax is different than current stable version.
* `@next` - Most possible up to date code. Currently, points to active progress with `v2.0.0-*` pre-releases. *Warning:* Syntax is different than current stable version.

Be aware of changes when using a version that is not tagged `@latest`. Please report any issues you encounter, and try to keep an eye on the [releases page](https://github.com/prescottprue/react-redux-firebase/releases) for updates.

Expand Down
17 changes: 9 additions & 8 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
* [Roles](/docs/recipes/roles.md)
* [Populate](/docs/recipes/populate.md)
* [Upload](/docs/recipes/upload.md)
* [Redux Thunk](/docs/recipes/thunks.md)
* [Redux Form](/docs/recipes/redux-form.md)
* [Redux Persist](/docs/recipes/redux-persist.md)
* [Redux Saga](/docs/recipes/redux-saga.md)
* [Redux Observable](/docs/recipes/redux-observable.md)
* [React Native](/docs/recipes/react-native.md)
* [React Chrome Redux](/docs/recipes/react-chrome-redux.md)
* [Server Side Rendering](/docs/recipes/ssr.md)
* [Performance](/docs/recipes/performance.md)
* [Integrations](/docs/integrations/README.md)
* [Redux Thunk](/docs/integrations/thunks.md)
* [Redux Form](/docs/integrations/redux-form.md)
* [Redux Persist](/docs/integrations/redux-persist.md)
* [Redux Saga](/docs/integrations/redux-saga.md)
* [Redux Observable](/docs/integrations/redux-observable.md)
* [React Native](/docs/integrations/react-native.md)
* [React Chrome Redux](/docs/integrations/react-chrome-redux.md)
* [API Reference](/docs/api/README.md)
* [constants](/docs/api/constants.md)
* [firebaseConnect](/docs/api/connect.md)
* [firebaseStateReducer](/docs/api/reducer.md)
* [reactReduxFirebase](/docs/api/compose.md)
* [reactReduxFirebase](/docs/api/enhancer.md)
* [props.firebase](/docs/api/props-firebase.md)
* [getFirebase](/docs/api/get-firebase.md)
* [firebaseInstance](/docs/api/firebaseInstance.md)
Expand Down
4 changes: 2 additions & 2 deletions bin/api-docs-generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const files = [
dest: 'firebaseInstance.md'
},
{
src: 'compose.js',
dest: 'compose.md'
src: 'enhancer.js',
dest: 'enhancer.md'
},
{
src: 'helpers.js',
Expand Down
5 changes: 3 additions & 2 deletions docs/api/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

## reactReduxFirebase

Middleware that handles configuration (placed in redux's
`compose` call)
Redux store enhancer that accepts configuration options and adds
store.firebase and store.firebaseAuth. Enhancers are most commonly placed in redux's `compose` call
along side applyMiddleware.

**Parameters**

Expand Down
77 changes: 53 additions & 24 deletions docs/api/connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,31 @@

## createFirebaseConnect

WARNING!! Advanced feature, and only be used when needing to
access a firebase instance created under a different store key
Function that creates a Higher Order Component that
automatically listens/unListens to provided firebase paths using
React's Lifecycle hooks.
**WARNING!!** This is an advanced feature, and should only be used when
needing to access a firebase instance created under a different store key.

**Parameters**

- `storeKey` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of key of store to connect to (store that contains state.firebase) (optional, default `'store'`)
- `storeKey` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Name of redux store which contains
Firebase state (state.firebase) (optional, default `'store'`)

**Examples**

_Data_
_Basic_

```javascript
import { connect } from 'react-redux'
// this.props.firebase set on App component as firebase object with helpers
import { createFirebaseConnect } from 'react-redux-firebase'

// sync /todos from firebase (in other store) into redux
const fbWrapped = createFirebaseConnect('someOtherName')(['todos'])

// pass todos list from redux as this.props.todosList
export default connect(({ firebase: data: { todos }, auth, profile }) => ({
todos,
profile, // pass profile data as this.props.profile
auth // pass auth data as this.props.auth
}))(fbWrapped)
// create firebase connect that uses another redux store
const firebaseConnect = createFirebaseConnect('anotherStore')
// use the firebaseConnect to wrap a component
export default firebaseConnect()(SomeComponent)
```

Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** that returns a firebaseConnect function, which is later used to wrap a component
Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** HOC that accepts a watchArray and wraps a component

## firebaseConnect

Expand All @@ -44,9 +42,7 @@ to provided firebase paths using React's Lifecycle hooks.

**Parameters**

- `watchArray` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array of objects or strings for paths to sync
from Firebase. Can also be a function that returns the array. The function
is passed the current props and the firebase object.
- `watchArray` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** Array of objects or strings for paths to sync from Firebase. Can also be a function that returns the array. The function is passed the current props and the firebase object.

**Examples**

Expand All @@ -70,11 +66,44 @@ const fbWrapped = firebaseConnect([
])(App)

// pass todos list from redux as this.props.todosList
export default connect(({ firebase: data: { todos }, auth, profile }) => ({
todos,
profile, // pass profile data as this.props.profile
auth // pass auth data as this.props.auth
>>>>>>> master
export default connect((state) => ({
todosList: state.firebase.data.todos,
profile: state.firebase.profile, // pass profile data as this.props.profile
auth: state.firebase.auth // pass auth data as this.props.auth
}))(fbWrapped)
```

_Data that depends on props_

```javascript
import { connect } from 'react-redux'
import { firebaseConnect } from 'react-redux-firebase'

// sync /todos from firebase into redux
const fbWrapped = firebaseConnect((props) => ([
`todos/${props.type}`
])(App)

// pass todos list for the specified type of todos from redux as `this.props.todosList`
export default connect(({ firebase: { data } }, { type }) => ({
todosList: data.todos && data.todos[type],
}))(fbWrapped)
```
_Data that depends on auth state_
```javascript
import { connect } from 'react-redux'
import { firebaseConnect } from 'react-redux-firebase'

// sync /todos from firebase into redux
const fbWrapped = firebaseConnect((props, firebase) => ([
`todos/${firebase._.authUid}`
])(App)

// pass todos list for the specified type of todos from redux as `this.props.todosList`
export default connect(({ firebase: { data, auth } }) => ({
todosList: data.todos && data.todos[auth.uid],
}))(fbWrapped)
```
Expand Down
19 changes: 16 additions & 3 deletions docs/api/constants.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,20 @@ Object containing all action types
- `FILE_DELETE_COMPLETE` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/FILE_DELETE_COMPLETE`
- `AUTH_UPDATE_START` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTH_UPDATE_START`
- `AUTH_UPDATE_ERROR` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTH_UPDATE_ERROR`
- `AUTH_UPDATE_COMPLETE` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTH_UPDATE_COMPLETE`
- `AUTH_UPDATE_SUCCESS` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTH_UPDATE_SUCCESS`
- `PROFILE_UPDATE_START` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/PROFILE_UPDATE_START`
- `PROFILE_UPDATE_ERROR` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/PROFILE_UPDATE_ERROR`
- `PROFILE_UPDATE_COMPLETE` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/PROFILE_UPDATE_COMPLETE`
- `PROFILE_UPDATE_SUCCESS` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/PROFILE_UPDATE_SUCCESS`
- `EMAIL_UPDATE_START` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/EMAIL_UPDATE_START`
- `EMAIL_UPDATE_ERROR` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/EMAIL_UPDATE_ERROR`
- `EMAIL_UPDATE_COMPLETE` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/EMAIL_UPDATE_COMPLETE`
- `EMAIL_UPDATE_SUCCESS` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/EMAIL_UPDATE_SUCCESS`
- `AUTH_RELOAD_START` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTH_RELOAD_START`
- `AUTH_RELOAD_ERROR` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTH_RELOAD_ERROR`
- `AUTH_RELOAD_SUCCESS` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTH_RELOAD_SUCCESS`
- `AUTH_LINK_START` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTH_LINK_START`
- `AUTH_LINK_ERROR` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTH_LINK_ERROR`
- `AUTH_LINK_SUCCESS` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTH_LINK_SUCCESS`
- `AUTH_EMPTY_CHANGE` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** `@@reactReduxFirebase/AUTH_LINK_SUCCESS`

**Examples**

Expand Down Expand Up @@ -107,3 +114,9 @@ Default configuration options
dispatch UNSET_LISTENER when disabling listeners for a specific path. USE WITH CAUTION
Setting this to true allows an action to be called that removes data
from redux (which might not always be expected).
- `firebaseStateName` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** 'firebase' Assumed name of Firebase
state (name given when passing reducer to combineReducers). Used in
firebaseAuthIsReady promise (see #264).
- `attachAuthIsReady` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` Whether or not to attach
firebaseAuthIsReady to store. authIsLoaded can be imported and used
directly instead based on preference.
92 changes: 92 additions & 0 deletions docs/api/enhancer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

- [reactReduxFirebase](#reactreduxfirebase)

## reactReduxFirebase

Redux store enhancer that accepts configuration options and adds
store.firebase and store.firebaseAuth. Enhancers are most commonly placed in redux's `compose` call
along side applyMiddleware.

**Parameters**

- `instance`
- `otherConfig`

**Properties**

- `firebaseInstance` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Initiated firebase instance (can also
be library following Firebase JS API such as `react-native-firebase`)
- `config` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Containing react-redux-firebase specific configuration
- `config.userProfile` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Location on firebase to store user profiles
- `config.enableLogging` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to enable Firebase database logging.
**Note**: Only works if instance has enableLogging function.
- `config.profileFactory` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Factory for modifying how user profile is saved.
- `config.presence` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Location on Firebase to store currently
online users list. Often set to `'presence'` or `'onlineUsers'`.
- `config.sessions` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Location on Firebase where user
sessions are stored (only if presense is set). Often set to `'sessions'` or `'onlineUsers'`.
- `config.updateProfileOnLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to update
profile when logging in. (default: `false`)
- `config.resetBeforeLogin` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to empty profile
and auth state on login
- `config.enableRedirectHandling` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to enable
auth redirect handling listener. (default: `true`)
- `config.onAuthStateChanged` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function run when auth state
changes. Argument Pattern: `(authData, firebase, dispatch)`
- `config.enableEmptyAuthChanges` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to enable
empty auth changes. When set to true, `onAuthStateChanged` will be fired with,
empty auth changes such as undefined on initialization. See
[#137](https://github.com/prescottprue/react-redux-firebase/issues/137) for
more details. (default: `false`)
- `config.onRedirectResult` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Function run when redirect
result is returned. Argument Pattern: `(authData, firebase, dispatch)`
- `config.customAuthParameters` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Object for setting which
customAuthParameters are passed to external auth providers.
- `config.profileFactory` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Factory for modifying how user profile is saved.
- `config.fileMetadataFactory` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** Factory for modifying
how file meta data is written during file uploads
- `config.profileParamsToPopulate` **([Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) \| [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String))** Parameters within
profile object to populate. As of `v2.0.0` data is only loaded for population, not actually automatically populated
(allows access to both unpopulated and populated profile data).
- `config.autoPopulateProfile` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** **NOTE**: Not yet enabled for v2.0.0. Whether or not to
automatically populate profile with data loaded through profileParamsToPopulate config. (default: `true`)
- `config.setProfilePopulateResults` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Whether or not to
call SET actions for data that results from populating profile to redux under
the data path. For example role parameter on profile populated from 'roles'
root. True will call SET_PROFILE as well as a SET action with the role that
is loaded (places it in data/roles). (default: `false`)

**Examples**

_Setup_

```javascript
import { createStore, compose } from 'redux'
import { reactReduxFirebase } from 'react-redux-firebase'
import * as firebase from 'firebase'

// React Redux Firebase Config
const config = {
userProfile: 'users', // saves user profiles to '/users' on Firebase
// here is where you place other config options
}

// initialize script from Firebase page
const fbConfg = {} // firebase config object
firebase.initializeApp(fbConfig)

// Add react-redux-firebase to compose
// Note: In full projects this will often be within createStore.js or store.js
const createStoreWithFirebase = compose(
reactReduxFirebase(firebase, config),
)(createStore)

// Use Function later to create store
const store = createStoreWithFirebase(rootReducer, initialState)
```

Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** That accepts a component and returns a Component which
wraps the provided component (higher order component).
18 changes: 18 additions & 0 deletions docs/api/firebaseInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
- [updateProfile](#updateprofile)
- [updateAuth](#updateauth)
- [updateEmail](#updateemail)
- [reloadAuth](#reloadauth)
- [linkWithCredential](#linkwithcredential)
- [ref](#ref)
- [database](#database)
- [storage](#storage)
Expand Down Expand Up @@ -385,6 +387,22 @@ Update user's email

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**

## reloadAuth

Reload user's auth object. Must be authenticated.

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**

## linkWithCredential

Links the user account with the given credentials.

**Parameters**

- `credential` **firebase.auth.AuthCredential** The auth credential

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)**

## ref

Firebase ref function
Expand Down
Loading

0 comments on commit 9a32d8c

Please sign in to comment.