Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nanostores/query

Package Overview
Dependencies
Maintainers
4
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nanostores/query - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

3

dist/main.d.ts

@@ -34,4 +34,5 @@ import { MapStore, ReadableAtom } from "nanostores";

}) => Promise<Result>;
declare type MutateCb<Data> = Data extends void ? () => Promise<unknown> : (data: Data) => Promise<unknown>;
export declare type MutatorStore<Data = void, Result = unknown, E = Error> = MapStore<{
mutate: (data: Data) => Promise<Result>;
mutate: MutateCb<Data>;
data?: Result;

@@ -38,0 +39,0 @@ loading?: boolean;

@@ -168,38 +168,40 @@ import { map, onStart, onStop, atom } from "nanostores";

function createMutatorStore(mutator) {
const mutate = async (data) => {
var _a, _b;
const newMutator = (_a = rewrittenSettings.fetcher) != null ? _a : mutator;
const keysToInvalidate = [];
try {
store.set({
error: void 0,
loading: true,
data: void 0,
mutate: store.get().mutate
});
const result = await newMutator({
data,
invalidate: (key) => {
keysToInvalidate.push(key);
},
getCacheUpdater: (key, shouldInvalidate = true) => [
(newVal) => {
mutateCache(key, newVal);
if (shouldInvalidate) {
keysToInvalidate.push(key);
}
},
cache.get(key)
]
});
store.setKey("data", result);
return result;
} catch (error) {
(_b = globalSettings == null ? void 0 : globalSettings.onError) == null ? void 0 : _b.call(globalSettings, error);
store.setKey("error", error);
} finally {
store.setKey("loading", false);
invalidateKeys(keysToInvalidate);
}
};
const store = map({
mutate: async (data) => {
var _a, _b;
const newMutator = (_a = rewrittenSettings.fetcher) != null ? _a : mutator;
const keysToInvalidate = [];
try {
store.set({
error: void 0,
loading: true,
data: void 0,
mutate: store.get().mutate
});
const result = await newMutator({
data,
invalidate: (key) => {
keysToInvalidate.push(key);
},
getCacheUpdater: (key, shouldInvalidate = true) => [
(newVal) => {
mutateCache(key, newVal);
if (shouldInvalidate) {
keysToInvalidate.push(key);
}
},
cache.get(key)
]
});
store.setKey("data", result);
} catch (error) {
(_b = globalSettings == null ? void 0 : globalSettings.onError) == null ? void 0 : _b.call(globalSettings, error);
store.setKey("error", error);
} finally {
store.setKey("loading", false);
invalidateKeys(keysToInvalidate);
}
},
mutate,
loading: false

@@ -206,0 +208,0 @@ });

{
"name": "@nanostores/query",
"version": "0.0.1",
"version": "0.0.2",
"description": "Tiny remote data fetching library for Nano Stores",

@@ -5,0 +5,0 @@ "scripts": {

Sorry, the diff of this file is not supported yet

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