Comparing version 0.0.15 to 0.0.16
@@ -45,6 +45,2 @@ declare type ShouldUpdateBoolean = boolean; | ||
$key: string; | ||
/** | ||
* Internal. Only called by `ProxyValue#toLens`. | ||
*/ | ||
[WRAP_IN_FUNC](): ProxyLens<A>; | ||
}; | ||
@@ -59,3 +55,2 @@ declare type ArrayProxyLens<A extends AnyArray> = BaseProxyLens<A> & { | ||
declare type ProxyLens<A> = A extends AnyArray ? ArrayProxyLens<A> : A extends AnyObject ? ObjectProxyLens<A> : A extends AnyPrimitive ? PrimitiveProxyLens<A> : never; | ||
declare const WRAP_IN_FUNC: unique symbol; | ||
@@ -71,6 +66,6 @@ declare type Listener = () => void; | ||
declare type Lens<A> = Omit<ProxyLens<A>, symbol>; | ||
declare const concave: <S>(initialState: S) => [Lens<S>, Store<S>]; | ||
declare const useConcave: <S>(initialState: S) => [Lens<S>, Store<S>]; | ||
declare type Lens<A> = ProxyLens<A>; | ||
declare const concave: <S>(initialState: S) => [ProxyLens<S>, Store<S>]; | ||
declare const useConcave: <S>(initialState: S) => [ProxyLens<S>, Store<S>]; | ||
export { Lens, Store, concave, useConcave }; |
@@ -127,4 +127,2 @@ var __create = Object.create; | ||
// src/proxy-lens.ts | ||
var PROXY_VALUE = Symbol(); | ||
var WRAP_IN_FUNC = Symbol(); | ||
var THROW_ON_COPY = Symbol(); | ||
@@ -146,74 +144,73 @@ var isProxyable = /* @__PURE__ */ __name((obj) => Array.isArray(obj) || isObject(obj), "isProxyable"); | ||
}, "createUseLensProxy"); | ||
var proxyValue = /* @__PURE__ */ __name((obj, lens) => { | ||
if (!isProxyable(obj)) { | ||
return obj; | ||
} | ||
if (Reflect.has(obj, PROXY_VALUE)) { | ||
return Reflect.get(obj, PROXY_VALUE); | ||
} | ||
let toJSON; | ||
const proxy = new Proxy(obj, { | ||
get(target, key) { | ||
if (key === "toJSON") { | ||
toJSON != null ? toJSON : toJSON = () => target; | ||
return toJSON; | ||
} | ||
if (key === "toLens") { | ||
return lens[WRAP_IN_FUNC]; | ||
} | ||
if (key === PROXY_VALUE) { | ||
return proxy; | ||
} | ||
const nextValue = target[key]; | ||
const nextLens = lens[key]; | ||
return proxyValue(nextValue, nextLens); | ||
}, | ||
ownKeys(target) { | ||
return Reflect.ownKeys(target).concat(["toLens", "toJSON"]); | ||
}, | ||
getOwnPropertyDescriptor(target, key) { | ||
let desc; | ||
if (key === "toLens" || key === "toJSON") { | ||
desc = { | ||
configurable: true, | ||
enumerable: true, | ||
writable: false | ||
}; | ||
} else { | ||
desc = Object.getOwnPropertyDescriptor(target, key); | ||
} | ||
if (desc === void 0) { | ||
return; | ||
} | ||
const value = proxy[key]; | ||
var proxyValueHandler = { | ||
get(target, key) { | ||
var _a, _b; | ||
if (key === "toJSON") { | ||
(_a = target.toJSON) != null ? _a : target.toJSON = () => target.data; | ||
return target.toJSON; | ||
} | ||
if (key === "toLens") { | ||
(_b = target.toLens) != null ? _b : target.toLens = () => target.lens; | ||
return target.toLens; | ||
} | ||
const nextData = target.data[key]; | ||
const nextLens = target.lens[key]; | ||
return proxyValue(nextData, nextLens); | ||
}, | ||
ownKeys(target) { | ||
return Reflect.ownKeys(target.data).concat(["toLens", "toJSON"]); | ||
}, | ||
getOwnPropertyDescriptor(target, key) { | ||
if (key === "toLens" || key === "toJSON") { | ||
return { | ||
writable: desc.writable, | ||
enumerable: desc.enumerable, | ||
configurable: desc.configurable, | ||
value | ||
configurable: true, | ||
enumerable: true, | ||
writable: false, | ||
value: target[key] | ||
}; | ||
}, | ||
preventExtensions() { | ||
return true; | ||
}, | ||
isExtensible() { | ||
return false; | ||
}, | ||
set() { | ||
throw new Error("Cannot set property on ProxyValue"); | ||
}, | ||
deleteProperty() { | ||
throw new Error("Cannot delete property on ProxyValue"); | ||
} | ||
}); | ||
Object.defineProperty(obj, PROXY_VALUE, { | ||
value: proxy, | ||
enumerable: false, | ||
writable: false, | ||
configurable: false | ||
}); | ||
return proxy; | ||
const desc = Object.getOwnPropertyDescriptor(target.data, key); | ||
if (desc === void 0) { | ||
return; | ||
} | ||
return { | ||
writable: desc.writable, | ||
enumerable: desc.enumerable, | ||
configurable: desc.configurable, | ||
value: target.data[key] | ||
}; | ||
}, | ||
has(target, key) { | ||
return key in target.data; | ||
}, | ||
getPrototypeOf() { | ||
return null; | ||
}, | ||
preventExtensions() { | ||
return true; | ||
}, | ||
isExtensible() { | ||
return false; | ||
}, | ||
set() { | ||
throw new Error("Cannot set property on ProxyValue"); | ||
}, | ||
deleteProperty() { | ||
throw new Error("Cannot delete property on ProxyValue"); | ||
} | ||
}; | ||
var valueCache = /* @__PURE__ */ new WeakMap(); | ||
var proxyValue = /* @__PURE__ */ __name((data, lens) => { | ||
if (!isProxyable(data)) { | ||
return data; | ||
} | ||
let cached = valueCache.get(data); | ||
if (!cached) { | ||
cached = new Proxy({ data, lens }, proxyValueHandler); | ||
valueCache.set(data, cached); | ||
} | ||
return cached; | ||
}, "proxyValue"); | ||
var proxyLens = /* @__PURE__ */ __name((createUseLensState, focus) => { | ||
const cache2 = {}; | ||
const keyCache = {}; | ||
let use; | ||
@@ -231,6 +228,2 @@ let toLens; | ||
} | ||
if (key === WRAP_IN_FUNC) { | ||
toLens != null ? toLens : toLens = () => proxy; | ||
return toLens; | ||
} | ||
if (key === "use") { | ||
@@ -240,8 +233,8 @@ use != null ? use : use = createUseLensProxy(createUseLensState, focus, proxy); | ||
} | ||
if (cache2[key] === void 0) { | ||
if (keyCache[key] === void 0) { | ||
const nextFocus = focusProp(focus, key); | ||
const nextProxy = proxyLens(createUseLensState, nextFocus); | ||
cache2[key] = nextProxy; | ||
keyCache[key] = nextProxy; | ||
} | ||
return cache2[key]; | ||
return keyCache[key]; | ||
}, | ||
@@ -287,3 +280,5 @@ ownKeys(_target) { | ||
}, "proxyLens"); | ||
var initProxyLens = /* @__PURE__ */ __name((createUseLensState) => proxyLens(createUseLensState, { lens: basicLens(), keyPath: [] }), "initProxyLens"); | ||
var initProxyLens = /* @__PURE__ */ __name((createUseLensState) => { | ||
return proxyLens(createUseLensState, { lens: basicLens(), keyPath: [] }); | ||
}, "initProxyLens"); | ||
@@ -290,0 +285,0 @@ // src/subscription-graph.ts |
{ | ||
"name": "concave", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"description": "A Lens-like interface for state management in React", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -47,3 +47,3 @@ # 🧐 Concave | ||
import { stateless } from "concave"; | ||
import type { State } from "./application-state"; | ||
import { State } from "./application-state"; | ||
@@ -56,3 +56,3 @@ export const [lens, LensProvider] = stateless<State>(); | ||
import type { State } from './application-state'; | ||
import { State } from './application-state'; | ||
import { Root } from './Root'; | ||
@@ -76,3 +76,3 @@ import { lens, LensProvider } from './LensProvider'; | ||
import { Lens } from "concave"; | ||
import type { State } from "./application-state"; | ||
import { State } from "./application-state"; | ||
import { Profile } from "./Profile"; | ||
@@ -79,0 +79,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105142
1039