@streamlayer/react-polyfills 0.1.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/lib/index.d.ts +4 -0
- package/lib/index.js +13 -0
- package/lib/legacy.d.ts +12 -0
- package/lib/legacy.js +10 -0
- package/package.json +29 -0
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as modern from '@nanostores/react';
|
|
2
|
+
import * as modernReact from 'react';
|
|
3
|
+
import * as legacy from './legacy';
|
|
4
|
+
export const useStore = process.env.REACT_LEGACY ? legacy.useStore : modern.useStore;
|
|
5
|
+
const legacyUseTransition = () => {
|
|
6
|
+
return [
|
|
7
|
+
false,
|
|
8
|
+
(fn) => {
|
|
9
|
+
window.requestAnimationFrame(() => fn());
|
|
10
|
+
},
|
|
11
|
+
];
|
|
12
|
+
};
|
|
13
|
+
export const useTransition = process.env.REACT_LEGACY ? legacyUseTransition : modernReact.useTransition;
|
package/lib/legacy.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Store, type StoreValue } from 'nanostores';
|
|
2
|
+
type StoreKeys<T> = T extends {
|
|
3
|
+
setKey: (k: infer K, v: any) => unknown;
|
|
4
|
+
} ? K : never;
|
|
5
|
+
export interface UseStoreOptions<SomeStore> {
|
|
6
|
+
/**
|
|
7
|
+
* Will re-render components only on specific key changes.
|
|
8
|
+
*/
|
|
9
|
+
keys?: StoreKeys<SomeStore>[];
|
|
10
|
+
}
|
|
11
|
+
export declare function useStore<SomeStore extends Store>(store: Store, opts?: UseStoreOptions<SomeStore>): StoreValue<SomeStore>;
|
|
12
|
+
export {};
|
package/lib/legacy.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import { listenKeys } from 'nanostores';
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
6
|
+
export function useStore(store, opts = {}) {
|
|
7
|
+
const subscribe = useCallback((onChange) => (opts.keys ? listenKeys(store, opts.keys, onChange) : store.listen(onChange)), [opts.keys, store]);
|
|
8
|
+
const get = store.get.bind(store);
|
|
9
|
+
return useSyncExternalStore(subscribe, get, get);
|
|
10
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@streamlayer/react-polyfills",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./lib/index.js",
|
|
6
|
+
"typings": "./lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/",
|
|
9
|
+
"package.json"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./lib/index.d.ts",
|
|
14
|
+
"import": "./lib/index.js",
|
|
15
|
+
"default": "./lib/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./queries/*": {
|
|
18
|
+
"types": "./lib/grpc/queries/*.d.ts",
|
|
19
|
+
"import": "./lib/grpc/queries/*.js",
|
|
20
|
+
"default": "./lib/grpc/queries/*.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@nanostores/react": "^0.7.1",
|
|
25
|
+
"nanostores": "^0.9.4",
|
|
26
|
+
"react": "^18.2.0",
|
|
27
|
+
"use-sync-external-store": "^1.2.0"
|
|
28
|
+
}
|
|
29
|
+
}
|