├── .firebaserc
├── database.rules.json
├── .jshintrc
├── firebase.json
├── src
├── store
│ ├── store.js
│ └── todos
│ │ └── todos.js
├── component
│ ├── app.js
│ └── todos
│ │ └── todos-list.component.js
├── firebase
│ └── firebase-store.js
└── index.js
├── .gitignore
├── .babelrc
├── .hgignore
├── index.html
├── react-mobx-firebase-boilerplate.iml
├── README.md
├── server.js
├── .eslintrc
├── webpack.config.js
├── LICENSE
├── package.json
└── react-mobx-firebase-boilerplate.ipr
/.firebaserc:
--------------------------------------------------------------------------------
1 | {
2 | "projects": {
3 | "default": "react-mobx-firebase"
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/database.rules.json:
--------------------------------------------------------------------------------
1 | {
2 | "rules": {
3 | ".read": true,
4 | ".write": true
5 | }
6 | }
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "node": true,
3 | "browser": true,
4 | "esnext": true,
5 | "newcap": false
6 | }
7 |
--------------------------------------------------------------------------------
/firebase.json:
--------------------------------------------------------------------------------
1 | {
2 | "database": {
3 | "rules": "database.rules.json"
4 | },
5 | "hosting": {
6 | "public": "public"
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/store/store.js:
--------------------------------------------------------------------------------
1 | import {todos} from './todos/todos';
2 |
3 | const store = {
4 | todos
5 | };
6 |
7 | window.store = store;
8 |
9 | export {store};
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # IntelliJ files
2 | .idea
3 | *.iws
4 |
5 | # Node
6 | build
7 | dist
8 | node_modules
9 | .tmp
10 | *.log
11 |
12 | # version control
13 | .hg
--------------------------------------------------------------------------------
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "presets": [
3 | "react",
4 | "es2015",
5 | "stage-1"
6 | ],
7 | "plugins": ["transform-decorators-legacy", "react-hot-loader/babel"]
8 | }
9 |
--------------------------------------------------------------------------------
/.hgignore:
--------------------------------------------------------------------------------
1 | syntax: glob
2 |
3 | # IntelliJ files
4 | .idea/
5 | *.iws
6 |
7 | # Node
8 | build/
9 | dist/
10 | node_modules/
11 | .tmp
12 | *.log
13 |
14 | # version control
15 | .git
16 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Todo App
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/react-mobx-firebase-boilerplate.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/src/component/app.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import DevTools from 'mobx-react-devtools';
3 | import { TodosListComponent } from './todos/todos-list.component';
4 |
5 | class App extends Component {
6 | render() {
7 | return (
8 |
9 |
10 |
11 |
12 | );
13 | }
14 | }
15 |
16 | export default App;
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | mobx-react-boilerplate
2 | =====================
3 |
4 | Boilerplate to show how [React](https://facebook.github.io/react), [MobX](https://mobxjs.github.io/mobx) and [Firebase](https://firebase.google.com) work together.
5 |
6 | This is an evolved version based on [mobx-react-boilerplate](https://github.com/mobxjs/mobx-react-boilerplate).
7 |
8 | ### Run the example
9 |
10 | ```
11 | npm install
12 | npm start
13 | open http://localhost:3000
14 | ```
15 |
--------------------------------------------------------------------------------
/server.js:
--------------------------------------------------------------------------------
1 | var webpack = require('webpack');
2 | var WebpackDevServer = require('webpack-dev-server');
3 | var config = require('./webpack.config');
4 |
5 | new WebpackDevServer(webpack(config), {
6 | publicPath: config.output.publicPath,
7 | hot: true,
8 | historyApiFallback: true
9 | }).listen(3000, 'localhost', function (err, result) {
10 | if (err) {
11 | console.log(err);
12 | }
13 |
14 | console.log('Listening at localhost:3000');
15 | });
16 |
--------------------------------------------------------------------------------
/.eslintrc:
--------------------------------------------------------------------------------
1 | {
2 | "ecmaFeatures": {
3 | "jsx": true,
4 | "modules": true
5 | },
6 | "env": {
7 | "browser": true,
8 | "node": true
9 | },
10 | "parser": "babel-eslint",
11 | "rules": {
12 | "quotes": [2, "single"],
13 | "strict": [2, "never"],
14 | "react/jsx-uses-react": 2,
15 | "react/jsx-uses-vars": 2,
16 | "react/jsx-no-undef" : 2,
17 | "react/react-in-jsx-scope": 2,
18 | },
19 | "plugins": [
20 | "react"
21 | ]
22 | }
23 |
--------------------------------------------------------------------------------
/src/firebase/firebase-store.js:
--------------------------------------------------------------------------------
1 | import firebase from 'firebase';
2 |
3 | var config = {
4 | apiKey: "AIzaSyBnOKy0aJtSl8X9FjmC-eRJyT1_nlwksWA",
5 | authDomain: "react-mobx-firebase.firebaseapp.com",
6 | databaseURL: "https://react-mobx-firebase.firebaseio.com",
7 | storageBucket: "react-mobx-firebase.appspot.com",
8 | };
9 | firebase.initializeApp(config);
10 |
11 | const root = firebase.database().ref();
12 | const todos = firebase.database().ref('todos');
13 |
14 | const Fb = {
15 | root,
16 | todos
17 | };
18 | export { Fb };
--------------------------------------------------------------------------------
/src/component/todos/todos-list.component.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {map} from 'lodash';
3 | import { observer } from 'mobx-react';
4 | import {todos} from '../../store/todos/todos';
5 |
6 | @observer
7 | export class TodosListComponent extends React.Component {
8 |
9 | del = (id) => {
10 | todos.del(id)
11 | };
12 |
13 | render() {
14 | return (
15 |
16 | {map(todos.json, (it, key) => (
17 | - {it.name}
)
19 | )}
20 |
21 | )
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { render } from 'react-dom';
3 | import { AppContainer } from 'react-hot-loader';
4 | import App from './component/app';
5 | import {store} from './store/store';
6 |
7 | render(
8 |
9 |
10 | ,
11 | document.getElementById('root')
12 | );
13 |
14 | if (module.hot) {
15 | module.hot.accept('./component/app', () => {
16 | const NextApp = require('./component/app').default;
17 |
18 | render(
19 |
20 |
21 | ,
22 | document.getElementById('root')
23 | );
24 | });
25 | }
26 |
--------------------------------------------------------------------------------
/src/store/todos/todos.js:
--------------------------------------------------------------------------------
1 | import {observable, computed} from 'mobx';
2 | import {Fb} from '../../firebase/firebase-store';
3 | import {map, toJS} from 'mobx';
4 |
5 | class Todos {
6 | @observable todos = map({});
7 |
8 | constructor() {
9 | Fb.todos.on('value', (snapshot) => {
10 | this.todos = snapshot.val();
11 | });
12 | }
13 |
14 | @computed get json() {
15 | return toJS(this.todos);
16 | }
17 |
18 | add = (name) => {
19 | const id = Fb.todos.push().key;
20 | this.update(id, name);
21 | };
22 |
23 | update = (id, name) => {
24 | Fb.todos.update({[id]: {name}})
25 | };
26 |
27 | del = (id) => {
28 | Fb.todos.child(id).remove();
29 | };
30 | }
31 |
32 | const todos = new Todos();
33 | export {todos};
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | var path = require('path');
2 | var webpack = require('webpack');
3 |
4 | module.exports = {
5 | devtool: 'eval',
6 | entry: [
7 | 'react-hot-loader/patch',
8 | 'webpack-dev-server/client?http://localhost:3000',
9 | 'webpack/hot/only-dev-server',
10 | './src/index'
11 | ],
12 | output: {
13 | path: path.join(__dirname, 'dist'),
14 | filename: 'bundle.js',
15 | publicPath: '/static/'
16 | },
17 | plugins: [
18 | new webpack.HotModuleReplacementPlugin()
19 | ],
20 | resolve: {
21 | extensions: ['', '.js', '.jsx']
22 | },
23 | module: {
24 | loaders: [{
25 | test: /\.jsx?$/,
26 | loaders: ['babel'],
27 | include: path.join(__dirname, 'src')
28 | }]
29 | }
30 | };
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-mobx-firebase-boilerplate",
3 | "version": "1.0.0",
4 | "description": "Boilerplate for React + MobX + Firebase projects with JSX, ES6 compilation and hot code reloading",
5 | "scripts": {
6 | "start": "node server.js",
7 | "lint": "eslint src"
8 | },
9 | "keywords": [
10 | "react",
11 | "reactjs",
12 | "boilerplate",
13 | "mobx",
14 | "firebase"
15 | ],
16 | "author": "Ming Huang",
17 | "license": "MIT",
18 | "devDependencies": {
19 | "babel-core": "^6.9.1",
20 | "babel-eslint": "^6.1.0",
21 | "babel-loader": "^6.2.4",
22 | "babel-plugin-transform-decorators-legacy": "^1.3.4",
23 | "babel-preset-es2015": "^6.9.0",
24 | "babel-preset-react": "^6.5.0",
25 | "babel-preset-stage-1": "^6.5.0",
26 | "eslint-plugin-react": "^5.1.1",
27 | "eslint": "^2.13.1",
28 | "mobx-react-devtools": "^4.2.0",
29 | "react-hot-loader": "^3.0.0-beta.2",
30 | "webpack": "^1.13.1",
31 | "webpack-dev-server": "^1.14.1"
32 | },
33 | "dependencies": {
34 | "firebase": "^3.3.0",
35 | "lodash": "^4.15.0",
36 | "mobx": "^2.2.2",
37 | "mobx-react": "^3.3.1",
38 | "react": "^15.1.0",
39 | "react-dom": "^15.1.0"
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/react-mobx-firebase-boilerplate.ipr:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | 1.7
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------