Created
December 10, 2017 16:50
-
-
Save x7c1/2f84d3bfc11c67ab609be94c26084a7a to your computer and use it in GitHub Desktop.
redux-seal middleware
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
| import { Sealer } from './Sealer'; | |
| export const seal = ({ dispatch, getState }) => next => action => { | |
| if (action.prototype instanceof Sealer) { | |
| return new action({ dispatch, getState }); | |
| } | |
| return next(action); | |
| }; |
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
| import React from 'react'; | |
| import { connect } from 'react-redux'; | |
| import { counterButton } from './counterButton'; | |
| const SamplePageView = props => { | |
| const button = props.counterButton(); | |
| return ( | |
| <div className='react-sample-area'> | |
| <button type='button' onClick={button.onClick}> | |
| {button.label} | |
| </button> | |
| </div> | |
| ); | |
| }; | |
| const mapStateToProps = state => state; | |
| const mapDispatchToProps = { | |
| counterButton, | |
| }; | |
| export const SamplePage = connect(mapStateToProps, mapDispatchToProps)(SamplePageView); |
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
| export class Sealer { | |
| constructor({ dispatch, getState }) { | |
| this.dispatch = dispatch; | |
| this.getState = getState; | |
| } | |
| get state() { | |
| return this.getState(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment