在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:hung-phan/koa-react-isomorphic开源软件地址:https://github.com/hung-phan/koa-react-isomorphic开源编程语言:JavaScript 84.7%开源软件介绍:https://github.com/hung-phan/micro-nextjs)React and Koa boilerplate (deprecated. New project available atThe idea of this repository is to implement all new concepts and libraries which work great for React.js.
Requirement
Features
ExplanationTemplatesTemplates are written in marko.js with predefined template helpers. To see its usage, please refer to Server side renderingI use webpack-isomorphic-tools to support loading assets in
the server side. You can see the configuration file under Fetch data
Takes a look at createRedialEnhancer({
[FETCH_DATA_HOOK]: ({ store }) => store.dispatch(fetchTodos()),
[UPDATE_HEADER_HOOK]: ({ store }) => store.dispatch(updateLink([
// window.javascriptAssets will be injected to do preload link for optimizing route
{ rel: 'preload', href: window.javascriptAssets['static-page'], as: 'script' },
])),
})
Default require for nodeThe default const { ROOT, PUBLIC } = global.nodeRequire('./config/path-helper'); Note: Preload assets via redialTo be able to support for asynchronous chunks loading using You can use this to inject assets for the next page to improve performance. This is what I am trying to achieve preload-webpack-plugin. This will map the hook with the current component and trigger it (Note: This will only be applied to root component). Async react componentsIdea to structure redux applicationFor now, the best way is to place all logic in the same place with components to make it less painful when scaling the application. Current structure is the combination of ideas from organizing-redux and ducks-modular-redux. Briefly, I will have our reducer, action-types, and actions in the same place with featured components. Localize selectorsSome great ideas from scoped-selectors-for-redux-modules.
You can create a localized scope for selector using export const mountPoint = 'todos';
export const selectors = globalizeSelectors({
getTodos: identity, // it will also work with reselect library
}, mountPoint); Then in main reducer, you can have sth like this, which helps reduce the coupling with React view /* @flow */
import { combineReducers } from 'redux';
import todosReducer, { mountPoint as todosMountPoint } from './components/todos/logicBundle';
import routingReducer, { mountPoint as routingMountPoint } from './components/routing/logicBundle';
import helmetReducer, { mountPoint as helmetMountPoint } from './components/helmet/logicBundle';
export default combineReducers({
[todosMountPoint]: todosReducer,
[routingMountPoint]: routingReducer,
[helmetMountPoint]: helmetReducer,
}); Sample for logicBundle: export const mountPoint = "todos";
export const selectors = globalizeSelectors(
{
getTodos: identity
},
mountPoint
);
export const ADD_TODO = "todos/ADD_TODO";
export const REMOVE_TODO = "todos/REMOVE_TODO";
export const COMPLETE_TODO = "todos/COMPLETE_TODO";
export const SET_TODOS = "todos/SET_TODOS";
export const addTodo: AddTodoActionType = createAction(ADD_TODO);
export const removeTodo: RemoveTodoActionType = createAction(REMOVE_TODO);
export const completeTodo: CompleteTodoActionType = createAction(COMPLETE_TODO);
export const setTodos: SetTodosActionType = createAction(SET_TODOS);
export const fetchTodos = () =>
(dispatch: Function): Promise<TodoType[]> =>
fetch(getUrl("/api/v1/todos"))
.then(res => res.json())
.then((res: TodoType[]) => dispatch(setTodos(res)));
export default handleActions(
{
[ADD_TODO]: (state, { payload: text }) => update(state, {
$push: [{ text, complete: false }]
}),
[REMOVE_TODO]: (state, { payload: index }) => update(state, {
$splice: [[index, 1]]
}),
[COMPLETE_TODO]: (state, { payload: index }) => update(state, {
$splice: [
[index, 1],
[index, 0, { ...state[index], complete: !state[index].complete }]
]
}),
[SET_TODOS]: (state, { payload: todos }) => todos
},
[]
); Upcoming
Development$ git clone [email protected]:hung-phan/koa-react-isomorphic.git
$ cd koa-react-isomorphic
$ yarn install Hot reload$ yarn run watch
$ yarn run dev With server rendering - encourage for testing only$ SERVER_RENDERING=true yarn run watch
$ yarn run dev Enable flowtype in development$ yarn run flow-watch
$ yarn run flow-stop # to terminate the server You need to add annotation to the file to enable flowtype ( Test$ yarn test Debug$ yarn run watch
$ yarn run debug ProductionStart production server$ yarn run build
$ SECRET_KEY=your_env_key yarn start Docker container$ docker-compose build
$ docker-compose up Access QAFeel free to open an issue on the repo. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论