Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

consume-multiple-contexts

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consume-multiple-contexts - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

24

es/consumeMultipleContexts.js

@@ -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);
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc