Created
December 29, 2017 00:07
-
-
Save pechitook/6c7627c7c47c0998285d39e8a553f5b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Importamos el store de verdad, el cual fue modificado para recibir un array | |
de middlewares que aplica además de los default (thunk en mi caso). Utilicé | |
la función `compose` de redux para esto, y quedó algo así: | |
``` | |
export default (middlewares = []) => createStore( | |
reducer, | |
compose(applyMiddleware(thunk, ...middlewares), | |
) | |
``` | |
*/ | |
import createStore from 'src/store'; | |
export default class Store { | |
storedActions = []; | |
// Esto es una simple función de middleware que guarda en | |
// `storedActions` los actions que se fueron disparando. | |
recordActions = store => next => action => { | |
this.storedActions.push(action); | |
next(action); | |
}; | |
// Acá creamos nuestro store pasando el middleware de acá 👆 | |
store = createStore([this.recordActions]); | |
// Exponemos unos métodos que ya tiene el store | |
dispatch = this.store.dispatch | |
getState = this.store.getState | |
// Creamos los helpers que queríamos! | |
clearActions = () => this.storedActions = []; | |
getActions = () => this.storedActions; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment