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

use-context-selector

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-context-selector - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

4

CHANGELOG.md

@@ -5,2 +5,6 @@ # Change Log

## [1.1.3] - 2020-09-17
### Changed
- useIsoLayoutEffect for SSR
## [1.1.2] - 2020-07-02

@@ -7,0 +11,0 @@ ### Changed

2

dist/index.modern.js

@@ -1,2 +0,2 @@

import e from"react";const r="production"!==process.env.NODE_ENV?Symbol("CONTEXT_LISTENERS"):Symbol(),t=t=>{const o=e.createContext(t,()=>0);var c,n;return o[r]=new Set,o.Provider=(c=o.Provider,n=o[r],e.memo(({value:r,children:t})=>("production"!==process.env.NODE_ENV?e.useLayoutEffect(()=>{n.forEach(e=>{e(r)})}):n.forEach(e=>{e(r)}),e.createElement(c,{value:r},t)))),delete o.Consumer,o},o=(t,o)=>{const c=t[r];if("production"!==process.env.NODE_ENV&&!c)throw new Error("useContextSelector requires special context");const[,n]=e.useReducer(e=>e+1,0),u=e.useContext(t),s=o(u),E=e.useRef(null);return e.useLayoutEffect(()=>{E.current={f:o,v:u,s}}),e.useLayoutEffect(()=>{const e=e=>{try{if(E.current.v===e||Object.is(E.current.s,E.current.f(e)))return}catch(e){}n()};return c.add(e),()=>{c.delete(e)}},[c]),s},c=e=>o(e,e=>e);export{t as createContext,c as useContext,o as useContextSelector};
import e from"react";const r=Symbol(),t="undefined"==typeof window||/ServerSideRendering/.test(window.navigator&&window.navigator.userAgent)?e=>e():e.useLayoutEffect,n=n=>{const o=e.createContext(n,()=>0);var c,u;return o[r]=new Set,o.Provider=(c=o.Provider,u=o[r],e.memo(({value:r,children:n})=>("production"!==process.env.NODE_ENV?t(()=>{u.forEach(e=>{e(r)})}):u.forEach(e=>{e(r)}),e.createElement(c,{value:r},n)))),delete o.Consumer,o},o=(n,o)=>{const c=n[r];if("production"!==process.env.NODE_ENV&&!c)throw new Error("useContextSelector requires special context");const[,u]=e.useReducer(e=>e+1,0),s=e.useContext(n),i=o(s),d=e.useRef(null);return t(()=>{d.current={f:o,v:s,s:i}}),t(()=>{const e=e=>{try{if(d.current.v===e||Object.is(d.current.s,d.current.f(e)))return}catch(e){}u()};return c.add(e),()=>{c.delete(e)}},[c]),i},c=e=>o(e,e=>e);export{n as createContext,c as useContext,o as useContextSelector,t as useIsoLayoutEffect};
//# sourceMappingURL=index.modern.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).useContextSelector={},e.react)}(this,function(e,t){t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var n="production"!==process.env.NODE_ENV?Symbol("CONTEXT_LISTENERS"):Symbol(),r=function(e,r){var o=e[n];if("production"!==process.env.NODE_ENV&&!o)throw new Error("useContextSelector requires special context");var u=t.useReducer(function(e){return e+1},0)[1],c=t.useContext(e),f=r(c),i=t.useRef(null);return t.useLayoutEffect(function(){i.current={f:r,v:c,s:f}}),t.useLayoutEffect(function(){var e=function(e){try{if(i.current.v===e||Object.is(i.current.s,i.current.f(e)))return}catch(e){}u()};return o.add(e),function(){o.delete(e)}},[o]),f};e.createContext=function(e){var r,o,u=t.createContext(e,function(){return 0});return u[n]=new Set,u.Provider=(r=u.Provider,o=u[n],t.memo(function(e){var n=e.value,u=e.children;return"production"!==process.env.NODE_ENV?t.useLayoutEffect(function(){o.forEach(function(e){e(n)})}):o.forEach(function(e){e(n)}),t.createElement(r,{value:n},u)})),delete u.Consumer,u},e.useContext=function(e){return r(e,function(e){return e})},e.useContextSelector=r});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).useContextSelector={},e.react)}(this,function(e,t){t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t;var n=Symbol(),r="undefined"==typeof window||/ServerSideRendering/.test(window.navigator&&window.navigator.userAgent)?function(e){return e()}:t.useLayoutEffect,o=function(e,o){var u=e[n];if("production"!==process.env.NODE_ENV&&!u)throw new Error("useContextSelector requires special context");var c=t.useReducer(function(e){return e+1},0)[1],i=t.useContext(e),f=o(i),a=t.useRef(null);return r(function(){a.current={f:o,v:i,s:f}}),r(function(){var e=function(e){try{if(a.current.v===e||Object.is(a.current.s,a.current.f(e)))return}catch(e){}c()};return u.add(e),function(){u.delete(e)}},[u]),f};e.createContext=function(e){var o,u,c=t.createContext(e,function(){return 0});return c[n]=new Set,c.Provider=(o=c.Provider,u=c[n],t.memo(function(e){var n=e.value,c=e.children;return"production"!==process.env.NODE_ENV?r(function(){u.forEach(function(e){e(n)})}):u.forEach(function(e){e(n)}),t.createElement(o,{value:n},c)})),delete c.Consumer,c},e.useContext=function(e){return o(e,function(e){return e})},e.useContextSelector=o,e.useIsoLayoutEffect=r});
//# sourceMappingURL=index.umd.js.map
{
"name": "use-context-selector",
"description": "React useContextSelector hook in userland",
"version": "1.1.2",
"version": "1.1.3",
"author": "Daishi Kato",

@@ -37,28 +37,28 @@ "repository": {

"devDependencies": {
"@babel/cli": "^7.10.4",
"@babel/core": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"@babel/cli": "^7.10.5",
"@babel/core": "^7.11.0",
"@babel/preset-env": "^7.11.0",
"@babel/preset-react": "^7.10.4",
"@testing-library/react": "^10.4.3",
"@types/react": "^16.9.41",
"@testing-library/react": "^10.4.7",
"@types/react": "^16.9.44",
"@types/react-dom": "^16.9.8",
"@typescript-eslint/eslint-plugin": "^3.5.0",
"@typescript-eslint/parser": "^3.5.0",
"@typescript-eslint/eslint-plugin": "^3.7.1",
"@typescript-eslint/parser": "^3.7.1",
"babel-loader": "^8.1.0",
"documentation": "^13.0.2",
"eslint": "^7.3.1",
"eslint": "^7.6.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.5",
"eslint-plugin-react": "^7.20.5",
"eslint-plugin-react-hooks": "^4.0.8",
"html-webpack-plugin": "^4.3.0",
"jest": "^26.1.0",
"microbundle": "^0.12.2",
"jest": "^26.2.2",
"microbundle": "^0.12.3",
"npm-run-all": "^4.1.5",
"react": "experimental",
"react-dom": "experimental",
"ts-loader": "^7.0.5",
"typescript": "^3.9.6",
"webpack": "^4.43.0",
"ts-loader": "^8.0.2",
"typescript": "^3.9.7",
"webpack": "^4.44.1",
"webpack-cli": "^3.3.12",

@@ -65,0 +65,0 @@ "webpack-dev-server": "^3.11.0"

import React from 'react';
const CONTEXT_LISTENERS = (
process.env.NODE_ENV !== 'production' ? Symbol('CONTEXT_LISTENERS')
/* for production */ : Symbol()
);
const CONTEXT_LISTENERS = Symbol();
const isSSR = typeof window === 'undefined'
|| /ServerSideRendering/.test(window.navigator && window.navigator.userAgent);
export const useIsoLayoutEffect = isSSR
? (fn) => fn()
: React.useLayoutEffect;
const createProvider = (OrigProvider, listeners) => React.memo(({ value, children }) => {

@@ -13,3 +17,3 @@ if (process.env.NODE_ENV !== 'production') {

// eslint-disable-next-line react-hooks/rules-of-hooks
React.useLayoutEffect(() => {
useIsoLayoutEffect(() => {
listeners.forEach((listener) => {

@@ -72,3 +76,3 @@ listener(value);

const ref = React.useRef(null);
React.useLayoutEffect(() => {
useIsoLayoutEffect(() => {
ref.current = {

@@ -80,3 +84,3 @@ f: selector, // last selector "f"unction

});
React.useLayoutEffect(() => {
useIsoLayoutEffect(() => {
const callback = (nextValue) => {

@@ -83,0 +87,0 @@ try {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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