floppy-disk 2.15.1 → 2.16.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/{utils/fetcher.js → fetcher.js} +1 -1
- package/esm/index.d.ts +8 -4
- package/esm/index.js +8 -4
- package/esm/react/create-mutation.d.ts +1 -1
- package/esm/react/create-store.d.ts +1 -1
- package/esm/react/create-store.js +1 -1
- package/esm/react/create-stores.d.ts +2 -1
- package/esm/react/create-stores.js +28 -2
- package/esm/{vanilla.d.ts → store.d.ts} +1 -1
- package/esm/{utils/index.d.ts → utils.d.ts} +19 -3
- package/esm/{utils/index.js → utils.js} +18 -2
- package/lib/{utils/fetcher.js → fetcher.js} +6 -6
- package/lib/index.d.ts +8 -4
- package/lib/index.js +8 -6
- package/lib/react/create-mutation.d.ts +1 -1
- package/lib/react/create-store.d.ts +1 -1
- package/lib/react/create-store.js +2 -2
- package/lib/react/create-stores.d.ts +2 -1
- package/lib/react/create-stores.js +31 -4
- package/lib/{vanilla.d.ts → store.d.ts} +1 -1
- package/lib/{utils/index.d.ts → utils.d.ts} +19 -3
- package/lib/{utils/index.js → utils.js} +19 -4
- package/package.json +28 -24
- package/utils/package.json +6 -0
- package/esm/react/index.d.ts +0 -6
- package/esm/react/index.js +0 -6
- package/lib/react/index.d.ts +0 -6
- package/lib/react/index.js +0 -9
- /package/esm/{utils/fetcher.d.ts → fetcher.d.ts} +0 -0
- /package/esm/{vanilla.js → store.js} +0 -0
- /package/lib/{utils/fetcher.d.ts → fetcher.d.ts} +0 -0
- /package/lib/{vanilla.js → store.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createError, getValue, identityFn } from '
|
|
1
|
+
import { createError, getValue, identityFn } from './utils';
|
|
2
2
|
const encodeParams = (params) => Object.entries(params)
|
|
3
3
|
.filter(([, value]) => value !== undefined && value !== null)
|
|
4
4
|
.map((kv) => kv.map(encodeURIComponent).join('='))
|
package/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './react';
|
|
1
|
+
export * from './store';
|
|
2
|
+
export * from './fetcher';
|
|
3
|
+
export * from './react/create-store';
|
|
4
|
+
export * from './react/create-stores';
|
|
5
|
+
export * from './react/create-query';
|
|
6
|
+
export * from './react/create-bi-direction-query';
|
|
7
|
+
export * from './react/create-mutation';
|
|
8
|
+
export * from './react/with-context';
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './react';
|
|
1
|
+
export * from './store';
|
|
2
|
+
export * from './fetcher';
|
|
3
|
+
export * from './react/create-store';
|
|
4
|
+
export * from './react/create-stores';
|
|
5
|
+
export * from './react/create-query';
|
|
6
|
+
export * from './react/create-bi-direction-query';
|
|
7
|
+
export * from './react/create-mutation';
|
|
8
|
+
export * from './react/with-context';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InitStoreOptions, SelectDeps, SetStoreData, StoreData, StoreInitializer, Subscribers } from '../
|
|
1
|
+
import { InitStoreOptions, SelectDeps, SetStoreData, StoreData, StoreInitializer, Subscribers } from '../store';
|
|
2
2
|
export type WatchProps<T, K extends SelectDeps<T> | keyof T = SelectDeps<T>> = {
|
|
3
3
|
selectDeps?: K;
|
|
4
4
|
render: (state: K extends keyof T ? T[K] : T) => any;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { InitStoreOptions, InitStoreReturn, SelectDeps, SetStoreData, StoreData, Subscribers } from '../store';
|
|
1
2
|
import { Maybe } from '../utils';
|
|
2
|
-
import { InitStoreOptions, InitStoreReturn, SelectDeps, SetStoreData, StoreData, Subscribers } from '../vanilla';
|
|
3
3
|
import { WatchProps } from './create-store';
|
|
4
4
|
export type StoreKey = Record<string, any> | undefined;
|
|
5
5
|
export type StoresInitializer<TKey extends StoreKey = StoreKey, T extends StoreData = StoreData> = T | ((api: {
|
|
@@ -70,6 +70,7 @@ export type CreateStoresOptions<TKey extends StoreKey = StoreKey, T extends Stor
|
|
|
70
70
|
defaultDeps?: SelectDeps<T>;
|
|
71
71
|
hashKeyFn?: (obj: TKey) => string;
|
|
72
72
|
};
|
|
73
|
+
export declare const hashStoreKey: (value?: any) => string;
|
|
73
74
|
/**
|
|
74
75
|
* @see https://floppy-disk.vercel.app/docs/api#createstores
|
|
75
76
|
*/
|
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { initStore, } from '../store';
|
|
3
|
+
import { getValue, noop } from '../utils';
|
|
4
|
+
const hasObjectPrototype = (value) => {
|
|
5
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
6
|
+
};
|
|
7
|
+
const isPlainObject = (value) => {
|
|
8
|
+
if (!hasObjectPrototype(value))
|
|
9
|
+
return false;
|
|
10
|
+
const ctor = value.constructor;
|
|
11
|
+
if (typeof ctor === 'undefined')
|
|
12
|
+
return true;
|
|
13
|
+
const prot = ctor.prototype;
|
|
14
|
+
if (!hasObjectPrototype(prot))
|
|
15
|
+
return false;
|
|
16
|
+
if (!prot.hasOwnProperty('isPrototypeOf'))
|
|
17
|
+
return false;
|
|
18
|
+
return true;
|
|
19
|
+
};
|
|
20
|
+
export const hashStoreKey = (value) =>
|
|
21
|
+
// Copied from: https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts
|
|
22
|
+
JSON.stringify(value, (_, val) => isPlainObject(val)
|
|
23
|
+
? Object.keys(val)
|
|
24
|
+
.sort()
|
|
25
|
+
.reduce((result, key) => {
|
|
26
|
+
result[key] = val[key];
|
|
27
|
+
return result;
|
|
28
|
+
}, {})
|
|
29
|
+
: val);
|
|
4
30
|
/**
|
|
5
31
|
* @see https://floppy-disk.vercel.app/docs/api#createstores
|
|
6
32
|
*/
|
|
@@ -9,7 +9,7 @@ export type StoreInitializer<T> = T | ((api: {
|
|
|
9
9
|
}) => T);
|
|
10
10
|
export type StoreEvent<T> = (state: T) => void;
|
|
11
11
|
export type InitStoreOptions<T> = {
|
|
12
|
-
intercept?: (nextState: T, prevState: T) => Maybe<Partial<T>>;
|
|
12
|
+
intercept?: (nextState: T, prevState: T) => void | Maybe<Partial<T>>;
|
|
13
13
|
onFirstSubscribe?: StoreEvent<T>;
|
|
14
14
|
onSubscribe?: StoreEvent<T>;
|
|
15
15
|
onUnsubscribe?: StoreEvent<T>;
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
export type Maybe<T> = T | null | undefined;
|
|
2
|
+
/**
|
|
3
|
+
* Check if this runs on browser.
|
|
4
|
+
*/
|
|
5
|
+
export declare const isClient: boolean;
|
|
1
6
|
export declare const noop: () => void;
|
|
2
7
|
export declare const identityFn: <T>(value: T) => T;
|
|
8
|
+
/**
|
|
9
|
+
* Check if a value is not undefined and not null.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const hasValue = (value: any) => value !== undefined && value !== null;
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
3
15
|
export declare const hasValue: (value: any) => boolean;
|
|
4
|
-
|
|
16
|
+
/**
|
|
17
|
+
* If the value is a function, it will invoke the function.\
|
|
18
|
+
* If the value is not a function, it will just return it.
|
|
19
|
+
*/
|
|
5
20
|
export declare const getValue: <T, P extends any[]>(valueOrComputeValueFn: T | ((...params: P) => T), ...params: P) => T;
|
|
6
|
-
|
|
7
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Create an Error instance with custom props.
|
|
23
|
+
*/
|
|
8
24
|
export declare const createError: (message: string, props: Record<string, any>) => Error & Record<string, any>;
|
|
@@ -1,14 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if this runs on browser.
|
|
3
|
+
*/
|
|
4
|
+
export const isClient = typeof window !== 'undefined' && !('Deno' in window);
|
|
1
5
|
export const noop = () => { };
|
|
2
6
|
export const identityFn = (value) => value;
|
|
7
|
+
/**
|
|
8
|
+
* Check if a value is not undefined and not null.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const hasValue = (value: any) => value !== undefined && value !== null;
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
3
14
|
export const hasValue = (value) => value !== undefined && value !== null;
|
|
4
|
-
|
|
15
|
+
/**
|
|
16
|
+
* If the value is a function, it will invoke the function.\
|
|
17
|
+
* If the value is not a function, it will just return it.
|
|
18
|
+
*/
|
|
5
19
|
export const getValue = (valueOrComputeValueFn, ...params) => {
|
|
6
20
|
if (typeof valueOrComputeValueFn === 'function') {
|
|
7
21
|
return valueOrComputeValueFn(...params);
|
|
8
22
|
}
|
|
9
23
|
return valueOrComputeValueFn;
|
|
10
24
|
};
|
|
11
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Create an Error instance with custom props.
|
|
27
|
+
*/
|
|
12
28
|
export const createError = (message, props) => {
|
|
13
29
|
const error = Object.assign(new Error(message), props);
|
|
14
30
|
return error;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fetcher = void 0;
|
|
4
|
-
const
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
5
|
const encodeParams = (params) => Object.entries(params)
|
|
6
6
|
.filter(([, value]) => value !== undefined && value !== null)
|
|
7
7
|
.map((kv) => kv.map(encodeURIComponent).join('='))
|
|
@@ -18,7 +18,7 @@ const encodeParams = (params) => Object.entries(params)
|
|
|
18
18
|
* @returns A function to fetch data
|
|
19
19
|
*/
|
|
20
20
|
const fetcher = (options) => async (...args) => {
|
|
21
|
-
const { url, query, params, payload, headers, interceptRequest =
|
|
21
|
+
const { url, query, params, payload, headers, interceptRequest = utils_1.identityFn, interceptResponse, ...rest } = (0, utils_1.getValue)(options, ...args);
|
|
22
22
|
let autoOptions = {};
|
|
23
23
|
let searchParams = params;
|
|
24
24
|
if (query) {
|
|
@@ -53,7 +53,7 @@ const fetcher = (options) => async (...args) => {
|
|
|
53
53
|
let resJson = await res.json();
|
|
54
54
|
if (query) {
|
|
55
55
|
if (resJson.errors) {
|
|
56
|
-
throw (0,
|
|
56
|
+
throw (0, utils_1.createError)('Error GraphQL response', {
|
|
57
57
|
status: res.status,
|
|
58
58
|
statusText: res.statusText,
|
|
59
59
|
response: resJson.errors,
|
|
@@ -69,7 +69,7 @@ const fetcher = (options) => async (...args) => {
|
|
|
69
69
|
return finalResponse;
|
|
70
70
|
}
|
|
71
71
|
catch (error) {
|
|
72
|
-
throw (0,
|
|
72
|
+
throw (0, utils_1.createError)('Error intercept response', {
|
|
73
73
|
status: res.status,
|
|
74
74
|
statusText: res.statusText,
|
|
75
75
|
response: resJson,
|
|
@@ -80,7 +80,7 @@ const fetcher = (options) => async (...args) => {
|
|
|
80
80
|
}
|
|
81
81
|
return resJson;
|
|
82
82
|
}
|
|
83
|
-
throw (0,
|
|
83
|
+
throw (0, utils_1.createError)('Fetch error', {
|
|
84
84
|
status: res.status,
|
|
85
85
|
statusText: res.statusText,
|
|
86
86
|
response: resJson,
|
|
@@ -88,7 +88,7 @@ const fetcher = (options) => async (...args) => {
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
const resText = await res.text().catch(() => undefined);
|
|
91
|
-
throw (0,
|
|
91
|
+
throw (0, utils_1.createError)('Response type is not a JSON', {
|
|
92
92
|
status: res.status,
|
|
93
93
|
statusText: res.statusText,
|
|
94
94
|
response: resText,
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './react';
|
|
1
|
+
export * from './store';
|
|
2
|
+
export * from './fetcher';
|
|
3
|
+
export * from './react/create-store';
|
|
4
|
+
export * from './react/create-stores';
|
|
5
|
+
export * from './react/create-query';
|
|
6
|
+
export * from './react/create-bi-direction-query';
|
|
7
|
+
export * from './react/create-mutation';
|
|
8
|
+
export * from './react/with-context';
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hashStoreKey = void 0;
|
|
4
3
|
const tslib_1 = require("tslib");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
tslib_1.__exportStar(require("./
|
|
8
|
-
tslib_1.__exportStar(require("./
|
|
9
|
-
tslib_1.__exportStar(require("./react"), exports);
|
|
4
|
+
tslib_1.__exportStar(require("./store"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./fetcher"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./react/create-store"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./react/create-stores"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./react/create-query"), exports);
|
|
9
|
+
tslib_1.__exportStar(require("./react/create-bi-direction-query"), exports);
|
|
10
|
+
tslib_1.__exportStar(require("./react/create-mutation"), exports);
|
|
11
|
+
tslib_1.__exportStar(require("./react/with-context"), exports);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InitStoreOptions, SelectDeps, SetStoreData, StoreData, StoreInitializer, Subscribers } from '../
|
|
1
|
+
import { InitStoreOptions, SelectDeps, SetStoreData, StoreData, StoreInitializer, Subscribers } from '../store';
|
|
2
2
|
export type WatchProps<T, K extends SelectDeps<T> | keyof T = SelectDeps<T>> = {
|
|
3
3
|
selectDeps?: K;
|
|
4
4
|
render: (state: K extends keyof T ? T[K] : T) => any;
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStore = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
5
|
+
const store_1 = require("../store");
|
|
6
6
|
/**
|
|
7
7
|
* @see https://floppy-disk.vercel.app/docs/api#createstore
|
|
8
8
|
*/
|
|
9
9
|
const createStore = (initializer, options = {}) => {
|
|
10
|
-
const { get, set, subscribe, getSubscribers } = (0,
|
|
10
|
+
const { get, set, subscribe, getSubscribers } = (0, store_1.initStore)(initializer, options);
|
|
11
11
|
const { defaultDeps } = options;
|
|
12
12
|
/**
|
|
13
13
|
* **IMPORTANT NOTE:** `selectDeps` function must not be changed after initialization.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { InitStoreOptions, InitStoreReturn, SelectDeps, SetStoreData, StoreData, Subscribers } from '../store';
|
|
1
2
|
import { Maybe } from '../utils';
|
|
2
|
-
import { InitStoreOptions, InitStoreReturn, SelectDeps, SetStoreData, StoreData, Subscribers } from '../vanilla';
|
|
3
3
|
import { WatchProps } from './create-store';
|
|
4
4
|
export type StoreKey = Record<string, any> | undefined;
|
|
5
5
|
export type StoresInitializer<TKey extends StoreKey = StoreKey, T extends StoreData = StoreData> = T | ((api: {
|
|
@@ -70,6 +70,7 @@ export type CreateStoresOptions<TKey extends StoreKey = StoreKey, T extends Stor
|
|
|
70
70
|
defaultDeps?: SelectDeps<T>;
|
|
71
71
|
hashKeyFn?: (obj: TKey) => string;
|
|
72
72
|
};
|
|
73
|
+
export declare const hashStoreKey: (value?: any) => string;
|
|
73
74
|
/**
|
|
74
75
|
* @see https://floppy-disk.vercel.app/docs/api#createstores
|
|
75
76
|
*/
|
|
@@ -1,20 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createStores = void 0;
|
|
3
|
+
exports.createStores = exports.hashStoreKey = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
+
const store_1 = require("../store");
|
|
5
6
|
const utils_1 = require("../utils");
|
|
6
|
-
const
|
|
7
|
+
const hasObjectPrototype = (value) => {
|
|
8
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
9
|
+
};
|
|
10
|
+
const isPlainObject = (value) => {
|
|
11
|
+
if (!hasObjectPrototype(value))
|
|
12
|
+
return false;
|
|
13
|
+
const ctor = value.constructor;
|
|
14
|
+
if (typeof ctor === 'undefined')
|
|
15
|
+
return true;
|
|
16
|
+
const prot = ctor.prototype;
|
|
17
|
+
if (!hasObjectPrototype(prot))
|
|
18
|
+
return false;
|
|
19
|
+
if (!prot.hasOwnProperty('isPrototypeOf'))
|
|
20
|
+
return false;
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
const hashStoreKey = (value) =>
|
|
24
|
+
// Copied from: https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts
|
|
25
|
+
JSON.stringify(value, (_, val) => isPlainObject(val)
|
|
26
|
+
? Object.keys(val)
|
|
27
|
+
.sort()
|
|
28
|
+
.reduce((result, key) => {
|
|
29
|
+
result[key] = val[key];
|
|
30
|
+
return result;
|
|
31
|
+
}, {})
|
|
32
|
+
: val);
|
|
33
|
+
exports.hashStoreKey = hashStoreKey;
|
|
7
34
|
/**
|
|
8
35
|
* @see https://floppy-disk.vercel.app/docs/api#createstores
|
|
9
36
|
*/
|
|
10
37
|
const createStores = (initializer, options = {}) => {
|
|
11
|
-
const { onBeforeChangeKey = utils_1.noop, onStoreInitialized = utils_1.noop, defaultDeps, hashKeyFn =
|
|
38
|
+
const { onBeforeChangeKey = utils_1.noop, onStoreInitialized = utils_1.noop, defaultDeps, hashKeyFn = exports.hashStoreKey, } = options;
|
|
12
39
|
const stores = new Map();
|
|
13
40
|
const getStore = (_key) => {
|
|
14
41
|
const key = _key || {};
|
|
15
42
|
const keyHash = hashKeyFn(key);
|
|
16
43
|
if (!stores.has(keyHash)) {
|
|
17
|
-
stores.set(keyHash, (0,
|
|
44
|
+
stores.set(keyHash, (0, store_1.initStore)((api) => (0, utils_1.getValue)(initializer, { key, keyHash, ...api }), options));
|
|
18
45
|
onStoreInitialized(key, keyHash);
|
|
19
46
|
}
|
|
20
47
|
return stores.get(keyHash);
|
|
@@ -9,7 +9,7 @@ export type StoreInitializer<T> = T | ((api: {
|
|
|
9
9
|
}) => T);
|
|
10
10
|
export type StoreEvent<T> = (state: T) => void;
|
|
11
11
|
export type InitStoreOptions<T> = {
|
|
12
|
-
intercept?: (nextState: T, prevState: T) => Maybe<Partial<T>>;
|
|
12
|
+
intercept?: (nextState: T, prevState: T) => void | Maybe<Partial<T>>;
|
|
13
13
|
onFirstSubscribe?: StoreEvent<T>;
|
|
14
14
|
onSubscribe?: StoreEvent<T>;
|
|
15
15
|
onUnsubscribe?: StoreEvent<T>;
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
export type Maybe<T> = T | null | undefined;
|
|
2
|
+
/**
|
|
3
|
+
* Check if this runs on browser.
|
|
4
|
+
*/
|
|
5
|
+
export declare const isClient: boolean;
|
|
1
6
|
export declare const noop: () => void;
|
|
2
7
|
export declare const identityFn: <T>(value: T) => T;
|
|
8
|
+
/**
|
|
9
|
+
* Check if a value is not undefined and not null.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* const hasValue = (value: any) => value !== undefined && value !== null;
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
3
15
|
export declare const hasValue: (value: any) => boolean;
|
|
4
|
-
|
|
16
|
+
/**
|
|
17
|
+
* If the value is a function, it will invoke the function.\
|
|
18
|
+
* If the value is not a function, it will just return it.
|
|
19
|
+
*/
|
|
5
20
|
export declare const getValue: <T, P extends any[]>(valueOrComputeValueFn: T | ((...params: P) => T), ...params: P) => T;
|
|
6
|
-
|
|
7
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Create an Error instance with custom props.
|
|
23
|
+
*/
|
|
8
24
|
export declare const createError: (message: string, props: Record<string, any>) => Error & Record<string, any>;
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createError = exports.
|
|
3
|
+
exports.createError = exports.getValue = exports.hasValue = exports.identityFn = exports.noop = exports.isClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Check if this runs on browser.
|
|
6
|
+
*/
|
|
7
|
+
exports.isClient = typeof window !== 'undefined' && !('Deno' in window);
|
|
4
8
|
const noop = () => { };
|
|
5
9
|
exports.noop = noop;
|
|
6
10
|
const identityFn = (value) => value;
|
|
7
11
|
exports.identityFn = identityFn;
|
|
12
|
+
/**
|
|
13
|
+
* Check if a value is not undefined and not null.
|
|
14
|
+
*
|
|
15
|
+
* ```ts
|
|
16
|
+
* const hasValue = (value: any) => value !== undefined && value !== null;
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
8
19
|
const hasValue = (value) => value !== undefined && value !== null;
|
|
9
20
|
exports.hasValue = hasValue;
|
|
10
|
-
|
|
11
|
-
|
|
21
|
+
/**
|
|
22
|
+
* If the value is a function, it will invoke the function.\
|
|
23
|
+
* If the value is not a function, it will just return it.
|
|
24
|
+
*/
|
|
12
25
|
const getValue = (valueOrComputeValueFn, ...params) => {
|
|
13
26
|
if (typeof valueOrComputeValueFn === 'function') {
|
|
14
27
|
return valueOrComputeValueFn(...params);
|
|
@@ -16,7 +29,9 @@ const getValue = (valueOrComputeValueFn, ...params) => {
|
|
|
16
29
|
return valueOrComputeValueFn;
|
|
17
30
|
};
|
|
18
31
|
exports.getValue = getValue;
|
|
19
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Create an Error instance with custom props.
|
|
34
|
+
*/
|
|
20
35
|
const createError = (message, props) => {
|
|
21
36
|
const error = Object.assign(new Error(message), props);
|
|
22
37
|
return error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "floppy-disk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.0-beta.1",
|
|
4
4
|
"description": "FloppyDisk - lightweight, simple, and powerful state management library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"state",
|
|
@@ -25,39 +25,43 @@
|
|
|
25
25
|
"sideEffects": false,
|
|
26
26
|
"files": [
|
|
27
27
|
"lib/",
|
|
28
|
-
"esm/"
|
|
28
|
+
"esm/",
|
|
29
|
+
"utils/"
|
|
29
30
|
],
|
|
30
|
-
"main": "lib/index.js",
|
|
31
|
-
"module": "esm/index.js",
|
|
32
|
-
"types": "lib/index.d.ts",
|
|
33
|
-
"typings": "lib/index.d.ts",
|
|
31
|
+
"main": "./lib/index.js",
|
|
32
|
+
"module": "./esm/index.js",
|
|
33
|
+
"types": "./lib/index.d.ts",
|
|
34
34
|
"exports": {
|
|
35
35
|
"./package.json": "./package.json",
|
|
36
36
|
".": {
|
|
37
|
-
"types": "./lib/index.d.ts",
|
|
38
37
|
"import": {
|
|
39
38
|
"types": "./esm/index.d.ts",
|
|
40
39
|
"default": "./esm/index.js"
|
|
41
40
|
},
|
|
42
|
-
"module":
|
|
43
|
-
|
|
41
|
+
"module": {
|
|
42
|
+
"types": "./esm/index.d.ts",
|
|
43
|
+
"default": "./esm/index.js"
|
|
44
|
+
},
|
|
45
|
+
"default": {
|
|
46
|
+
"types": "./lib/index.d.ts",
|
|
47
|
+
"default": "./lib/index.js"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"./utils": {
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./esm/utils.d.ts",
|
|
53
|
+
"default": "./esm/utils.js"
|
|
54
|
+
},
|
|
55
|
+
"module": {
|
|
56
|
+
"types": "./esm/utils.d.ts",
|
|
57
|
+
"default": "./esm/utils.js"
|
|
58
|
+
},
|
|
59
|
+
"default": {
|
|
60
|
+
"types": "./lib/utils.d.ts",
|
|
61
|
+
"default": "./lib/utils.js"
|
|
62
|
+
}
|
|
44
63
|
}
|
|
45
64
|
},
|
|
46
|
-
"scripts": {
|
|
47
|
-
"prepare": "husky install",
|
|
48
|
-
"build:cjs": "tsc -p tsconfig.prod.json",
|
|
49
|
-
"build:es": "tsc -p tsconfig.prod.json -m esNext --outDir esm",
|
|
50
|
-
"build": "yarn clean && yarn build:cjs && yarn build:es",
|
|
51
|
-
"prebuild": "ts-node ./scripts/preact.ts",
|
|
52
|
-
"clean": "rimraf lib esm",
|
|
53
|
-
"format": "prettier --check .",
|
|
54
|
-
"format:fix": "prettier --write .",
|
|
55
|
-
"lint": "eslint .",
|
|
56
|
-
"lint:fix": "eslint . --fix",
|
|
57
|
-
"lint:types": "tsc --noEmit",
|
|
58
|
-
"test": "jest --silent",
|
|
59
|
-
"semantic-release": "semantic-release"
|
|
60
|
-
},
|
|
61
65
|
"release": {
|
|
62
66
|
"branches": [
|
|
63
67
|
"main",
|
package/esm/react/index.d.ts
DELETED
package/esm/react/index.js
DELETED
package/lib/react/index.d.ts
DELETED
package/lib/react/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./create-store"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./create-stores"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./create-query"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./create-bi-direction-query"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./create-mutation"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./with-context"), exports);
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|