diff --git a/README.md b/README.md index f3e74e6..49bc6e1 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ When we have the `firebaseApp` we just add it as paramater to our Provider. import React from 'react'; import ReactDOM from 'react-dom'; import { Provider } from 'react-redux'; -import { FirebaseProvider } from 'firekit'; // Import the FirebaseProvider from firekit +import { FirebaseProvider } from 'firekit-provider'; // Import the FirebaseProvider from firekit import configureStore from './store'; import { Root } from './containers/Root'; import { addLocalizationData } from './locales'; @@ -157,7 +157,7 @@ Let us take a look on a simple component. import React, { Component } from 'react'; import {injectIntl, intlShape} from 'react-intl'; import { Activity } from '../../containers/Activity'; -import { withFirebase } from 'firekit'; +import { withFirebase } from 'firekit-provider'; class MyComponent extends Component { @@ -201,7 +201,7 @@ The `FirebaseProvider` provides the `firebaseApp` trought the rect context and ` import React, { Component } from 'react'; import {injectIntl, intlShape} from 'react-intl'; import { Activity } from '../../containers/Activity'; -import { withFirebase } from 'firekit'; +import { withFirebase } from 'firekit-provider'; class MyComponent extends Component { @@ -239,7 +239,7 @@ Firebase has integrated a listener to observe the connection state to your fireb ```js import React, { Component } from 'react'; import { connect } from 'react-redux'; -import { withFirebase } from 'firekit'; +import { withFirebase } from 'firekit-provider'; class MyComponent extends Component { @@ -285,7 +285,7 @@ We can easely observe lists in the realtime database using the `watchList` and ` ```js import React, { Component } from 'react'; import { connect } from 'react-redux'; -import { withFirebase } from 'firekit'; +import { withFirebase } from 'firekit-provider'; import _ from 'lodash'; class MyComponent extends Component { @@ -413,6 +413,7 @@ And comes the cool thing. If you are in the Form working on fields and someone e //... {history.push('/companies');}} @@ -447,6 +448,7 @@ Firebase offers a simple API for managing push notification messages. Firekit pr - [X] integrate firebase auth watcher - [X] integrate firebase queries watcher - [X] implement alias names (custom destination locations) for path and list watchers +- [X] seperate firekit-provider and fireform in seperate projects - [ ] integrate selectors for lists - [ ] integrate error hanling - [ ] integrate loading indicators in redux state diff --git a/src/components/FirebaseProvider.js b/demo/firekit-provider/FirebaseProvider.js similarity index 100% rename from src/components/FirebaseProvider.js rename to demo/firekit-provider/FirebaseProvider.js diff --git a/src/withFirebase.js b/demo/firekit-provider/withFirebase.js similarity index 84% rename from src/withFirebase.js rename to demo/firekit-provider/withFirebase.js index 55a3ba3..62693c5 100644 --- a/src/withFirebase.js +++ b/demo/firekit-provider/withFirebase.js @@ -1,11 +1,11 @@ import React from 'react' import PropTypes from 'prop-types' -import { clearInitialization } from './store/initialization/actions' -import { initConnection, unsubscribeConnection } from './store/connection/actions' -import { watchAuth, authStateChanged, authError} from './store/auth/actions' -import { watchList, unwatchList, destroyList, unwatchAllLists } from './store/lists/actions' -import { watchPath, unwatchPath, destroyPath, unwatchAllPaths } from './store/paths/actions' -import { initMessaging, clearMessage } from './store/messaging/actions' +import { clearInitialization } from '../../src/store/initialization/actions' +import { initConnection, unsubscribeConnection } from '../../src/store/connection/actions' +import { watchAuth, authStateChanged, authError} from '../../src/store/auth/actions' +import { watchList, unwatchList, destroyList, unwatchAllLists } from '../../src/store/lists/actions' +import { watchPath, unwatchPath, destroyPath, unwatchAllPaths } from '../../src/store/paths/actions' +import { initMessaging, clearMessage } from '../../src/store/messaging/actions' const withFirebase = (Component) => { const ChildComponent = (props, context) => { diff --git a/demo/src/components/Drawer/DrawerContent.js b/demo/src/components/Drawer/DrawerContent.js index 10bf58b..1058921 100644 --- a/demo/src/components/Drawer/DrawerContent.js +++ b/demo/src/components/Drawer/DrawerContent.js @@ -8,7 +8,7 @@ import allLocales from '../../locales'; import firebase from 'firebase'; import { injectIntl } from 'react-intl'; import { withRouter } from 'react-router-dom'; -import { withFirebase } from '../../../../src'; +import withFirebase from '../../../firekit-provider/withFirebase'; const DrawerContent = (props, context) => { diff --git a/demo/src/components/Drawer/DrawerHeader.js b/demo/src/components/Drawer/DrawerHeader.js index 855bf88..d48391f 100644 --- a/demo/src/components/Drawer/DrawerHeader.js +++ b/demo/src/components/Drawer/DrawerHeader.js @@ -9,7 +9,7 @@ import {RMWIcon} from '../Icons'; import {injectIntl} from 'react-intl'; import muiThemeable from 'material-ui/styles/muiThemeable'; import CircularProgress from 'material-ui/CircularProgress'; -import { withFirebase } from '../../../../src'; +import withFirebase from '../../../firekit-provider/withFirebase';; const DrawerHeader = ({muiTheme, intl, auth, setAuthMenuOpen, fetchUser, dialogs, setDialogIsOpen, firebaseApp}) => { const styles={ diff --git a/demo/src/containers/About/About.js b/demo/src/containers/About/About.js index 5443afd..a56c155 100644 --- a/demo/src/containers/About/About.js +++ b/demo/src/containers/About/About.js @@ -1,7 +1,7 @@ import React, { Component } from 'react'; import {injectIntl, intlShape} from 'react-intl'; import { Activity } from '../../containers/Activity'; -import { withFirebase } from '../../../../src'; +import withFirebase from '../../../firekit-provider/withFirebase'; class About extends Component { diff --git a/demo/src/containers/Companies/Companie.js b/demo/src/containers/Companies/Companie.js index 36f197a..29bbe36 100644 --- a/demo/src/containers/Companies/Companie.js +++ b/demo/src/containers/Companies/Companie.js @@ -9,7 +9,8 @@ import firebase from 'firebase'; import FontIcon from 'material-ui/FontIcon'; import FlatButton from 'material-ui/FlatButton'; import Dialog from 'material-ui/Dialog'; -import { withFirebase, FireForm } from '../../../../src'; +import withFirebase from '../../../firekit-provider/withFirebase'; +import FireForm from 'fireform' const path='/companies/'; @@ -56,7 +57,7 @@ class Companie extends Component { render() { - const {history, intl, setDialogIsOpen, dialogs, match}=this.props; + const {history, intl, setDialogIsOpen, dialogs, match, firebaseApp}=this.props; const actions = [ {history.push('/companies');}} diff --git a/demo/src/containers/Companies/Companies.js b/demo/src/containers/Companies/Companies.js index 7ff203a..d2426e5 100644 --- a/demo/src/containers/Companies/Companies.js +++ b/demo/src/containers/Companies/Companies.js @@ -11,7 +11,7 @@ import FontIcon from 'material-ui/FontIcon'; import FloatingActionButton from 'material-ui/FloatingActionButton'; import {withRouter} from 'react-router-dom'; import Avatar from 'material-ui/Avatar'; -import { withFirebase } from '../../../../src'; +import withFirebase from '../../../firekit-provider/withFirebase'; class Vehicles extends Component { diff --git a/demo/src/containers/MyAccount/Form.js b/demo/src/containers/MyAccount/Form.js index 612f636..975b214 100644 --- a/demo/src/containers/MyAccount/Form.js +++ b/demo/src/containers/MyAccount/Form.js @@ -11,7 +11,7 @@ import { setDialogIsOpen } from '../../store/dialogs/actions'; import { ImageCropDialog } from '../../containers/ImageCropDialog'; import IconButton from 'material-ui/IconButton'; import { withRouter } from 'react-router-dom'; -import { withFirebase } from '../../../../src'; +import withFirebase from '../../../firekit-provider/withFirebase'; import {GoogleIcon, FacebookIcon, GitHubIcon, TwitterIcon} from '../../components/Icons'; import muiThemeable from 'material-ui/styles/muiThemeable'; import config from '../../config'; diff --git a/demo/src/containers/MyAccount/MyAccount.js b/demo/src/containers/MyAccount/MyAccount.js index dc45965..4108e46 100644 --- a/demo/src/containers/MyAccount/MyAccount.js +++ b/demo/src/containers/MyAccount/MyAccount.js @@ -10,7 +10,8 @@ import FlatButton from 'material-ui/FlatButton'; import Dialog from 'material-ui/Dialog'; import firebase from 'firebase'; import {formValueSelector } from 'redux-form'; -import { withFirebase, FireForm } from '../../../../src'; +import withFirebase from '../../../firekit-provider/withFirebase'; +import FireForm from 'fireform' const path='/users/'; @@ -248,7 +249,7 @@ class MyAccount extends Component { render() { - const {history, intl, setDialogIsOpen, dialogs, match, auth}=this.props; + const {history, intl, setDialogIsOpen, dialogs, match, auth, firebaseApp}=this.props; const actions = [
{history.push('/tasks');}} diff --git a/demo/src/containers/Tasks/Tasks.js b/demo/src/containers/Tasks/Tasks.js index 88f3646..49bb5b1 100644 --- a/demo/src/containers/Tasks/Tasks.js +++ b/demo/src/containers/Tasks/Tasks.js @@ -19,7 +19,7 @@ import {BottomNavigation} from 'material-ui/BottomNavigation'; import {withRouter} from 'react-router-dom'; import FlatButton from 'material-ui/FlatButton'; import Dialog from 'material-ui/Dialog'; -import { withFirebase } from '../../../../src'; +import withFirebase from '../../../firekit-provider/withFirebase'; class Tasks extends Component { diff --git a/demo/src/containers/Users/Users.js b/demo/src/containers/Users/Users.js index d3330c5..5796941 100644 --- a/demo/src/containers/Users/Users.js +++ b/demo/src/containers/Users/Users.js @@ -10,7 +10,7 @@ import Avatar from 'material-ui/Avatar'; import FontIcon from 'material-ui/FontIcon'; import {GoogleIcon, FacebookIcon, GitHubIcon, TwitterIcon} from '../../components/Icons'; import IconButton from 'material-ui/IconButton'; -import { withFirebase } from '../../../../src'; +import withFirebase from '../../../firekit-provider/withFirebase'; import ReactList from 'react-list'; class Users extends Component { diff --git a/demo/src/index.js b/demo/src/index.js index f41a7ff..fff032b 100644 --- a/demo/src/index.js +++ b/demo/src/index.js @@ -1,7 +1,7 @@ import React, {Component} from 'react' import {render} from 'react-dom' import { Provider } from 'react-redux'; -import { FirebaseProvider } from '../../src'; +import FirebaseProvider from '../firekit-provider/FirebaseProvider'; import configureStore from './store'; import { Root } from './containers/Root'; import { addLocalizationData } from './locales'; diff --git a/package-lock.json b/package-lock.json index bf21fc7..8bfc626 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4016,6 +4016,18 @@ "firebase": "4.4.0" } }, + "fireform": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/fireform/-/fireform-0.2.1.tgz", + "integrity": "sha512-0CojM4ZNvmbQfX5wEOWitHoQAIDXjUKpG1W0K5UhoGUcWysNO68a4jXAbx48RpH7EblXt8VpCyCh3E1huPeJwA==", + "dev": true + }, + "firekit-provider": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/firekit-provider/-/firekit-provider-0.2.0.tgz", + "integrity": "sha512-ToFuQwZEFiKIYnxL+k3oDL9P38E4Hju0sdAbpSOPM2ywAyZljDEOCAVrQi8vaFz49tZfKP1LpDltmKS2r71TLQ==", + "dev": true + }, "flatten": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/flatten/-/flatten-1.0.2.tgz", diff --git a/package.json b/package.json index 8c59172..31123ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "firekit", - "version": "0.1.31", + "version": "0.2.1", "description": "Firebase toolkit for sync with redux", "main": "lib/index.js", "module": "es/index.js", @@ -20,14 +20,12 @@ "test:watch": "nwb test-react --server" }, "dependencies": {}, - "peerDependencies": { - "react": "15.x || 16.x", - "firebase": "4.x", - "redux-form": "7.x" - }, + "peerDependencies": {}, "devDependencies": { "firebase": "^4.4.0", "firebaseui": "^2.3.0", + "fireform": "^0.2.1", + "firekit-provider": "^0.2.0", "github-markdown-css": "^2.8.0", "immutable": "^3.8.1", "intl": "^1.2.5", @@ -65,9 +63,8 @@ "license": "MIT", "repository": "https://github.com/TarikHuber/firekit", "keywords": [ - "react-component", "firebase", "redux", - "react" + "sync" ] } diff --git a/src/components/FireForm.js b/src/components/FireForm.js deleted file mode 100644 index f24558d..0000000 --- a/src/components/FireForm.js +++ /dev/null @@ -1,144 +0,0 @@ -import React, {Component} from 'react'; -import PropTypes from 'prop-types'; -import { initialize } from 'redux-form'; -import withFirebase from '../withFirebase'; - -class FireForm extends Component { - - constructor(props, context){ - super(); - this.context=context; - this.state={ - initialized: false - } - } - - clean(obj){ - Object.keys(obj).forEach((key) => (obj[key] === undefined) && delete obj[key]); - return obj - } - - getCreateValues = (values) => { - const { handleCreateValues } = this.props; - - if(handleCreateValues!==undefined && handleCreateValues instanceof Function){ - return handleCreateValues(values); - } - - return values; - - } - - getUpdateValues = (values, dispatch, props) => { - const { handleUpdateValues } = this.props; - - if(handleUpdateValues!==undefined && handleUpdateValues instanceof Function){ - return handleUpdateValues(values); - } - - return values; - } - - - handleSubmit =(values) => { - const { path, uid, onSubmitSuccess, firebaseApp} = this.props; - - if(uid){ - - const updateValues=this.getUpdateValues(this.clean(values)); - - if(updateValues){ - firebaseApp.database().ref().child(`${path}${uid}`).update(updateValues).then(()=>{ - if(onSubmitSuccess && onSubmitSuccess instanceof Function){ - onSubmitSuccess(values, uid); - } - }, e=>{console.log(e);}) - } - - }else{ - - const createValues=this.getCreateValues(this.clean(values)); - - if(createValues){ - firebaseApp.database().ref().child(`${path}`).push(createValues).then((snap)=>{ - if(onSubmitSuccess && onSubmitSuccess instanceof Function){ - onSubmitSuccess(values, snap.key); - } - }, e=>{console.log(e);}) - } - - } - - } - - handleDelete = () => { - const { onDelete, path, uid, firebaseApp} = this.props; - - if(uid){ - firebaseApp.database().ref().child(`${path}${uid}`).remove().then(()=>{ - if(onDelete && onDelete instanceof Function){ - onDelete(); - } - }) - } - - } - - componentWillMount(){ - const { path, uid, name, firebaseApp} = this.props; - - if(uid){ - firebaseApp.database().ref(`${path}${uid}`).on('value', - snapshot => { - this.setState({initialized: true}, ()=>{ - this.props.dispatch(initialize(name, snapshot.val(), true)) - }) - }) - }else{ - this.setState({initialValues: {}, initialized:true}) - } - - } - - componentWillReceiveProps = (nextProps) => { - const { uid, name, path, firebaseApp } = this.props; - const { uid: nextUid } = nextProps; - - if(uid && uid!==nextUid){ - firebaseApp.database().ref(`${path}${nextUid}`).on('value', - snapshot => { - this.setState({initialized: true}, ()=>{ - nextProps.dispatch(initialize(name, snapshot.val(), true)) - }) - }) - } - } - - componentWillUnmount(){ - const { path, uid, firebaseApp} = this.props; - firebaseApp.database().ref(`${path}${uid}`).off() - } - - - render() { - - return React.Children.only(React.cloneElement(this.props.children, { - onSubmit: this.handleSubmit, - ...this.state, - ...this.props - })) - } -} - -FireForm.propTypes = { - path: PropTypes.string.isRequired, - name: PropTypes.string.isRequired, - uid: PropTypes.string, - onSubmitSuccess: PropTypes.func, - onDelete: PropTypes.func, - handleCreateValues: PropTypes.func, - handleUpdateValues: PropTypes.func, -}; - - -export default withFirebase(FireForm); diff --git a/src/index.js b/src/index.js index b3c876e..792621f 100644 --- a/src/index.js +++ b/src/index.js @@ -14,9 +14,6 @@ const firekitReducers = { initialization: initializationReducer } -export { default as FirebaseProvider } from './components/FirebaseProvider' -export { default as FireForm } from './components/FireForm' -export { default as withFirebase } from './withFirebase' export { default as authReducer } from './store/auth/reducer' export { default as connectionReducer } from './store/connection/reducer' export { default as messagingReducer } from './store/messaging/reducer'