initial
This commit is contained in:
commit
af69a60d3d
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
node_modules
|
2
.idea/.gitignore
vendored
Normal file
2
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/workspace.xml
|
9
.idea/BaseContextProvider.iml
Normal file
9
.idea/BaseContextProvider.iml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/misc.xml
Normal file
6
.idea/misc.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptSettings">
|
||||||
|
<option name="languageLevel" value="JSX" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/BaseContextProvider.iml" filepath="$PROJECT_DIR$/.idea/BaseContextProvider.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
4
.npmignore
Normal file
4
.npmignore
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
src
|
||||||
|
demo
|
||||||
|
.babelrc
|
||||||
|
webpack.config.js
|
14
lib/BaseContextProvider.js
Normal file
14
lib/BaseContextProvider.js
Normal file
File diff suppressed because one or more lines are too long
5143
package-lock.json
generated
Normal file
5143
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
28
package.json
Normal file
28
package.json
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "BaseContextProvider",
|
||||||
|
"version": "1.1.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "./lib/baseContextProvider.js",
|
||||||
|
"license": "",
|
||||||
|
"scripts": {
|
||||||
|
"build": "webpack"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"prop-types": "^15.6.0",
|
||||||
|
"react": "^16.0.0",
|
||||||
|
"react-dom": "^16.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"babel-core": "^6.21.0",
|
||||||
|
"babel-loader": "^7.1.4",
|
||||||
|
"babel-preset-env": "^1.6.1",
|
||||||
|
"babel-preset-react": "^6.16.0",
|
||||||
|
"babel-preset-stage-0": "^6.24.1",
|
||||||
|
"path": "^0.12.7",
|
||||||
|
"prop-types": "^15.6.0",
|
||||||
|
"react": "^16.0.0",
|
||||||
|
"react-dom": "^16.0.0",
|
||||||
|
"webpack": "^4.5.0",
|
||||||
|
"webpack-cli": "^3.2.1"
|
||||||
|
}
|
||||||
|
}
|
60
src/baseContextProvider.js
Normal file
60
src/baseContextProvider.js
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
const BaseContext = React.createContext({ base: 'Context' })
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Component : BaseContextProvider
|
||||||
|
*
|
||||||
|
* @author sl
|
||||||
|
* @time 13/2/20
|
||||||
|
* @param {{}}
|
||||||
|
* @constructor
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class BaseContextProvider extends React.Component {
|
||||||
|
getContextReturnValue() {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
|
getContext() {
|
||||||
|
return BaseContext
|
||||||
|
|
||||||
|
throw new Error('Please Implement Context')
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const contextReturn = this.getContextReturnValue()
|
||||||
|
const Context = this.getContext()
|
||||||
|
const { children } = this.props
|
||||||
|
|
||||||
|
//
|
||||||
|
return <Context.Provider value={contextReturn}>{children}</Context.Provider>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const baseContextWrap = (Provider) => {
|
||||||
|
return (Component) => (props) => <Provider children={<Component {...props} />} />
|
||||||
|
}
|
||||||
|
|
||||||
|
export function baseUseContext(context) {
|
||||||
|
return function() {
|
||||||
|
return React.useContext(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function baseWithContext(context, contextPassPropKey) {
|
||||||
|
const Consumer = context.Consumer
|
||||||
|
return (Component) => (props) => (
|
||||||
|
<Consumer>
|
||||||
|
{(contextValue) => (
|
||||||
|
<Component {...{ ...props, [contextPassPropKey]: contextValue }} />
|
||||||
|
)}
|
||||||
|
</Consumer>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseContextProvider.propTypes = {}
|
||||||
|
|
||||||
|
BaseContextProvider.defaultProps = {}
|
||||||
|
|
||||||
|
export default BaseContextProvider
|
20
webpack.config.js
Normal file
20
webpack.config.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
var path = require('path');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
mode: 'production',
|
||||||
|
entry: './src/baseContextProvider.js',
|
||||||
|
output: {
|
||||||
|
path: path.resolve('lib'),
|
||||||
|
filename: 'BaseContextProvider.js',
|
||||||
|
libraryTarget: 'commonjs2'
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.jsx?$/,
|
||||||
|
exclude: /(node_modules)/,
|
||||||
|
use: 'babel-loader'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user