react to create a project to learn basic grammar Redux middleware redux-thunk, simple application redux-saga (D)

1. Installation npm install --save redux-thunk

2. Installation npm install --save redux-saga

Alternatively wherein both use the same;

// Store / index file if you want to use the middleware, it must be introduced in the redux applyMiddleware 
Import {createstore, applyMiddleware, Compose} from 'redux' ;
 // Import from the thunk 'redux-the thunk' 
Import from the reducer './reducer '     
Import from mySaga ' ./mySaga ' 
Import from createSagaMiddleware ' Redux-saga '    @ incorporated saga 
const sagaMiddleware createSagaMiddleware = ();    // Create saga middleware 

// Chrome browser plug-in installed, there are three in the upper right corner of the browser point and click on the "more tools," then click on "extensions", then click "open the Chrome web store" on the right side, then search Redux DevTools installed directly; (circumvention tools) 
// configuration Redux Dev tools plug-in console debugging data warehouse 
//Store createstore = const (the reducer, window && window .__ .__ REDUX_DEVTOOLS_EXTENSION__ REDUX_DEVTOOLS_EXTENSION __ ()) 
// Redux-thunk and Redux Dev Tools plug-in to be used together, and need to use the enhanced functions. Need to compose the introduction of an increasing function before use 
// Redux Redux middleware the thunk-Saga-Redux 
? = Const composeEnhancers window .__ REDUX_DEVTOOLS_EXTENSION_COMPOSE__ 
    window .__ REDUX_DEVTOOLS_EXTENSION_COMPOSE __ ({}): compose 

// const = composeEnhancers Enhancer (applyMiddleware (the thunk)) // If you want to use-thunk Redux 

const Enhancer = composeEnhancers (applyMiddleware (sagaMiddleware)) // If you want to use Saga-Redux 

const store = createstore (the reducer, Enhancer) // create a data repository 

// the then RUN at The Saga
sagaMiddleware.run(mySaga)

export default store

// 官方写法
// const store = createStore(
//   reducer,
//   applyMiddleware(thunk)
// ) 
// In the following the new folder store mySaga.js 
// Import {Call, PUT, takeEvery, takeLatest} from 'Redux-Saga / Effects' 

// Sagas variety of forms can yield Effect. The easiest way is to yield a Promise. 
// Generator function 
// mySaga.js write the business logic 

// Note that using yield * will cause the Javascript runtime environment spread to the entire sequence. The resulting iterator (from Game ()) for all values of the yield from the nest in the iterator. A more powerful alternative is to use more generic middleware combination of mechanisms. 
function * mySaga () { 
  the yield the console.log ( 1111 ) 
} 

Export default mySaga;

 

Guess you like

Origin www.cnblogs.com/lhl66/p/12486976.html