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.5.1 to 1.6.0

9

Changelog.md

@@ -0,1 +1,10 @@

## 1.6.0
Added the ability to hold onto previously resolved action results (if they were successful) until the new action resolves, when using a `useWatch()` or `useBeckon()`:
* Pass `holdPrevious: true` as an option to either `useWatch()` or `useBeckon()` to enable this.
* When a new action is running on top of an old result, the returned value from your action hooks will now have `started = true`, `finished = true`, `result = sameResult` and a final value to check called `updating = true`:
* `[true, true, result, true]` (for `useWatch()`)
* `[true, result, true]` for (`useBeckon()`)
### 1.5.1

@@ -2,0 +11,0 @@

1

dist/async-types.d.ts

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

cacheBreakEnabled?: boolean;
holdPrevious?: boolean;
}

@@ -61,0 +62,0 @@ export interface IAsyncActionWatchOptions extends IAsyncActionBeckonOptions {

20

dist/index.es.js

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

}
function checkKeyAndReturnResponse(key, cache, initiate, ssr, args, stores, fromListener = false, postActionEnabled = true, cacheBreakEnabled = true) {
function checkKeyAndReturnResponse(key, cache, initiate, ssr, args, stores, fromListener = false, postActionEnabled = true, cacheBreakEnabled = true, holdingResult = undefined) {
if (cache.results.hasOwnProperty(key)) {

@@ -485,2 +485,7 @@ const cacheBreakLoop = cacheBreakWatcher.hasOwnProperty(key) && cacheBreakWatcher[key] > 2;

else {
if (holdingResult) {
const response = [...holdingResult];
response[3] = true;
return response;
}
return [

@@ -500,2 +505,7 @@ false,

}
if (holdingResult) {
const response = [...holdingResult];
response[3] = true;
return response;
}
return [

@@ -514,3 +524,3 @@ true,

}
const useWatch = (args = {}, { initiate = false, ssr = true, postActionEnabled = false, cacheBreakEnabled = false, } = {}) => {
const useWatch = (args = {}, { initiate = false, ssr = true, postActionEnabled = false, cacheBreakEnabled = false, holdPrevious = false, } = {}) => {
const responseRef = useRef();

@@ -562,8 +572,8 @@ const prevKeyRef = useRef();

prevKeyRef.current = key;
responseRef.current = checkKeyAndReturnResponse(key, cache, initiate, ssr, args, stores, false, postActionEnabled, cacheBreakEnabled);
responseRef.current = checkKeyAndReturnResponse(key, cache, initiate, ssr, args, stores, false, postActionEnabled, cacheBreakEnabled, (holdPrevious && responseRef.current && responseRef.current[1]) ? responseRef.current : undefined);
}
return responseRef.current;
};
const useBeckon = (args = {}, { ssr = true, postActionEnabled = true, cacheBreakEnabled = true } = {}) => {
const result = useWatch(args, { initiate: true, ssr, postActionEnabled, cacheBreakEnabled });
const useBeckon = (args = {}, { ssr = true, postActionEnabled = true, cacheBreakEnabled = true, holdPrevious = false } = {}) => {
const result = useWatch(args, { initiate: true, ssr, postActionEnabled, cacheBreakEnabled, holdPrevious });
return [result[1], result[2], result[3]];

@@ -570,0 +580,0 @@ };

@@ -397,3 +397,3 @@ '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 checkKeyAndReturnResponse(key, cache, initiate, ssr, args, stores, fromListener = false, postActionEnabled = true, cacheBreakEnabled = true) {
function checkKeyAndReturnResponse(key, cache, initiate, ssr, args, stores, fromListener = false, postActionEnabled = true, cacheBreakEnabled = true, holdingResult = undefined) {
if (cache.results.hasOwnProperty(key)) {

@@ -484,2 +484,7 @@ const cacheBreakLoop = cacheBreakWatcher.hasOwnProperty(key) && cacheBreakWatcher[key] > 2;

else {
if (holdingResult) {
const response = [...holdingResult];
response[3] = true;
return response;
}
return [

@@ -499,2 +504,7 @@ false,

}
if (holdingResult) {
const response = [...holdingResult];
response[3] = true;
return response;
}
return [

@@ -513,3 +523,3 @@ true,

}
const useWatch = (args = {}, { initiate = false, ssr = true, postActionEnabled = false, cacheBreakEnabled = false, } = {}) => {
const useWatch = (args = {}, { initiate = false, ssr = true, postActionEnabled = false, cacheBreakEnabled = false, holdPrevious = false, } = {}) => {
const responseRef = React.useRef();

@@ -561,8 +571,8 @@ const prevKeyRef = React.useRef();

prevKeyRef.current = key;
responseRef.current = checkKeyAndReturnResponse(key, cache, initiate, ssr, args, stores, false, postActionEnabled, cacheBreakEnabled);
responseRef.current = checkKeyAndReturnResponse(key, cache, initiate, ssr, args, stores, false, postActionEnabled, cacheBreakEnabled, (holdPrevious && responseRef.current && responseRef.current[1]) ? responseRef.current : undefined);
}
return responseRef.current;
};
const useBeckon = (args = {}, { ssr = true, postActionEnabled = true, cacheBreakEnabled = true } = {}) => {
const result = useWatch(args, { initiate: true, ssr, postActionEnabled, cacheBreakEnabled });
const useBeckon = (args = {}, { ssr = true, postActionEnabled = true, cacheBreakEnabled = true, holdPrevious = false } = {}) => {
const result = useWatch(args, { initiate: true, ssr, postActionEnabled, cacheBreakEnabled, holdPrevious });
return [result[1], result[2], result[3]];

@@ -569,0 +579,0 @@ };

{
"name": "pullstate",
"version": "1.5.1",
"version": "1.6.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