consume-multiple-contexts
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -18,15 +18,21 @@ import React from 'react'; | ||
function withMultipleContext(...rest) { | ||
const multipleContexts = createMultipleContexts(...rest); | ||
function withMultipleContextsFactory(...rest) { | ||
const withContext = createMultipleContexts(...rest); | ||
return Component => { | ||
class MultipleContexts extends React.PureComponent { | ||
class ComponentWithMultipleContexts extends React.Component { | ||
constructor(...rest) { | ||
super(...rest); | ||
this._renderComponent = context => React.createElement(Component, _extends({}, context, this.props)); | ||
} | ||
render() { | ||
return multipleContexts(context => React.createElement(Component, _extends({}, context, this.props))); | ||
return withContext(this._renderComponent); | ||
} | ||
} | ||
hoistNonReactStatic(MultipleContexts, Component); | ||
hoistNonReactStatic(ComponentWithMultipleContexts, Component); | ||
return MultipleContexts; | ||
return ComponentWithMultipleContexts; | ||
}; | ||
@@ -42,5 +48,5 @@ } | ||
return renderProps => { | ||
return renderComponent => { | ||
let context = {}; | ||
let callbackWithContext = () => renderProps(context); | ||
let callbackWithContext = () => renderComponent(context); | ||
@@ -67,2 +73,2 @@ let consumerTree = namedContexts.reduce((componentTreeFactory, namedContext) => generateConsumer(namedContext, context, componentTreeFactory), callbackWithContext)(); | ||
export { withMultipleContext, createNamedContext, createMultipleContexts }; | ||
export { withMultipleContextsFactory, createNamedContext, createMultipleContexts, generateConsumer }; |
@@ -24,15 +24,21 @@ 'use strict'; | ||
function withMultipleContext(...rest) { | ||
const multipleContexts = createMultipleContexts(...rest); | ||
function withMultipleContextsFactory(...rest) { | ||
const withContext = createMultipleContexts(...rest); | ||
return Component => { | ||
class MultipleContexts extends React.PureComponent { | ||
class ComponentWithMultipleContexts extends React.Component { | ||
constructor(...rest) { | ||
super(...rest); | ||
this._renderComponent = context => React.createElement(Component, _extends({}, context, this.props)); | ||
} | ||
render() { | ||
return multipleContexts(context => React.createElement(Component, _extends({}, context, this.props))); | ||
return withContext(this._renderComponent); | ||
} | ||
} | ||
hoistNonReactStatic(MultipleContexts, Component); | ||
hoistNonReactStatic(ComponentWithMultipleContexts, Component); | ||
return MultipleContexts; | ||
return ComponentWithMultipleContexts; | ||
}; | ||
@@ -48,5 +54,5 @@ } | ||
return renderProps => { | ||
return renderComponent => { | ||
let context = {}; | ||
let callbackWithContext = () => renderProps(context); | ||
let callbackWithContext = () => renderComponent(context); | ||
@@ -73,4 +79,5 @@ let consumerTree = namedContexts.reduce((componentTreeFactory, namedContext) => generateConsumer(namedContext, context, componentTreeFactory), callbackWithContext)(); | ||
exports.withMultipleContext = withMultipleContext; | ||
exports.withMultipleContextsFactory = withMultipleContextsFactory; | ||
exports.createNamedContext = createNamedContext; | ||
exports.createMultipleContexts = createMultipleContexts; | ||
exports.generateConsumer = generateConsumer; |
{ | ||
"name": "consume-multiple-contexts", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Utility for consuming multiple contexts with DRY", | ||
@@ -5,0 +5,0 @@ "main": "lib/consumeMultipleContexts.js", |
@@ -90,3 +90,3 @@ # consume-multiple-contexts | ||
const renderWithContext = createMultipleContexts( | ||
const withContext = createMultipleContexts( | ||
createNamedContext('theme', ThemeContext), | ||
@@ -100,3 +100,3 @@ createNamedContext('user', UserContext) | ||
function Content() { | ||
return renderWithContext(({ theme, user }) => ( | ||
return withContext(({ theme, user }) => ( | ||
<ProfilePage theme={theme} user={user} /> | ||
@@ -107,3 +107,3 @@ )); | ||
function Sidebar() { | ||
return renderWithContext(({ theme, user }) => ( | ||
return withContext(({ theme, user }) => ( | ||
<ProfileSidebar theme={theme} user={user} /> | ||
@@ -117,3 +117,3 @@ )); | ||
```javascript | ||
import { createNamedContext, withMultipleContext } from 'consume-multiple-contexts'; | ||
import { createNamedContext, withMultipleContextsFactory } from 'consume-multiple-contexts'; | ||
@@ -127,2 +127,3 @@ const ThemeContext = React.createContext('light'); | ||
]; | ||
const withContext = withMultipleContextsFactory(themeContext, userContext); | ||
@@ -132,5 +133,5 @@ . | ||
const Content = withMultipleContext(...multipleContexts)(ProfilePage); | ||
const Sidebar = withMultipleContext(...multipleContexts)(ProfileSidebar); | ||
const Content = withContext(ProfilePage); | ||
const Sidebar = withContext(ProfileSidebar); | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11382
114
132