The goal of this project is to provide a starting base for an isomorphic (universal) mobx react project.
Features:
async/awaitsupport- Isomorphic
- CSS and SCSS compilation
- MongoDB user register/login/logout
- Token based authentication
- Decorators for accessing actions and state
- Hot reload
- Automatic restarts (when server code changes)
For development:
npm run dev
For production:
npm run prod
Node 6+ or Node 4 with additional babel plugins
MongoDB server
- Optimized for minimal bundle size.
- Optimized for server-side speed.
- Using MobX, the easiest and insanely fast state manager.
- Simple and minimal with routing, authentication, database and server-side rendering.
- Good developer experience with hot-reloading and source-maps.
gb -G=4 -k=true -c 200 -n 10000 http://localhost:2000/about
Document Path: /page/about
Document Length: 1374 bytes
Concurrency Level: 200
Time taken for tests: 26.03 seconds
Complete requests: 10000
Failed requests: 0
HTML transferred: 13740000 bytes
Requests per second: 384.16 [#/sec] (mean)
Time per request: 520.620 [ms] (mean)
Time per request: 2.603 [ms] (mean, across all concurrent requests)
HTML Transfer rate: 515.42 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Total: 66 2 52.84 503 783Tested on i7-6700K @ 4.00GHz 16GB RAM. Single node.js instance.
Stores will contain the state of your application and the methods that mutate that state. Basically most of your client side logic is inside stores.
The @connect decorator injects stores into your components.
Additionally, it keeps your components up to date with any changes in your stores.
Example: If you display a messageCount from a Messages store and it gets updated,
then all the visible components that display that messageCount will update themselves.
No, it actually allows the rendering to be done more efficiently. So connect as many as you want !
- Goto
src/server/models - Add
[Name].jswith your model in it
- Goto
src/client/stores - Add
[name].js(based on another store likeaccount.js) - Update
src/client/stores.js
- Goto
src/server/config - Set
server.SSRvariable totrueorfalse
Make sure you added the @connect decorator to your component.
You cannot use decorators on stateless components. You should instead wrap your component like this:
const MyComponent = connect((props, context) => {
return <p>{context.state.something} !</p>
})Add a static onEnter method to your component like this:
class MyComponent extends React.Component {
static onEnter({ myStore, params }) {
// Make sure to ALWAYS returns something (preferably a promise), even if its nothing!
// Otherwise we won't know when the method finished it's work
return myStore.browse()
}
// ...
}The onEnter method is smart, it will be executed either on the server or on the browser depending on how you access the website.
It also passes all your stores and url params as arguments as a convenience.
Ryan Megidov
