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.2.0 to 1.2.1

4

CHANGELOG.md

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

## [1.2.1] - 2020-10-01
### Added
- Type definition for useContextUpdate
## [1.2.0] - 2020-10-01

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

2

dist/index.modern.js

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

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

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

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

@@ -6,0 +6,0 @@ "repository": {

@@ -14,3 +14,7 @@ import { Context, FC } from 'react';

export const useContextUpdate: <T>(
context: Context<T>,
) => (thunk: () => void) => void;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const BridgeProvider: FC<{ context: Context<any>; value: any }>;

@@ -37,3 +37,3 @@ import React from 'react';

listeners.current.forEach((listener) => listener(versionRef.current));
return thunk();
thunk();
});

@@ -40,0 +40,0 @@ }, []);

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