Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@flexbase/store-react

Package Overview
Dependencies
Maintainers
4
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flexbase/store-react - npm Package Compare versions

Comparing version
1.0.6
to
2.0.0
+8
dist/core/use.store.d.ts
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'
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
};