forked from yahoo/fluxible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Replace obsolete react context (yahoo#663)
- Loading branch information
1 parent
2dbf3aa
commit 3e7e2a9
Showing
14 changed files
with
99 additions
and
122 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,39 @@ | ||
import { Component, createContext, createElement } from 'react'; | ||
import { arrayOf, node, object, string } from 'prop-types'; | ||
|
||
export const FluxibleContext = createContext({ | ||
executeAction: () => {}, | ||
getStore: () => {}, | ||
}); | ||
|
||
export class FluxibleProvider extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
const state = { | ||
executeAction: this.props.context.executeAction, | ||
getStore: this.props.context.getStore, | ||
}; | ||
|
||
this.props.plugins.forEach(plugin => { | ||
state[plugin] = this.props.context[plugin]; | ||
}); | ||
|
||
this.state = state; | ||
} | ||
|
||
render() { | ||
const props = { value: this.state }; | ||
return createElement(FluxibleContext.Provider, props, this.props.children); | ||
} | ||
} | ||
|
||
FluxibleProvider.propTypes = { | ||
children: node.isRequired, | ||
context: object.isRequired, | ||
plugins: arrayOf(string) | ||
}; | ||
|
||
FluxibleProvider.defaultProps = { | ||
plugins: [] | ||
}; |
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
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
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
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
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
Oops, something went wrong.