New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

pullstate

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pullstate - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1-alpha.0

dist/useStoreStateOpt-types.d.ts

76

dist/index.es.js

@@ -26,36 +26,2 @@ import React,{useState,useRef,useEffect,useContext,useMemo}from'react';import produce$1 from'immer';const isEqual = require("fast-deep-equal");

return subState;
}let updateListenerOrd = 0;
function fastGet(obj, path) {
return path.reduce((cur = obj, key) => {
return cur[key];
}, undefined);
}
function getSubStateFromPaths(store, paths) {
const state = store.getRawState();
const resp = [];
for (const path of paths) {
resp.push(fastGet(state, path));
}
return resp;
}
function useStoreStateOpt(store, paths) {
const [subState, setSubState] = useState(() => getSubStateFromPaths(store, paths));
const updateRef = useRef({
shouldUpdate: true,
onStoreUpdate: null,
currentSubState: null,
ordKey: `_${updateListenerOrd++}`,
});
updateRef.current.currentSubState = subState;
if (updateRef.current.onStoreUpdate === null) {
updateRef.current.onStoreUpdate = function onStoreUpdateOpt() {
setSubState(getSubStateFromPaths(store, paths));
};
store._addUpdateListenerOpt(updateRef.current.onStoreUpdate, updateRef.current.ordKey, paths);
}
useEffect(() => () => {
updateRef.current.shouldUpdate = false;
store._removeUpdateListenerOpt(updateRef.current.ordKey);
}, []);
return subState;
}const isEqual$1 = require("fast-deep-equal");

@@ -249,3 +215,43 @@ const Immer = require("immer");

}
}function InjectStoreState({ store, on = s => s, children, }) {
}let updateListenerOrd = 0;
function fastGet(obj, path) {
return path.reduce((cur = obj, key) => {
return cur[key];
}, undefined);
}
function getSubStateFromPaths(store, paths) {
const state = store.getRawState();
const resp = [];
for (const path of paths) {
resp.push(fastGet(state, path));
}
return resp;
}
function useStoreStateOpt(store, paths) {
const [subState, setSubState] = useState(() => getSubStateFromPaths(store, paths));
const updateRef = useRef({
shouldUpdate: true,
onStoreUpdate: null,
currentSubState: null,
ordKey: `_${updateListenerOrd++}`,
});
updateRef.current.currentSubState = subState;
if (updateRef.current.onStoreUpdate === null) {
updateRef.current.onStoreUpdate = function onStoreUpdateOpt() {
setSubState(getSubStateFromPaths(store, paths));
};
store._addUpdateListenerOpt(updateRef.current.onStoreUpdate, updateRef.current.ordKey, paths);
}
useEffect(() => () => {
updateRef.current.shouldUpdate = false;
store._removeUpdateListenerOpt(updateRef.current.ordKey);
}, []);
return subState;
}
const PostSearchStore = new Store({
posts: [],
currentSearchText: "",
loadingPosts: false,
});
const [posts, text] = useStoreStateOpt(PostSearchStore, [["posts"], ["currentSearchText"]]);function InjectStoreState({ store, on = s => s, children, }) {
const state = useStoreState(store, on);

@@ -252,0 +258,0 @@ return children(state);

@@ -26,36 +26,2 @@ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});function _interopDefault(e){return(e&&(typeof e==='object')&&'default'in e)?e['default']:e}var React=require('react'),React__default=_interopDefault(React),produce$1=_interopDefault(require('immer'));const isEqual = require("fast-deep-equal");

return subState;
}let updateListenerOrd = 0;
function fastGet(obj, path) {
return path.reduce((cur = obj, key) => {
return cur[key];
}, undefined);
}
function getSubStateFromPaths(store, paths) {
const state = store.getRawState();
const resp = [];
for (const path of paths) {
resp.push(fastGet(state, path));
}
return resp;
}
function useStoreStateOpt(store, paths) {
const [subState, setSubState] = React.useState(() => getSubStateFromPaths(store, paths));
const updateRef = React.useRef({
shouldUpdate: true,
onStoreUpdate: null,
currentSubState: null,
ordKey: `_${updateListenerOrd++}`,
});
updateRef.current.currentSubState = subState;
if (updateRef.current.onStoreUpdate === null) {
updateRef.current.onStoreUpdate = function onStoreUpdateOpt() {
setSubState(getSubStateFromPaths(store, paths));
};
store._addUpdateListenerOpt(updateRef.current.onStoreUpdate, updateRef.current.ordKey, paths);
}
React.useEffect(() => () => {
updateRef.current.shouldUpdate = false;
store._removeUpdateListenerOpt(updateRef.current.ordKey);
}, []);
return subState;
}const isEqual$1 = require("fast-deep-equal");

@@ -249,3 +215,43 @@ const Immer = require("immer");

}
}function InjectStoreState({ store, on = s => s, children, }) {
}let updateListenerOrd = 0;
function fastGet(obj, path) {
return path.reduce((cur = obj, key) => {
return cur[key];
}, undefined);
}
function getSubStateFromPaths(store, paths) {
const state = store.getRawState();
const resp = [];
for (const path of paths) {
resp.push(fastGet(state, path));
}
return resp;
}
function useStoreStateOpt(store, paths) {
const [subState, setSubState] = React.useState(() => getSubStateFromPaths(store, paths));
const updateRef = React.useRef({
shouldUpdate: true,
onStoreUpdate: null,
currentSubState: null,
ordKey: `_${updateListenerOrd++}`,
});
updateRef.current.currentSubState = subState;
if (updateRef.current.onStoreUpdate === null) {
updateRef.current.onStoreUpdate = function onStoreUpdateOpt() {
setSubState(getSubStateFromPaths(store, paths));
};
store._addUpdateListenerOpt(updateRef.current.onStoreUpdate, updateRef.current.ordKey, paths);
}
React.useEffect(() => () => {
updateRef.current.shouldUpdate = false;
store._removeUpdateListenerOpt(updateRef.current.ordKey);
}, []);
return subState;
}
const PostSearchStore = new Store({
posts: [],
currentSearchText: "",
loadingPosts: false,
});
const [posts, text] = useStoreStateOpt(PostSearchStore, [["posts"], ["currentSearchText"]]);function InjectStoreState({ store, on = s => s, children, }) {
const state = useStoreState(store, on);

@@ -252,0 +258,0 @@ return children(state);

import React from "react";
import { Store } from "./Store";
import { TPath } from "./useStoreStateOpt";
export interface IPropsInjectStoreStateOpt<S = any, P extends TPath[] = TPath[]> {
import { TAllPathsParameter } from "./useStoreStateOpt-types";
export interface IPropsInjectStoreStateOpt<S = any, P extends TAllPathsParameter<S> = TAllPathsParameter<S>> {
store: Store<S>;

@@ -6,0 +6,0 @@ paths: P;

import { Patch } from "immer";
import { TPath } from "./useStoreStateOpt";
import { DeepKeyOfArray } from "./useStoreStateOpt-types";
export declare type TPullstateUpdateListener = () => void;

@@ -32,3 +32,3 @@ export interface IStoreInternalOptions<S> {

_addUpdateListener(listener: TPullstateUpdateListener): void;
_addUpdateListenerOpt(listener: TPullstateUpdateListener, ordKey: string, paths: TPath[]): void;
_addUpdateListenerOpt(listener: TPullstateUpdateListener, ordKey: string, paths: DeepKeyOfArray<S>[]): void;
_removeUpdateListener(listener: TPullstateUpdateListener): void;

@@ -35,0 +35,0 @@ _removeUpdateListenerOpt(ordKey: string): void;

import { Store } from "./Store";
export declare type TPath = (string | number | symbol)[];
declare function useStoreStateOpt<S = any>(store: Store<S>, paths: TPath[]): any[];
import { DeepTypeOfArray, TAllPathsParameter } from "./useStoreStateOpt-types";
declare function useStoreStateOpt<S, P extends TAllPathsParameter<S>>(store: Store<S>, paths: P): [DeepTypeOfArray<S, P[0]>] | [DeepTypeOfArray<S, P[0]>, DeepTypeOfArray<S, P[1]>] | [DeepTypeOfArray<S, P[0]>, DeepTypeOfArray<S, P[1]>, DeepTypeOfArray<S, P[2]>] | [DeepTypeOfArray<S, P[0]>, DeepTypeOfArray<S, P[1]>, DeepTypeOfArray<S, P[2]>, DeepTypeOfArray<S, P[3]>] | [DeepTypeOfArray<S, P[0]>, DeepTypeOfArray<S, P[1]>, DeepTypeOfArray<S, P[2]>, DeepTypeOfArray<S, P[3]>, DeepTypeOfArray<S, P[4]>] | [DeepTypeOfArray<S, P[0]>, DeepTypeOfArray<S, P[1]>, DeepTypeOfArray<S, P[2]>, DeepTypeOfArray<S, P[3]>, DeepTypeOfArray<S, P[4]>, DeepTypeOfArray<S, P[5]>] | [DeepTypeOfArray<S, P[0]>, DeepTypeOfArray<S, P[1]>, DeepTypeOfArray<S, P[2]>, DeepTypeOfArray<S, P[3]>, DeepTypeOfArray<S, P[4]>, DeepTypeOfArray<S, P[5]>, DeepTypeOfArray<S, P[6]>] | [DeepTypeOfArray<S, P[0]>, DeepTypeOfArray<S, P[1]>, DeepTypeOfArray<S, P[2]>, DeepTypeOfArray<S, P[3]>, DeepTypeOfArray<S, P[4]>, DeepTypeOfArray<S, P[5]>, DeepTypeOfArray<S, P[6]>, DeepTypeOfArray<S, P[7]>] | [DeepTypeOfArray<S, P[0]>, DeepTypeOfArray<S, P[1]>, DeepTypeOfArray<S, P[2]>, DeepTypeOfArray<S, P[3]>, DeepTypeOfArray<S, P[4]>, DeepTypeOfArray<S, P[5]>, DeepTypeOfArray<S, P[6]>, DeepTypeOfArray<S, P[7]>, DeepTypeOfArray<S, P[8]>] | [DeepTypeOfArray<S, P[0]>, DeepTypeOfArray<S, P[1]>, DeepTypeOfArray<S, P[2]>, DeepTypeOfArray<S, P[3]>, DeepTypeOfArray<S, P[4]>, DeepTypeOfArray<S, P[5]>, DeepTypeOfArray<S, P[6]>, DeepTypeOfArray<S, P[7]>, DeepTypeOfArray<S, P[8]>, DeepTypeOfArray<S, P[9]>] | [DeepTypeOfArray<S, P[0]>, DeepTypeOfArray<S, P[1]>, DeepTypeOfArray<S, P[2]>, DeepTypeOfArray<S, P[3]>, DeepTypeOfArray<S, P[4]>, DeepTypeOfArray<S, P[5]>, DeepTypeOfArray<S, P[6]>, DeepTypeOfArray<S, P[7]>, DeepTypeOfArray<S, P[8]>, DeepTypeOfArray<S, P[9]>, DeepTypeOfArray<S, P[10]>];
export { useStoreStateOpt };
export interface IPostSearchStore {
posts: any[];
currentSearchText: string;
loadingPosts: boolean;
}
export declare const PostSearchStore: Store<IPostSearchStore>;
{
"name": "pullstate",
"version": "1.2.0",
"version": "1.2.1-alpha.0",
"description": "Simple state stores using immer and React hooks",

@@ -59,5 +59,5 @@ "main": "dist/index.js",

"ts-node": "^8.2.0",
"typescript": "3.5.1",
"webpack": "^4.29.5",
"webpack-cli": "^3.2.3",
"typescript": "3.5.3",
"webpack": "^4.36.1",
"webpack-cli": "^3.3.6",
"js-beautify": "^1.9.0-beta5",

@@ -64,0 +64,0 @@ "react-testing-library": "^5.9.0"

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