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

context-state

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

context-state - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

./dist/index.js

7

CHANGELOG.md

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

# [2.1.0](https://github.com/hemengke1997/context-state/compare/v2.0.0...v2.1.0) (2023-12-22)
# [2.2.0](https://github.com/hemengke1997/context-state/compare/v2.0.0...v2.2.0) (2024-02-29)

@@ -9,3 +9,8 @@

### Features
* tree-shaking ([0530aa9](https://github.com/hemengke1997/context-state/commit/0530aa97021e5e70e133a70542bef86de11af2fd))
# [2.0.0](https://github.com/hemengke1997/context-state/compare/v1.0.2...v2.0.0) (2023-02-06)

@@ -12,0 +17,0 @@

34

dist/index.d.ts

@@ -1,31 +0,3 @@

import * as react from 'react';
import { ReactNode, MutableRefObject } from 'react';
declare function shallowEqual(origin: any, next: any): boolean;
type EqualityFC<T = any> = (old: T, now: T) => boolean;
type SelectorFn<Value, Selected> = (value: Value) => Selected;
declare const CONTEXT_VALUE: unique symbol;
declare const EMPTY: unique symbol;
type Listener<Value> = (v: Value) => void;
interface ContextInnerValue<Value> {
v: MutableRefObject<Value>;
l: Set<Listener<Value>>;
}
interface ContextValue<Value> {
[CONTEXT_VALUE]: ContextInnerValue<Value>;
}
type UseHookType<InitialValue, Value> = (initialValue: InitialValue) => Value;
declare function createContainer<Value, InitialValue>(useHook: UseHookType<InitialValue, Value>): {
Provider: ({ value, children }: {
value?: InitialValue;
children: ReactNode;
}) => react.FunctionComponentElement<react.ProviderProps<typeof EMPTY | ContextValue<Value>>>;
Consumer: ({ children }: {
children: (value: Value) => ReactNode;
}) => ReactNode;
useSelector: <Selected>(selector: SelectorFn<Value, Selected>, equalityFn?: EqualityFC) => Selected;
usePicker: <Selected_1 extends keyof Value>(selected: Selected_1[], equalityFn?: EqualityFC) => Pick<Value, Selected_1>;
};
export { SelectorFn, createContainer, shallowEqual };
export { createContainer } from './createContainer.js';
export { shallowEqual } from './utils/shallowEqual.js';
import 'react';

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

import{createContext as e,createElement as r,useContext as t,useRef as n}from"react";function c(e,r){return!!Object.is(e,r)||!!(e&&"object"==typeof e&&r&&"object"==typeof r&&[...Object.keys(e),...Object.keys(r)].every((t=>e[t]===r[t]&&Object.prototype.hasOwnProperty.call(e,t)&&Object.prototype.hasOwnProperty.call(r,t))))}import{useEffect as o,useLayoutEffect as u}from"react";var i="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?u:o;import{useCallback as s,useEffect as a,useRef as f,useState as l}from"react";var d=()=>{const e=f(!1);return a((()=>(e.current=!1,()=>{e.current=!0})),[]),e};var p="[context-state]: Component must be wrapped with <Container.Provider> 👻",v=Symbol("CONTEXT_VALUE"),w=Symbol("EMPTY"),m=new Map,y="production"!==process.env.NODE_ENV;function b(o){const u=e(w),a=o.toString().slice(0,24);function f(e,r=c){const o=t(u);let f=o?.[v];if(o===w){if(!y)throw new Error(p);if(f=m.get(a)[v].v.current,!f)throw new Error(p)}const{v:{current:b},l:E}=f,[,O]=function(e){const r=d(),[t,n]=l(e);return[t,s((e=>{r.current||n(e)}),[])]}(0),h=e(b),j=n();return j.current={value:b,selected:h},i((()=>{function t(t){try{if(!j.current)return;if(j.current.value===t)return;const n=e(t);if(r(j.current.selected,n))return;O((e=>e+1))}catch(e){}}return E.add(t),()=>{E.delete(t)}}),[E]),h}return{Provider:({value:e,children:t})=>{const c=o(e),s=n(c),f=n();if(!f.current){const e=new Set;f.current={[v]:{v:s,l:e}}}return y&&m.set(a,f.current),i((()=>{s.current=c,f.current?.[v].l.forEach((e=>{e(c)}))}),[c]),r(u.Provider,{value:f.current},t)},Consumer:({children:e})=>e(f((e=>e))),useSelector:f,usePicker:function(e,r=c){return f((r=>function(e,r){const t={};return e?Object.assign(t,...r.map((r=>({[r]:e[r]})))):t}(r,e)),r)}}}export{b as createContainer,c as shallowEqual};
"use strict";var e=require("./createContainer.js"),r=require("./utils/index.js");Object.defineProperty(exports,"createContainer",{enumerable:!0,get:function(){return e.createContainer}}),Object.defineProperty(exports,"shallowEqual",{enumerable:!0,get:function(){return r.shallowEqual}});
{
"name": "context-state",
"version": "2.1.0",
"version": "2.2.0",
"description": "React state management library",
"type": "module",
"keywords": [

@@ -26,12 +25,21 @@ "react",

],
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
"import": {
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.mjs"
},
"module": {
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.js"
},
"default": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"sideEffects": false,
"peerDependencies": {

@@ -50,2 +58,3 @@ "react": ">=16.8.0"

"conventional-changelog-cli": "^2.2.2",
"esbuild-plugin-replace": "^1.4.0",
"eslint": "^8.52.0",

@@ -56,3 +65,3 @@ "jsdom": "^21.1.1",

"terser": "^5.24.0",
"tsup": "^7.2.0",
"tsup": "^8.0.2",
"typescript": "^5.0.2",

@@ -63,9 +72,9 @@ "vitest": "^0.29.7"

"dev": "tsup --watch",
"build": "tsup",
"build": "rm -rf dist && tsup",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"test": "vitest",
"lint": "eslint .",
"up": "pnpm update --i --L",
"up": "taze -I -w",
"bump": "bumpp package.json -c -p -t --all -x \"pnpm run changelog\""
}
}
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