SHARE
TWEET

Untitled

a guest Sep 11th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const thunk = api => `I am a thunk with api: ${api.getState}`
  2.  
  3.  
  4. // middlewares -> createStore (function) -> reducer (function)
  5. const applyMiddleware =
  6.       (...middlewares) =>
  7.           (createStore) =>
  8.              (...args) => {
  9.                   const store = { data: createStore.data + 1 }
  10.                  
  11.                   let dispatch = () => 'I am dispatch'
  12.                  
  13.                   const middlewareApi = {
  14.                     getState: store.data,
  15.                     dispatch: (...args) => dispatch(...args)
  16.                   }
  17.                  
  18.                   const chain = middlewares.map(middleware => middleware(middlewareApi))
  19.                  
  20.                   console.log('chain-->', chain)
  21.                
  22.                    
  23.  
  24.              }
  25.  
  26.  
  27. //applyMiddleware(thunk)({ data: 0.1})('reducer', 'preloadedstate')
  28.  
  29.  
  30. const createThunkMiddleware =
  31.        (extraArg) =>
  32.           ({ dispatch, getState}) =>
  33.               next =>
  34.                 action => action(dispatch, getState, extraArg)
  35.  
  36. const _applyMiddleware = (middlewares, createStore, args, ) =>
  37.       `${middlewares} ${createStore} ${args}`
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top