Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mirror-thin....把 redux 相关与 react 相关分离成不同的包 #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ export const options = {
// global initial state
// initialState: undefined,

// Should be one of ['browser', 'hash', 'memory']
// Learn more: https://github.com/ReactTraining/history/blob/master/README.md
historyMode: 'browser',

// A list of the standard Redux middleware
middlewares: [],

Expand All @@ -25,20 +21,13 @@ export const options = {

}

const historyModes = ['browser', 'hash', 'memory']

export default function defaults(opts = {}) {

const {
historyMode,
middlewares,
addEffect
} = opts

if (historyMode && !historyModes.includes(historyMode)) {
throw new Error(`historyMode "${historyMode}" is invalid, must be one of ${historyModes.join(', ')}!`)
}

if (middlewares && !Array.isArray(middlewares)) {
throw new Error(`middlewares "${middlewares}" is invalid, must be an Array!`)
}
Expand Down
30 changes: 3 additions & 27 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,21 @@
import { Route, Redirect, Switch, Prompt, withRouter } from 'react-router'
import { Link, NavLink } from 'react-router-dom'
import { connect } from 'react-redux'
import model from './model'
import { actions } from './actions'
import render from './render'
import hook from './hook'
import Router from './router'
import defaults from './defaults'
import init from './init'

export default {
model,
actions,
hook,
defaults,
connect,
render,

Router,
Route,
Link,
NavLink,
Switch,
Redirect,
Prompt,
withRouter
init,
}

export {
model,
actions,
hook,
defaults,
connect,
render,

Router,
Route,
Link,
NavLink,
Switch,
Redirect,
Prompt,
withRouter
init,
}
23 changes: 23 additions & 0 deletions src/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { options } from './defaults'
import { models } from './model'
import { store, createStore, replaceReducer } from './store'

let started = false
let Root

export default function init() {

const { initialState, middlewares, reducers } = options

if (started) {

// If app has rendered, do `store.replaceReducer` to update store.
replaceReducer(store, models, reducers)


} else {
createStore(models, reducers, initialState, middlewares)
}

return store
}
45 changes: 0 additions & 45 deletions src/render.js

This file was deleted.

59 changes: 0 additions & 59 deletions src/router.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/routerMiddleware.js

This file was deleted.

16 changes: 6 additions & 10 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ import {
combineReducers,
compose
} from 'redux'
import { routerReducer } from 'react-router-redux'

import createMiddleware from './middleware'
import routerMiddleware from './routerMiddleware'

export let store

export function createStore(models, reducers, initialState, middlewares = []) {

const middleware = applyMiddleware(
routerMiddleware(),
...middlewares,
createMiddleware()
)
Expand All @@ -25,12 +22,12 @@ export function createStore(models, reducers, initialState, middlewares = []) {

// Following line to exclude from coverage report:
/* istanbul ignore next */
if (process.env.NODE_ENV !== 'production') {
// Redux devtools extension support.
if (global.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) {
composeEnhancers = global.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
}
}
// if (process.env.NODE_ENV !== 'production') {
// // Redux devtools extension support.
// if (global.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) {
// composeEnhancers = global.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
// }
// }

const reducer = createReducer(models, reducers)
const enhancer = composeEnhancers(...enhancers)
Expand All @@ -55,7 +52,6 @@ function createReducer(models, reducers) {
return combineReducers({
...reducers,
...modelReducers,
routing: routerReducer
})

}