This commit is contained in:
Vut Pov 2020-06-03 13:06:30 +07:00
commit af69a60d3d
13 changed files with 5308 additions and 0 deletions

7
.babelrc Normal file
View File

@ -0,0 +1,7 @@
{
"presets": [
"react",
"env",
"stage-0"
]
}

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

2
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
# Default ignored files
/workspace.xml

View 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
View 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
View 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
View 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
View File

@ -0,0 +1,4 @@
src
demo
.babelrc
webpack.config.js

File diff suppressed because one or more lines are too long

5143
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

28
package.json Normal file
View 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"
}
}

View 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
View 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'
}
]
}
}