Skip to content

Commit

Permalink
getting mobx working with hot reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
lostpebble committed Aug 4, 2016
1 parent 556e016 commit 62fa58c
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .babelrc
Expand Up @@ -7,6 +7,7 @@
"react"
],
"plugins": [
"transform-decorators-legacy",
"react-hot-loader/babel",
"transform-regenerator"
]
Expand All @@ -18,6 +19,7 @@
"react"
],
"plugins": [
"transform-decorators-legacy",
"react-hot-loader/babel"
]
},
Expand All @@ -26,6 +28,9 @@
"presets": [
"es2015-webpack",
"react"
],
"plugins": [
"transform-decorators-legacy"
]
}
}
Expand Down
26 changes: 0 additions & 26 deletions client/mobx/stores/app-store.js

This file was deleted.

8 changes: 6 additions & 2 deletions package.json
Expand Up @@ -5,9 +5,9 @@
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node ./server/babel-server.js",
"start": "node ./src/server/babel-server.js",
"build": "cross-env BABEL_ENV=client-build webpack --config webpack.config.client.js --env.prod",
"dev": "cross-env NODE_ENV=development nodemon ./server/babel-server.js"
"dev": "cross-env NODE_ENV=development nodemon ./src/server/babel-server.js"
},
"author": "Paul Myburgh",
"license": "ISC",
Expand All @@ -24,17 +24,21 @@
"koa-router": "^7.0.1",
"koa-static": "^3.0.0",
"mobx": "^2.4.1",
"mobx-react": "^3.5.3",
"react": "^15.3.0",
"react-dom": "^15.3.0"
},
"devDependencies": {
"babel-cli": "^6.11.4",
"babel-loader": "^6.2.4",
"babel-plugin-transform-decorators": "^6.8.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-regenerator": "^6.11.4",
"babel-polyfill": "^6.9.1",
"babel-preset-es2015": "^6.9.0",
"babel-preset-es2015-webpack": "^6.4.2",
"babel-preset-react": "^6.11.1",
"babel-preset-stage-0": "^6.5.0",
"babel-preset-stage-3": "^6.11.0",
"cross-env": "^2.0.0",
"json-loader": "^0.5.4",
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions client/react/Counter.js → src/client/react/Counter.js
@@ -1,6 +1,9 @@
import React, { Component } from 'react';
import { observer } from 'mobx-react';

@observer
export default class Counter extends Component {

constructor(props) {
super(props);
this.state = { counter: 0 };
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions client/entry.js → src/crossover/entry.js
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import App from './React/App';
import App from '../client/react/App';

/*
+* This function is important for the crossover between server and client (isomorphic / universal).
Expand Down Expand Up @@ -30,7 +30,7 @@ if (typeof document !== 'undefined') {
// This is required for React hot reloading, will be
// turned off automatically for production
if (module.hot) {
module.hot.accept('./React/App', () => {
module.hot.accept('../client/react/App', () => {
ReactDOM.render(
baseReact(),
rootEl
Expand Down
26 changes: 26 additions & 0 deletions src/crossover/mobx/stores/counterStore.js
@@ -0,0 +1,26 @@
import { observable, action } from 'mobx';

const initialState = {
counterValue: 0,
};

export default class CounterStore {

@observable counterValue = 0;

constructor(counter) {
Object.assign(this, counter);
// this.counterValue = initialState && initialState.appStore && initialState.appStore.counterValue ? initialState.appStore.counterValue : 0;
}

@action
increaseCount() {
this.counterValue++;
}

toJson() {
return {
counterValue: this.counterValue,
};
}
}
File renamed without changes.
File renamed without changes.
Expand Up @@ -6,7 +6,7 @@ import logger from 'koa-logger';

import webpack from 'webpack';
import { devMiddleware, hotMiddleware } from 'koa-webpack-middleware';
import devConfig from '../../webpack.config.client';
import devConfig from '../../../webpack.config.client';

export function baseErrorHandling() {
return async (ctx, next) => {
Expand Down
@@ -1,6 +1,6 @@
import { renderToString } from 'react-dom/server';

import { baseReact } from '../../client/entry';
import { baseReact } from '../../crossover/entry';

export function renderReact() {
return async (ctx) => {
Expand Down
2 changes: 1 addition & 1 deletion server/server.js → src/server/server.js
Expand Up @@ -20,7 +20,7 @@ const prod = process.env.NODE_ENV !== 'development';

const app = new Koa();

const pug = new Pug({ viewPath: './server/views' });
const pug = new Pug({ viewPath: './src/server/views' });
pug.use(app);

app.use(serverLogging());
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions webpack.config.client.js
Expand Up @@ -6,10 +6,10 @@ module.exports = (env) => {

return ({
entry: !env.prod ? (
['react-hot-loader/patch', 'webpack-hot-middleware/client', './client/entry.js']
['react-hot-loader/patch', 'webpack-hot-middleware/client', './src/crossover/entry.js']
) : (
{
js: './client/entry.js',
js: './src/crossover/entry.js',
vendor: ['react', 'react-dom'],
}
),
Expand Down

0 comments on commit 62fa58c

Please sign in to comment.