-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(redux): add common class for redux runtime mixin
- Loading branch information
1 parent
158f204
commit 06c1ec5
Showing
3 changed files
with
41 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const { applyMiddleware } = require('redux'); | ||
const ReduxThunkMiddleware = require('redux-thunk').default; | ||
const { | ||
Mixin, | ||
strategies: { | ||
sync: { override }, | ||
}, | ||
} = require('hops-mixin'); | ||
|
||
class ReduxRuntimeCommonMixin extends Mixin { | ||
constructor(config, element, { redux: options = {} } = {}) { | ||
super(config); | ||
this.middlewares = options.middlewares; | ||
} | ||
|
||
getReduxMiddlewares() { | ||
return [ | ||
ReduxThunkMiddleware.withExtraArgument({ | ||
config: this.config, | ||
}), | ||
]; | ||
} | ||
|
||
applyMiddlewares() { | ||
const middlewares = this.middlewares || this.getReduxMiddlewares(); | ||
|
||
return middlewares.map(m => applyMiddleware(m)); | ||
} | ||
} | ||
|
||
ReduxRuntimeCommonMixin.strategies = { | ||
getReduxMiddlewares: override, | ||
}; | ||
|
||
module.exports = ReduxRuntimeCommonMixin; |
This file contains 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