[] Redux: Redux', 1 |
, Redux, Redux Redux.
, Redux, , Redux Reactiflux , API Redux Github', Redux' Reddit' HN (HackerNews). , , , Redux , . Redux', , , :)
Redux, , . , , , - .
, , , , , , Redux. .
, , Redux . , Redux , Redux. (, HN : , action' action creator' , , ?, , .)
, , , Redux' , , , , Redux , , Redux. Redux , . , , Redux, Redux', , Redux.
. 1 Redux, , . , Redux, ( ).
2 , Redux, . , Redux , , .
, ! (, .)
, ? Redux'. , Redux .
. - , Redux , . , .
ReactConf 2017 - , , , , , , , , , -. , . , .
, , , - . , Redux , -.
( Redux) , , , Redux, -. (, -, , Redux .) , , , Redux', , , , .
, Redux' . .
createStore Redux'. , , , store enhancers ( , store ) observables, createStore ( --Redux Redux):
function createStore(reducer) {
var state;
var listeners = []
function getState() {
return state
}
function subscribe(listener) {
listeners.push(listener)
return unsubscribe() {
var index = listeners.indexOf(listener)
listeners.splice(index, 1)
}
}
function dispatch(action) {
state = reducer(state, action)
listeners.forEach(listener => listener())
}
dispatch({})
return { dispatch, subscribe, getState }
}
25 , . , action , API store.
:
pull-request :
, , Redux Webpack, React, , , action creator', , Babel, npm, CSS , , , Egghead, , ... , HTML, - DOM. !
dispatch createStore -reducer . , , , , Redux.
createStore , , . createStore : action', store, , action' type undefined.
Flux . Flux Action' Flux:
, , , web api , action , action . ActionCreators action, action . type. store action, , . Flux, stor' view ; . Action' stor' , ().
Redux type, , action', .
, . combineReducers , reducer , , action, - undefined. , JS , -reducer'. , combineReducers , -reducer' . , combineReducers , , , .
Redux : enhancer' () store action', , . store enhancer action' , action' . , action' . , Redux DevTools ( Chrome), , , action' , , . action' .
- . -reducer , acton' . reducer' , DevTools action. , .
connect React-Redux. , connect, , , . , , .
, , action , connect , . , connect , ( combineReducers , , ). , connect mapStateToProps, , props, store. , , connect . connect' , , - , connect , .
, Redux. Reselect -, Redux. , , , , .
, React' shouldComponentUpdate, , props props, :
return !shallowEqual(this.props, nextProps)
, . - , React' .
Redux' createStore , : action' , type. , , type.
, , Redux DevTools, React-Redux, React Reselect, , action'/ -reducer'. , , , . , .
, , Redux'. -reducer AJAX-. getState() . , , , action' . , .
, , Redux'. , , Redux'.
Redux , Redux, , . :
README Redux'a.
- , Redux.
- (Stores, Action Creator', ) .
- Flux', .
- - Flux.
- , , .
- : JS , , ImmutableJS ..
- , Redux , .
- , Stor'.
- (, , /)
- , Redux.
- stor' action'. .
- (mocks).
- Stor', Stor' .
- API .
- ?
Redux, issue-, , Redux.
Redux Flux. Flux: (dispatching) action', action' type, action' (action creators), , , .
Redux ʻ, : Flux' Flux ʻ.
Redux', , . , .
, action, , , action ( ). store , , action , .
, .
Redux' type action', , action' . Redux DevTools type action', , .
, , . , action . , , action , action . action (, SET_DATA), action , .
Redux , , , . , : , , .
, Redux , , , , . ( , Redux' , , : .)
reducer' , , -reducer . reducer' AJAX .
AJAX - - , , , - . , .
Redux Flux store. Flux Redux Flux . Flux UsersStore, PostsStore CommentsStore, Redux , : { users, posts, comments }.
, , . , . , reducer , , , . reducer' . combineReducers Redux' .
-reducer , , action' reducer' , . , action' reducer' , Redux'. : action' 1-- reducer'.
Redux . ( applyMiddleware store enhancers) , , , .
Redux . -reducer, . combineReducers, reducer' . reducer' . , reducer' , , .
Flux', Stor' waitFor(), . CommentsStore PostsStore , , PostsStore.waitFor(), , PostsStore . , . , Redux -reducer' .
( ) Combining Stateless Stores
, commentsReducer action'. hasCommentReallyBeenAdded (). API. , , : reducer . store . , , - .
export default function commentsReducer(state = initialState, action, hasPostReallyBeenAdded) {}
//
export default function rootReducer(state = initialState, action) {
const postState = postsReducer(state.post, action);
const {hasPostReallyBeenAdded} = postState;
const commentState = commentsReducer(state.comments, action, hasPostReallyBeenAdded);
return { post : postState, comments : commentState };
}
reducer' . reducer reducer', / .
Redux'. :
API API. middleware stor' , Redux dispatch() createStore() . , 1.0. . , API.
Redux NuclearJS:
- ImmutableJS
- API
- , Redux -
Redux , .
API createStore, . , (Reducer, Action Creator) - Redux. , Redux , , .
API. Flux, Flummox , , (, START/SUCCESS/FAILURE action' ). - , , .
action' , action middleware, middlewar', , .
, , Redux , , , , Flummox. , .( Slack) Ko Flux . , , , reduxjs Github'.
- Redux', , Rx . , , Redux Rx, middlewar'.
, middleware API , , . Flux Flummox , , -middleware. - , - , , . Redux , , , . Redux Thunk , . , / . !
. , Redux , . README, Redux' , , API . , Redux , Redux , .
Redux', 2 , , Redux, , Redux.
: blog.isquaredsoftware.com/2017/05/idiomatic-redux-tao-of-redux-part-1
, , .