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.4.1 to 1.5.0

10

Changelog.md

@@ -0,1 +1,11 @@

## 1.5.0
Allow selecting a subset of passed arguments too an async function to create the fingerprint. This is purely for performance reasons when you want to pass in large data sets.
Pass an extra option when creating the Async Action: `subsetKey: (args) => subset` - basically it takes the arguments given, and allows you to return subset of those arguments which pullstate will use internally to create cache fingerprints.
### 1.4.1
* Added `immer` as direct dependency. Was `peerDependency` before - but this is not sufficient when requiring certain versions of `immer` for new functionality. Also `peerDependency` gives errors to users whose projects don't use `immer` outside of `pullstate`.
## 1.4.0

@@ -2,0 +12,0 @@

1

dist/async-types.d.ts

@@ -132,3 +132,4 @@ import { IPullstateAllStores } from "./PullstateCore";

postActionHook?: TPullstateAsyncPostActionHook<A, R, T, S>;
subsetKey?: (args: A) => any;
}
export {};

2

dist/async.d.ts

@@ -7,2 +7,2 @@ import { IPullstateAllStores } from "./PullstateCore";

export declare function errorResult<R = any, T extends string = string>(tags?: (EAsyncEndTags | T)[], message?: string): IAsyncActionResultNegative<T>;
export declare function createAsyncAction<A = any, R = any, T extends string = string, S extends IPullstateAllStores = IPullstateAllStores>(action: TPullstateAsyncAction<A, R, T, S>, { clientStores, shortCircuitHook, cacheBreakHook, postActionHook, }?: ICreateAsyncActionOptions<A, R, T, S>): IOCreateAsyncActionOutput<A, R, T>;
export declare function createAsyncAction<A = any, R = any, T extends string = string, S extends IPullstateAllStores = IPullstateAllStores>(action: TPullstateAsyncAction<A, R, T, S>, { clientStores, shortCircuitHook, cacheBreakHook, postActionHook, subsetKey, }?: ICreateAsyncActionOptions<A, R, T, S>): IOCreateAsyncActionOutput<A, R, T>;

@@ -8,4 +8,4 @@ import { useStoreState } from "./useStoreState";

import { EAsyncActionInjectType, InjectAsyncAction, TInjectAsyncActionProps } from "./InjectAsyncAction";
import { EAsyncEndTags, TPullstateAsyncAction } from "./async-types";
import { EAsyncEndTags, TPullstateAsyncAction, TAsyncActionResult } from "./async-types";
import { InjectStoreStateOpt } from "./InjectStoreStateOpt";
export { useStoreState, useStoreStateOpt, update, Store, InjectStoreState, InjectStoreStateOpt, PullstateProvider, useStores, createPullstateCore, createAsyncAction, successResult, errorResult, EAsyncEndTags, IPullstateInstanceConsumable, InjectAsyncAction, EAsyncActionInjectType, TInjectAsyncActionProps, TPullstateAsyncAction, };
export { useStoreState, useStoreStateOpt, update, Store, InjectStoreState, InjectStoreStateOpt, PullstateProvider, useStores, createPullstateCore, createAsyncAction, successResult, errorResult, EAsyncEndTags, IPullstateInstanceConsumable, InjectAsyncAction, EAsyncActionInjectType, TInjectAsyncActionProps, TPullstateAsyncAction, TAsyncActionResult, };

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

}
function createKey(ordinal, args) {
return `${ordinal}-${keyFromObject(args)}`;
}
function notifyListeners(key) {

@@ -385,5 +382,11 @@ if (clientAsyncCache.listeners.hasOwnProperty(key)) {

}
function createAsyncAction(action, { clientStores = {}, shortCircuitHook, cacheBreakHook, postActionHook, } = {}) {
function createAsyncAction(action, { clientStores = {}, shortCircuitHook, cacheBreakHook, postActionHook, subsetKey, } = {}) {
const ordinal = asyncCreationOrdinal++;
const onServer = typeof window === "undefined";
function _createKey(keyOrdinal, args) {
if (subsetKey !== undefined) {
return `${keyOrdinal}-${keyFromObject(subsetKey(args))}`;
}
return `${keyOrdinal}-${keyFromObject(args)}`;
}
let cacheBreakWatcher = {};

@@ -511,3 +514,5 @@ let watchIdOrd = 0;

const useWatch = (args = {}, { initiate = false, ssr = true, postActionEnabled = false, cacheBreakEnabled = false, } = {}) => {
const key = createKey(ordinal, args);
const responseRef = useRef(null);
const prevKeyRef = useRef(null);
const key = _createKey(ordinal, args);
let watchId = useRef(null);

@@ -517,3 +522,2 @@ if (watchId.current === null) {

}
const prevKeyRef = useRef(null);
if (!shouldUpdate.hasOwnProperty(key)) {

@@ -551,3 +555,2 @@ shouldUpdate[key] = {

}
const responseRef = useRef(null);
const [_, setWatchUpdate] = useState(0);

@@ -569,3 +572,3 @@ if (prevKeyRef.current !== key) {

const run = async (args = {}, { treatAsUpdate = false, ignoreShortCircuit = false, respectCache = false, _asyncCache = clientAsyncCache, _stores = clientStores, } = {}) => {
const key = createKey(ordinal, args);
const key = _createKey(ordinal, args);
if (_asyncCache.results.hasOwnProperty(key) && respectCache) {

@@ -657,3 +660,3 @@ if (cacheBreakHook !== undefined &&

const clearCache = (args = {}) => {
const key = createKey(ordinal, args);
const key = _createKey(ordinal, args);
clearActionCache(key);

@@ -677,3 +680,3 @@ };

const setCached = (args, result, { notify = true } = {}) => {
const key = createKey(ordinal, args);
const key = _createKey(ordinal, args);
const cache = onServer

@@ -688,3 +691,3 @@ ? useContext(PullstateContext)._asyncCache

const updateCached = (args, updater, { notify = true, resetTimeCached = true } = {}) => {
const key = createKey(ordinal, args);
const key = _createKey(ordinal, args);
const cache = onServer

@@ -713,3 +716,3 @@ ? useContext(PullstateContext)._asyncCache

const getCached = (args = {}, { checkCacheBreak = false } = {}) => {
const key = createKey(ordinal, args);
const key = _createKey(ordinal, args);
let cacheBreakable = false;

@@ -839,8 +842,4 @@ const cache = onServer

createAsyncAction(action, options = {}) {
return createAsyncAction(action, {
clientStores: this.originStores,
shortCircuitHook: options.shortCircuitHook,
cacheBreakHook: options.cacheBreakHook,
postActionHook: options.postActionHook,
});
options.clientStores = this.originStores;
return createAsyncAction(action, options);
}

@@ -847,0 +846,0 @@ }

@@ -341,5 +341,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");

}
function createKey(ordinal, args) {
return `${ordinal}-${keyFromObject(args)}`;
}
function notifyListeners(key) {

@@ -384,5 +381,11 @@ if (clientAsyncCache.listeners.hasOwnProperty(key)) {

}
function createAsyncAction(action, { clientStores = {}, shortCircuitHook, cacheBreakHook, postActionHook, } = {}) {
function createAsyncAction(action, { clientStores = {}, shortCircuitHook, cacheBreakHook, postActionHook, subsetKey, } = {}) {
const ordinal = asyncCreationOrdinal++;
const onServer = typeof window === "undefined";
function _createKey(keyOrdinal, args) {
if (subsetKey !== undefined) {
return `${keyOrdinal}-${keyFromObject(subsetKey(args))}`;
}
return `${keyOrdinal}-${keyFromObject(args)}`;
}
let cacheBreakWatcher = {};

@@ -510,3 +513,5 @@ let watchIdOrd = 0;

const useWatch = (args = {}, { initiate = false, ssr = true, postActionEnabled = false, cacheBreakEnabled = false, } = {}) => {
const key = createKey(ordinal, args);
const responseRef = React.useRef(null);
const prevKeyRef = React.useRef(null);
const key = _createKey(ordinal, args);
let watchId = React.useRef(null);

@@ -516,3 +521,2 @@ if (watchId.current === null) {

}
const prevKeyRef = React.useRef(null);
if (!shouldUpdate.hasOwnProperty(key)) {

@@ -550,3 +554,2 @@ shouldUpdate[key] = {

}
const responseRef = React.useRef(null);
const [_, setWatchUpdate] = React.useState(0);

@@ -568,3 +571,3 @@ if (prevKeyRef.current !== key) {

const run = async (args = {}, { treatAsUpdate = false, ignoreShortCircuit = false, respectCache = false, _asyncCache = clientAsyncCache, _stores = clientStores, } = {}) => {
const key = createKey(ordinal, args);
const key = _createKey(ordinal, args);
if (_asyncCache.results.hasOwnProperty(key) && respectCache) {

@@ -656,3 +659,3 @@ if (cacheBreakHook !== undefined &&

const clearCache = (args = {}) => {
const key = createKey(ordinal, args);
const key = _createKey(ordinal, args);
clearActionCache(key);

@@ -676,3 +679,3 @@ };

const setCached = (args, result, { notify = true } = {}) => {
const key = createKey(ordinal, args);
const key = _createKey(ordinal, args);
const cache = onServer

@@ -687,3 +690,3 @@ ? React.useContext(PullstateContext)._asyncCache

const updateCached = (args, updater, { notify = true, resetTimeCached = true } = {}) => {
const key = createKey(ordinal, args);
const key = _createKey(ordinal, args);
const cache = onServer

@@ -712,3 +715,3 @@ ? React.useContext(PullstateContext)._asyncCache

const getCached = (args = {}, { checkCacheBreak = false } = {}) => {
const key = createKey(ordinal, args);
const key = _createKey(ordinal, args);
let cacheBreakable = false;

@@ -838,8 +841,4 @@ const cache = onServer

createAsyncAction(action, options = {}) {
return createAsyncAction(action, {
clientStores: this.originStores,
shortCircuitHook: options.shortCircuitHook,
cacheBreakHook: options.cacheBreakHook,
postActionHook: options.postActionHook,
});
options.clientStores = this.originStores;
return createAsyncAction(action, options);
}

@@ -846,0 +845,0 @@ }

import React from "react";
import { Store } from "./Store";
import { IAsyncActionRunOptions, ICreateAsyncActionOptions, IOCreateAsyncActionOutput, IPullstateAsyncActionOrdState, IPullstateAsyncCache, IPullstateAsyncResultState, TPullstateAsyncAction, TPullstateAsyncRunResponse } from "./async-types";
declare type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
export interface IPullstateAllStores {

@@ -21,3 +20,3 @@ [storeName: string]: Store<any>;

useStores(): S;
createAsyncAction<A = any, R = any, T extends string = string>(action: TPullstateAsyncAction<A, R, T, S>, options?: Omit<ICreateAsyncActionOptions<A, R, T, S>, "clientStores">): IOCreateAsyncActionOutput<A, R, T>;
createAsyncAction<A = any, R = any, T extends string = string>(action: TPullstateAsyncAction<A, R, T, S>, options?: ICreateAsyncActionOptions<A, R, T, S>): IOCreateAsyncActionOutput<A, R, T>;
}

@@ -24,0 +23,0 @@ interface IPullstateSnapshot {

{
"name": "pullstate",
"version": "1.4.1",
"version": "1.5.0",
"description": "Simple state stores using immer and React hooks",

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

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