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

concave

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

concave - npm Package Compare versions

Comparing version 0.0.9-alpha4 to 0.0.9

14

dist/concave.es.js

@@ -100,4 +100,4 @@ var __defProp = Object.defineProperty;

const isProxyable = (obj) => Array.isArray(obj) || isObject(obj);
const createUse = (fixtures, lens) => {
const use = fixtures.createUse(fixtures.lens);
const createUseLens = (fixtures, lens) => {
const use = fixtures.createUseLens(fixtures.lens);
return function useLens(shouldUpdate) {

@@ -183,3 +183,3 @@ const [state, setState] = use(shouldUpdate);

if (key === "use") {
use != null ? use : use = createUse(fixtures, proxy);
use != null ? use : use = createUseLens(fixtures, proxy);
return use;

@@ -321,3 +321,3 @@ }

ExternalStoreContext.displayName = "Lens(ExternalStoreContext)";
const createUse2 = (lens2) => {
const createUseLens2 = (lens2) => {
return function useLensState(shouldUpdate) {

@@ -333,3 +333,3 @@ const store = React.useContext(ExternalStoreContext);

lens: basicLens(),
createUse: createUse2,
createUseLens: createUseLens2,
meta: { keyPath: [] }

@@ -358,3 +358,3 @@ });

const store = externalStore(initialState);
const createUse2 = (lens2) => {
const createUseLens2 = (lens2) => {
return function useLensState(shouldUpdate) {

@@ -366,3 +366,3 @@ return useSyncExternalStoreWithLens(store, lens2, shouldUpdate);

lens: basicLens(),
createUse: createUse2,
createUseLens: createUseLens2,
meta: { keyPath: [] }

@@ -369,0 +369,0 @@ });

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

var M=Object.defineProperty,W=Object.defineProperties;var Y=Object.getOwnPropertyDescriptors;var R=Object.getOwnPropertySymbols;var q=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var A=(c,l,i)=>l in c?M(c,l,{enumerable:!0,configurable:!0,writable:!0,value:i}):c[l]=i,S=(c,l)=>{for(var i in l||(l={}))q.call(l,i)&&A(c,i,l[i]);if(R)for(var i of R(l))z.call(l,i)&&A(c,i,l[i]);return c},x=(c,l)=>W(c,Y(l));(function(c,l){typeof exports=="object"&&typeof module!="undefined"?l(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],l):(c=typeof globalThis!="undefined"?globalThis:c||self,l(c.Concave={},c.React))})(this,function(c,l){"use strict";function i(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var f=i(l);const P=e=>Object.prototype.toString.call(e)==="[object Object]",_=e=>JSON.parse(JSON.stringify(e)),N=e=>P(e)?S({},e):Array.isArray(e)?[...e]:_(e),T=Object.freeze({get(e){return e},set(e,r){return r}}),m=()=>T,D=(e,r,t)=>({get(o){const n=e.get(o);return r(n)},set(o,n){const s=e.get(o);return e.set(o,t(s,n))}}),V=(e,r)=>D(e,t=>t[r],(t,o)=>{const n=N(t);return n[r]=o,n}),j=(e,r)=>t=>{const o=e.get(t),n=r(o);return Object.is(o,n)?t:e.set(t,r(o))},w=e=>{const r=new Set;let t=e;return{subscribe(o){return r.add(o),()=>r.delete(o)},getSnapshot(){return t},update(o){const n=o(t);Object.is(n,t)||(t=n,r.forEach(s=>s()))}}},I={isCalledInsideReactDevtools:()=>{var r;return(r=new Error().stack)==null?void 0:r.includes("react_devtools_backend")}},p=Symbol(),O=Symbol(),$=Symbol(),F=e=>Array.isArray(e)||P(e),H=(e,r)=>{const t=e.createUse(e.lens);return function(n){const[s,a]=t(n);return[E(s,r),a]}},E=(e,r)=>{if(!F(e))return e;if(Reflect.has(e,p))return Reflect.get(e,p);let t;const o=new Proxy(e,{get(n,s){if(s===p)return o;if(s==="toJSON")return t!=null||(t=()=>n),t;if(s==="toLens")return r[O];const a=n[s],u=r[s];return E(a,u)},ownKeys(n){return[...Reflect.ownKeys(n),"toLens","toJSON"]},getOwnPropertyDescriptor(n,s){return s===p?{enumerable:!1,value:o}:{configurable:!0,enumerable:!0,value:o[s]}},preventExtensions(){return!0},isExtensible(){return!1},set(){throw new Error("Cannot set property on ProxyValue")},deleteProperty(){throw new Error("Cannot delete property on ProxyValue")}});return Object.defineProperty(e,p,{value:o,enumerable:!1}),o},h=e=>{const r={};let t,o,n;const s=new Proxy({},{get(a,u){if(u!=="$$typeof"){if(u==="$key")return n!=null||(n=`Lens(${e.meta.keyPath.join(".")})`),n;if(u===O)return o!=null||(o=()=>s),o;if(u==="use")return t!=null||(t=H(e,s)),t;if(r[u]===void 0){const g=x(S({},e),{meta:x(S({},e.meta),{keyPath:[...e.meta.keyPath,u]}),lens:V(e.lens,u)}),y=h(g);r[u]=y}return r[u]}},ownKeys(a){return["$key","use",$]},getOwnPropertyDescriptor(a,u){if(u==="$key"||u==="use")return{configurable:!0,enumerable:!0,value:s[u]};if(I.isCalledInsideReactDevtools())return{configurable:!0,enumerable:!1,value:void 0};throw new Error("ProxyLens threw because you tried to access all property descriptors\u2014probably through `{ ...lens }` or `Object.assign({}, lens)`. Doing this will break the type safety offered by this library so it is forbidden. Sorry, buddy pal.")},getPrototypeOf(){return null},preventExtensions(){return!0},isExtensible(){return!1},set(){throw new Error("Cannot set property on ProxyLens")},deleteProperty(){throw new Error("Cannot delete property on ProxyLens")}});return s},v=e=>{if(typeof e=="boolean")return(r,t)=>e?r!==t:!1;if(typeof e=="function")return e;if(Array.isArray(e)){const r=Object.fromEntries(e.map(t=>[t,!0]));return v(r)}return(r,t)=>{let o=!1,n=!1,s,a;if(Array.isArray(r)?(o=!0,s=r):s=[r],Array.isArray(t)?(n=!0,a=t):a=[t],n!==o||s.length!==a.length)return!0;for(let u=0;u<s.length;u++){const g=s[u],y=a[u];for(const d in e)if(v(e[d])(g[d],y[d]))return!0}return!1}},b=Symbol(),L=(e,r,t=!0)=>{const o=f.default.useRef(b),n=f.default.useRef(t),s=f.default.useRef(b);n.current!==t&&(s.current=b),n.current=t;const a=()=>{const y=o.current,d=r.get(e.getSnapshot());return Object.is(y,d)?y:y===b||(s.current===b&&(s.current=v(t)),s.current(y,d))?d:y},u=f.default.useSyncExternalStore(e.subscribe,a,a),g=f.default.useCallback(y=>e.update(j(r,y)),[e]);return o.current=u,[u,g]},C=Symbol(),J=()=>{const e=f.default.createContext(C);e.displayName="Lens(ExternalStoreContext)";const r=n=>function(a){const u=f.default.useContext(e);if(u===C)throw new Error("Cannot call `lens.use()` in a component outside of <LensProvider />");return L(u,n,a)},t=h({lens:m(),createUse:r,meta:{keyPath:[]}}),o=n=>{const s=f.default.useRef();s.current||(s.current=w(n.value));const a=s.current;return f.default.useEffect(()=>{a.getSnapshot()!==n.value&&a.update(()=>n.value)},[n.value]),f.default.useEffect(()=>a.subscribe(()=>n.onChange(a.getSnapshot())),[n.onChange]),f.default.createElement(e.Provider,{value:a},n.children)};return o.displayName="Lens(Provider)",[t,o]},K=e=>{const r=w(e),t=s=>function(u){return L(r,s,u)};return[h({lens:m(),createUse:t,meta:{keyPath:[]}}),{get current(){return r.getSnapshot()},set current(s){r.update(()=>s)}}]};c.stateful=K,c.stateless=J,Object.defineProperty(c,"__esModule",{value:!0}),c[Symbol.toStringTag]="Module"});
var M=Object.defineProperty,W=Object.defineProperties;var Y=Object.getOwnPropertyDescriptors;var R=Object.getOwnPropertySymbols;var q=Object.prototype.hasOwnProperty,z=Object.prototype.propertyIsEnumerable;var A=(c,l,i)=>l in c?M(c,l,{enumerable:!0,configurable:!0,writable:!0,value:i}):c[l]=i,S=(c,l)=>{for(var i in l||(l={}))q.call(l,i)&&A(c,i,l[i]);if(R)for(var i of R(l))z.call(l,i)&&A(c,i,l[i]);return c},x=(c,l)=>W(c,Y(l));(function(c,l){typeof exports=="object"&&typeof module!="undefined"?l(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],l):(c=typeof globalThis!="undefined"?globalThis:c||self,l(c.Concave={},c.React))})(this,function(c,l){"use strict";function i(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var f=i(l);const P=e=>Object.prototype.toString.call(e)==="[object Object]",_=e=>JSON.parse(JSON.stringify(e)),N=e=>P(e)?S({},e):Array.isArray(e)?[...e]:_(e),T=Object.freeze({get(e){return e},set(e,r){return r}}),m=()=>T,D=(e,r,t)=>({get(o){const n=e.get(o);return r(n)},set(o,n){const s=e.get(o);return e.set(o,t(s,n))}}),V=(e,r)=>D(e,t=>t[r],(t,o)=>{const n=N(t);return n[r]=o,n}),j=(e,r)=>t=>{const o=e.get(t),n=r(o);return Object.is(o,n)?t:e.set(t,r(o))},w=e=>{const r=new Set;let t=e;return{subscribe(o){return r.add(o),()=>r.delete(o)},getSnapshot(){return t},update(o){const n=o(t);Object.is(n,t)||(t=n,r.forEach(s=>s()))}}},I={isCalledInsideReactDevtools:()=>{var r;return(r=new Error().stack)==null?void 0:r.includes("react_devtools_backend")}},p=Symbol(),O=Symbol(),$=Symbol(),F=e=>Array.isArray(e)||P(e),H=(e,r)=>{const t=e.createUseLens(e.lens);return function(n){const[s,a]=t(n);return[L(s,r),a]}},L=(e,r)=>{if(!F(e))return e;if(Reflect.has(e,p))return Reflect.get(e,p);let t;const o=new Proxy(e,{get(n,s){if(s===p)return o;if(s==="toJSON")return t!=null||(t=()=>n),t;if(s==="toLens")return r[O];const a=n[s],u=r[s];return L(a,u)},ownKeys(n){return[...Reflect.ownKeys(n),"toLens","toJSON"]},getOwnPropertyDescriptor(n,s){return s===p?{enumerable:!1,value:o}:{configurable:!0,enumerable:!0,value:o[s]}},preventExtensions(){return!0},isExtensible(){return!1},set(){throw new Error("Cannot set property on ProxyValue")},deleteProperty(){throw new Error("Cannot delete property on ProxyValue")}});return Object.defineProperty(e,p,{value:o,enumerable:!1}),o},h=e=>{const r={};let t,o,n;const s=new Proxy({},{get(a,u){if(u!=="$$typeof"){if(u==="$key")return n!=null||(n=`Lens(${e.meta.keyPath.join(".")})`),n;if(u===O)return o!=null||(o=()=>s),o;if(u==="use")return t!=null||(t=H(e,s)),t;if(r[u]===void 0){const g=x(S({},e),{meta:x(S({},e.meta),{keyPath:[...e.meta.keyPath,u]}),lens:V(e.lens,u)}),y=h(g);r[u]=y}return r[u]}},ownKeys(a){return["$key","use",$]},getOwnPropertyDescriptor(a,u){if(u==="$key"||u==="use")return{configurable:!0,enumerable:!0,value:s[u]};if(I.isCalledInsideReactDevtools())return{configurable:!0,enumerable:!1,value:void 0};throw new Error("ProxyLens threw because you tried to access all property descriptors\u2014probably through `{ ...lens }` or `Object.assign({}, lens)`. Doing this will break the type safety offered by this library so it is forbidden. Sorry, buddy pal.")},getPrototypeOf(){return null},preventExtensions(){return!0},isExtensible(){return!1},set(){throw new Error("Cannot set property on ProxyLens")},deleteProperty(){throw new Error("Cannot delete property on ProxyLens")}});return s},v=e=>{if(typeof e=="boolean")return(r,t)=>e?r!==t:!1;if(typeof e=="function")return e;if(Array.isArray(e)){const r=Object.fromEntries(e.map(t=>[t,!0]));return v(r)}return(r,t)=>{let o=!1,n=!1,s,a;if(Array.isArray(r)?(o=!0,s=r):s=[r],Array.isArray(t)?(n=!0,a=t):a=[t],n!==o||s.length!==a.length)return!0;for(let u=0;u<s.length;u++){const g=s[u],y=a[u];for(const d in e)if(v(e[d])(g[d],y[d]))return!0}return!1}},b=Symbol(),E=(e,r,t=!0)=>{const o=f.default.useRef(b),n=f.default.useRef(t),s=f.default.useRef(b);n.current!==t&&(s.current=b),n.current=t;const a=()=>{const y=o.current,d=r.get(e.getSnapshot());return Object.is(y,d)?y:y===b||(s.current===b&&(s.current=v(t)),s.current(y,d))?d:y},u=f.default.useSyncExternalStore(e.subscribe,a,a),g=f.default.useCallback(y=>e.update(j(r,y)),[e]);return o.current=u,[u,g]},C=Symbol(),J=()=>{const e=f.default.createContext(C);e.displayName="Lens(ExternalStoreContext)";const r=n=>function(a){const u=f.default.useContext(e);if(u===C)throw new Error("Cannot call `lens.use()` in a component outside of <LensProvider />");return E(u,n,a)},t=h({lens:m(),createUseLens:r,meta:{keyPath:[]}}),o=n=>{const s=f.default.useRef();s.current||(s.current=w(n.value));const a=s.current;return f.default.useEffect(()=>{a.getSnapshot()!==n.value&&a.update(()=>n.value)},[n.value]),f.default.useEffect(()=>a.subscribe(()=>n.onChange(a.getSnapshot())),[n.onChange]),f.default.createElement(e.Provider,{value:a},n.children)};return o.displayName="Lens(Provider)",[t,o]},K=e=>{const r=w(e),t=s=>function(u){return E(r,s,u)};return[h({lens:m(),createUseLens:t,meta:{keyPath:[]}}),{get current(){return r.getSnapshot()},set current(s){r.update(()=>s)}}]};c.stateful=K,c.stateless=J,Object.defineProperty(c,"__esModule",{value:!0}),c[Symbol.toStringTag]="Module"});
//# sourceMappingURL=concave.umd.js.map
import { BasicLens } from "./basic-lens";
import { ShouldUpdate } from "./should-update";
declare type Key = string | symbol;
declare type Key = string | number | symbol;
declare type AnyObject = {

@@ -12,8 +12,8 @@ [key: Key]: JSON;

declare type Update<A> = (updater: Updater<A>) => void;
declare type Use<A> = (shouldUpdate?: ShouldUpdate<A>) => readonly [A, Update<A>];
declare type UseProxy<A> = (shouldUpdate?: ShouldUpdate<A>) => readonly [ProxyValue<A>, Update<A>];
declare type CreateUse<S> = <A>(lens: BasicLens<S, A>) => Use<A>;
declare type UseLens<A> = (shouldUpdate?: ShouldUpdate<A>) => readonly [A, Update<A>];
declare type UseLensProxy<A> = (shouldUpdate?: ShouldUpdate<A>) => readonly [ProxyValue<A>, Update<A>];
declare type CreateUseLens<S> = <A>(lens: BasicLens<S, A>) => UseLens<A>;
declare type LensFixtures<S, A> = {
lens: BasicLens<S, A>;
createUse: CreateUse<S>;
createUseLens: CreateUseLens<S>;
meta: {

@@ -36,3 +36,3 @@ keyPath: Key[];

*/
use: UseProxy<A>;
use: UseLensProxy<A>;
/**

@@ -39,0 +39,0 @@ * A unique key for cases when you need a key. e.g. A React list.

{
"name": "concave",
"version": "0.0.9-alpha4",
"version": "0.0.9",
"description": "A Lens-like interface for state management in React",

@@ -5,0 +5,0 @@ "main": "dist/concave.umd.js",

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