@flexbase/store-react
Advanced tools
| import { Setter, Store } from '@flexbase/store'; | ||
| /** | ||
| * A hook that attaches a store to a react state | ||
| * Internally it uses `useState` and `useEffect` to create a subscription between the store and react state | ||
| * @param store The store to use | ||
| * @returns A value and function to update it | ||
| */ | ||
| export declare const useStore: <T>(store: Store<T>) => [T | undefined, Setter<T>]; |
| import { Setter, Store } from '@flexbase/store'; | ||
| /** | ||
| * A hook that attaches a store to a react state | ||
| * Internally it uses `useState` and `useLayoutEffect` to create a subscription between the store and react state | ||
| * @param store The store to use | ||
| * @returns A value and function to update it | ||
| */ | ||
| export declare const useStoreLayout: <T>(store: Store<T>) => [T | undefined, Setter<T>]; |
| export { useStore } from './core/use.store.js'; | ||
| export { useStoreLayout } from './core/use.store.layout.js'; |
| import { StorageManager as c } from "@flexbase/store"; | ||
| import { useState as i, useEffect as g, useLayoutEffect as b } from "react"; | ||
| const S = (t) => { | ||
| const e = c.lookupManager(t); | ||
| if (e === void 0) | ||
| throw Error(`Unable to find storage manager for ${t.key.toString()}`); | ||
| const r = e.getValue(t), [o, n] = i(r), a = e.getSetter(t); | ||
| return g(() => { | ||
| const s = e.subscribe(t, (u) => (n(u.value), Promise.resolve())); | ||
| return () => s.unsubscribe(); | ||
| }, [e, t]), [o, a]; | ||
| }, m = (t) => { | ||
| const e = c.lookupManager(t); | ||
| if (e === void 0) | ||
| throw Error(`Unable to find storage manager for ${t.key.toString()}`); | ||
| const r = e.getValue(t), [o, n] = i(r), a = e.getSetter(t); | ||
| return b(() => { | ||
| const s = e.subscribe(t, (u) => (n(u.value), Promise.resolve())); | ||
| return () => s.unsubscribe(); | ||
| }, [e, t]), [o, a]; | ||
| }; | ||
| export { | ||
| S as useStore, | ||
| m as useStoreLayout | ||
| }; |
+5
-8
| { | ||
| "name": "@flexbase/store-react", | ||
| "version": "1.0.6", | ||
| "version": "2.0.0", | ||
| "description": "React extensions for @flexbase/store", | ||
| "main": "./index.cjs.js", | ||
| "module": "./index.es.js", | ||
| "exports": { | ||
| ".": { "import": "./index.es.js", "require": "./index.cjs.js" } | ||
| }, | ||
| "main": "./dist/index.js", | ||
| "exports": "./dist/index.js", | ||
| "homepage": "https://github.com/flexbase-eng/store-react#readme", | ||
@@ -23,4 +20,4 @@ "repository": { | ||
| "dependencies": { | ||
| "@flexbase/observable-subject": "^1.4.3", | ||
| "@flexbase/store": "^1.2.4" | ||
| "@flexbase/observable-subject": "^2.0.0", | ||
| "@flexbase/store": "^2.0.1" | ||
| }, | ||
@@ -27,0 +24,0 @@ "peerDependencies": { "react": "^18.1.0" }, |
| import { Setter, Store } from '@flexbase/store'; | ||
| /** | ||
| * A hook that attaches a store to a react state | ||
| * Internally it uses `useState` and `useEffect` to create a subscription between the store and react state | ||
| * @param store The store to use | ||
| * @returns A value and function to update it | ||
| */ | ||
| export declare const useStore: <T>(store: Store<T>) => [T | undefined, Setter<T>]; |
| import { Setter, Store } from '@flexbase/store'; | ||
| /** | ||
| * A hook that attaches a store to a react state | ||
| * Internally it uses `useState` and `useLayoutEffect` to create a subscription between the store and react state | ||
| * @param store The store to use | ||
| * @returns A value and function to update it | ||
| */ | ||
| export declare const useStoreLayout: <T>(store: Store<T>) => [T | undefined, Setter<T>]; |
| "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@flexbase/store"),r=require("react"),g=e=>{const t=i.StorageManager.lookupManager(e);if(t===void 0)throw Error(`Unable to find storage manager for ${e.key.toString()}`);const o=t.getValue(e),[a,n]=r.useState(o),u=t.getSetter(e);return r.useEffect(()=>{const s=t.subscribe(e,c=>(n(c.value),Promise.resolve()));return()=>s.unsubscribe()},[t,e]),[a,u]},S=e=>{const t=i.StorageManager.lookupManager(e);if(t===void 0)throw Error(`Unable to find storage manager for ${e.key.toString()}`);const o=t.getValue(e),[a,n]=r.useState(o),u=t.getSetter(e);return r.useLayoutEffect(()=>{const s=t.subscribe(e,c=>(n(c.value),Promise.resolve()));return()=>s.unsubscribe()},[t,e]),[a,u]};exports.useStore=g;exports.useStoreLayout=S; |
| export { useStore } from './core/use.store'; | ||
| export { useStoreLayout } from './core/use.store.layout'; |
| export * from './index' |
-25
| import { StorageManager as c } from "@flexbase/store"; | ||
| import { useState as i, useEffect as g, useLayoutEffect as b } from "react"; | ||
| const S = (t) => { | ||
| const e = c.lookupManager(t); | ||
| if (e === void 0) | ||
| throw Error(`Unable to find storage manager for ${t.key.toString()}`); | ||
| const r = e.getValue(t), [o, n] = i(r), a = e.getSetter(t); | ||
| return g(() => { | ||
| const s = e.subscribe(t, (u) => (n(u.value), Promise.resolve())); | ||
| return () => s.unsubscribe(); | ||
| }, [e, t]), [o, a]; | ||
| }, m = (t) => { | ||
| const e = c.lookupManager(t); | ||
| if (e === void 0) | ||
| throw Error(`Unable to find storage manager for ${t.key.toString()}`); | ||
| const r = e.getValue(t), [o, n] = i(r), a = e.getSetter(t); | ||
| return b(() => { | ||
| const s = e.subscribe(t, (u) => (n(u.value), Promise.resolve())); | ||
| return () => s.unsubscribe(); | ||
| }, [e, t]), [o, a]; | ||
| }; | ||
| export { | ||
| S as useStore, | ||
| m as useStoreLayout | ||
| }; |
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
0
-100%0
-100%5044
-15.33%7
-22.22%43
-10.42%+ Added
+ Added
+ Added
- Removed
- Removed
Updated