Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
refactor: actionDispatcher now named initActionDispatcher dispatch re…
Browse files Browse the repository at this point in the history
…turned result of server.createInitAction (#237)

BREAKING: you must use createInitAction instead of actionDispatcher
  • Loading branch information
christophehurpeau authored Feb 17, 2017
1 parent fcf56c7 commit 5cf9628
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 21 deletions.
10 changes: 5 additions & 5 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ file at the root of your project.
- [host](#host)
- [port](#port)
- [middlewares](#serverMiddlewares)
- [actionDispatcher](#actionDispatcher)
- [createInitAction](#createInitAction)
- [layout](#layout)
- [ErrorPage](#ErrorPage)
- [onError](#onError)
Expand Down Expand Up @@ -96,12 +96,12 @@ specify its URL here (usually it means you want to use a CDN, or that you don't
Path to a file exporting an array of koa middlewares. Useful for additional logging, proxy request,
authentication or other things on server.

### <a id='actionDispatcher'></a>[`actionDispatcher`](#actionDispatcher)
### <a id='createInitAction'></a>[`createInitAction`](#createInitAction)
**`Path (`[`KoaRequest`](http://koajs.com/#request)`, `[`dispatch`](https://redux.js.org/docs/api/Store.html#getState)`, `[`getState`](http://redux.js.org/docs/api/Store.html#getState)`) -> yieldable`**

Path to a file exporting an actionDispatcher. Useful for populating the store on the server before rendering.
The actionDispatcher is passed the node http request object, the dispatch function, and getState
as parameters. It's expected to return something that can be yield (Promise, Generator, etc..) or nothing. If it returns a yieldable, then the server will wait for its completion before continuing.
Path to a file exporting an createInitAction. Useful for populating the store on the server before rendering.
`request` object is passed as a parameter to `createInitAction`.
It must return an action or nothing. The action can be a thunk.

### <a id='layout'></a>[`layout`](#layout)
**`Path <ReactComponent>`**
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ import { Route } from 'vitaminjs';

export default (
<Route path="/">

);
```
Create the `reducers.js` file:
Expand Down
2 changes: 1 addition & 1 deletion config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
ErrorPage: '__vitamin__/src/server/components/ErrorPage',
onError: '__vitamin__/config/utils/defaultFunction',
layout: '__vitamin__/src/server/components/HTMLLayout',
actionDispatcher: '__vitamin__/config/utils/defaultFunction',
createInitAction: '__vitamin__/config/utils/defaultFunction',
},
routes: '__vitamin__/config/utils/emptyArray',
basePath: '',
Expand Down
2 changes: 1 addition & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default () => {
['server', 'ErrorPage'],
['server', 'onError'],
['server', 'layout'],
['server', 'actionDispatcher'],
['server', 'createInitAction'],
['redux', 'reducers'],
['redux', 'middlewares'],
['redux', 'enhancers'],
Expand Down
4 changes: 2 additions & 2 deletions src/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import appMiddlewares from '__app_modules__server_middlewares__';
import renderer from './middlewares/renderer';
import storeCreator from './middlewares/store';
import router from './middlewares/router';
import actionDispatcher from './middlewares/actionDispatcher';
import initActionDispatcher from './middlewares/initActionDispatcher';
import staticAssetsServer from './middlewares/staticAssetsServer';

export default compose([
Expand All @@ -30,7 +30,7 @@ export default compose([
...appMiddlewares,
staticAssetsServer(),
storeCreator(),
actionDispatcher(),
initActionDispatcher(),
router(),
renderer(),
].filter(Boolean));
11 changes: 0 additions & 11 deletions src/server/middlewares/actionDispatcher.js

This file was deleted.

11 changes: 11 additions & 0 deletions src/server/middlewares/initActionDispatcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import createInitAction from '__app_modules__server_createInitAction__';

export default () => async (ctx, next) => {
const { dispatch } = ctx.state.store;
const action = createInitAction(ctx.request);
if (action) {
await dispatch(action);
}
await next();
};

0 comments on commit 5cf9628

Please sign in to comment.