rxfy-react 0.2.0 → 1.0.0
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/README.md +390 -20
- package/dist/chunk-BO3M5NLW.js +42 -0
- package/dist/index.cjs +9705 -32
- package/dist/index.d.ts +79 -29
- package/dist/index.js +9684 -24
- package/dist/next.cjs +83 -0
- package/dist/next.d.ts +8 -0
- package/dist/next.js +49 -0
- package/package.json +40 -21
- package/dist/index.d.cts +0 -32
package/dist/next.cjs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/next/index.ts
|
|
22
|
+
var next_exports = {};
|
|
23
|
+
__export(next_exports, {
|
|
24
|
+
HydrationStream: () => HydrationStream
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(next_exports);
|
|
27
|
+
|
|
28
|
+
// src/next/HydrationStream.tsx
|
|
29
|
+
var import_navigation = require("next/navigation");
|
|
30
|
+
var import_react2 = require("react");
|
|
31
|
+
var import_rxfy = require("rxfy");
|
|
32
|
+
|
|
33
|
+
// src/registry-context.ts
|
|
34
|
+
var import_react = require("react");
|
|
35
|
+
var ModelRegistryContext = (0, import_react.createContext)(null);
|
|
36
|
+
function useModelRegistry() {
|
|
37
|
+
const ctx = (0, import_react.useContext)(ModelRegistryContext);
|
|
38
|
+
if (!ctx) throw new Error("StoreProvider not found");
|
|
39
|
+
return ctx;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/next/HydrationStream.tsx
|
|
43
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
44
|
+
function HydrationStream() {
|
|
45
|
+
const registry = useModelRegistry();
|
|
46
|
+
const flushedQueries = (0, import_react2.useRef)(/* @__PURE__ */ new Set());
|
|
47
|
+
const flushedEntities = (0, import_react2.useRef)(/* @__PURE__ */ new Set());
|
|
48
|
+
(0, import_navigation.useServerInsertedHTML)(() => {
|
|
49
|
+
var _a;
|
|
50
|
+
const full = (0, import_rxfy.dehydrate)(registry);
|
|
51
|
+
const delta = { queries: {}, models: {} };
|
|
52
|
+
let hasData = false;
|
|
53
|
+
for (const [key, entry] of Object.entries(full.queries)) {
|
|
54
|
+
if (flushedQueries.current.has(key)) continue;
|
|
55
|
+
flushedQueries.current.add(key);
|
|
56
|
+
delta.queries[key] = entry;
|
|
57
|
+
hasData = true;
|
|
58
|
+
}
|
|
59
|
+
for (const [name, entities] of Object.entries(full.models)) {
|
|
60
|
+
for (const [key, entity] of Object.entries(entities)) {
|
|
61
|
+
const id = JSON.stringify([name, key]);
|
|
62
|
+
if (flushedEntities.current.has(id)) continue;
|
|
63
|
+
flushedEntities.current.add(id);
|
|
64
|
+
((_a = delta.models)[name] ?? (_a[name] = {}))[key] = entity;
|
|
65
|
+
hasData = true;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (!hasData) return null;
|
|
69
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
70
|
+
"script",
|
|
71
|
+
{
|
|
72
|
+
dangerouslySetInnerHTML: {
|
|
73
|
+
__html: `window.__RXFY_SSR__=window.__RXFY_SSR__||[];window.__RXFY_SSR__.push(${(0, import_rxfy.serializeForHtml)(delta)})`
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
81
|
+
0 && (module.exports = {
|
|
82
|
+
HydrationStream
|
|
83
|
+
});
|
package/dist/next.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Next.js App Router streaming adapter. Render once inside StoreProvider; each stream
|
|
3
|
+
* flush emits newly settled queries / newly written entities as a window.__RXFY_SSR__
|
|
4
|
+
* push — StoreProvider on the client ingests them, including late-arriving chunks.
|
|
5
|
+
*/
|
|
6
|
+
declare function HydrationStream(): null;
|
|
7
|
+
|
|
8
|
+
export { HydrationStream };
|
package/dist/next.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useModelRegistry
|
|
4
|
+
} from "./chunk-BO3M5NLW.js";
|
|
5
|
+
|
|
6
|
+
// src/next/HydrationStream.tsx
|
|
7
|
+
import { useServerInsertedHTML } from "next/navigation";
|
|
8
|
+
import { useRef } from "react";
|
|
9
|
+
import { dehydrate, serializeForHtml } from "rxfy";
|
|
10
|
+
import { jsx } from "react/jsx-runtime";
|
|
11
|
+
function HydrationStream() {
|
|
12
|
+
const registry = useModelRegistry();
|
|
13
|
+
const flushedQueries = useRef(/* @__PURE__ */ new Set());
|
|
14
|
+
const flushedEntities = useRef(/* @__PURE__ */ new Set());
|
|
15
|
+
useServerInsertedHTML(() => {
|
|
16
|
+
var _a;
|
|
17
|
+
const full = dehydrate(registry);
|
|
18
|
+
const delta = { queries: {}, models: {} };
|
|
19
|
+
let hasData = false;
|
|
20
|
+
for (const [key, entry] of Object.entries(full.queries)) {
|
|
21
|
+
if (flushedQueries.current.has(key)) continue;
|
|
22
|
+
flushedQueries.current.add(key);
|
|
23
|
+
delta.queries[key] = entry;
|
|
24
|
+
hasData = true;
|
|
25
|
+
}
|
|
26
|
+
for (const [name, entities] of Object.entries(full.models)) {
|
|
27
|
+
for (const [key, entity] of Object.entries(entities)) {
|
|
28
|
+
const id = JSON.stringify([name, key]);
|
|
29
|
+
if (flushedEntities.current.has(id)) continue;
|
|
30
|
+
flushedEntities.current.add(id);
|
|
31
|
+
((_a = delta.models)[name] ?? (_a[name] = {}))[key] = entity;
|
|
32
|
+
hasData = true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (!hasData) return null;
|
|
36
|
+
return /* @__PURE__ */ jsx(
|
|
37
|
+
"script",
|
|
38
|
+
{
|
|
39
|
+
dangerouslySetInnerHTML: {
|
|
40
|
+
__html: `window.__RXFY_SSR__=window.__RXFY_SSR__||[];window.__RXFY_SSR__.push(${serializeForHtml(delta)})`
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
HydrationStream
|
|
49
|
+
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rxfy-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "rxfy bindings for react",
|
|
5
|
-
"
|
|
5
|
+
"homepage": "https://github.com/vanya2h/rxfy#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/vanya2h/rxfy/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/vanya2h/rxfy.git"
|
|
12
|
+
},
|
|
13
|
+
"author": "hi@vanya2h.me",
|
|
6
14
|
"type": "module",
|
|
7
15
|
"exports": {
|
|
8
16
|
".": {
|
|
9
17
|
"import": "./dist/index.js",
|
|
10
18
|
"types": "./dist/index.d.ts",
|
|
11
19
|
"default": "./dist/index.cjs"
|
|
20
|
+
},
|
|
21
|
+
"./next": {
|
|
22
|
+
"import": "./dist/next.js",
|
|
23
|
+
"types": "./dist/next.d.ts",
|
|
24
|
+
"default": "./dist/next.cjs"
|
|
12
25
|
}
|
|
13
26
|
},
|
|
14
27
|
"main": "./dist/index.js",
|
|
@@ -18,41 +31,47 @@
|
|
|
18
31
|
"dist",
|
|
19
32
|
"package.json"
|
|
20
33
|
],
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@vanya2h/utils": "0.1.2"
|
|
23
|
-
},
|
|
24
34
|
"devDependencies": {
|
|
25
35
|
"@testing-library/jest-dom": "^6.6.3",
|
|
26
|
-
"@testing-library/react": "^16.
|
|
27
|
-
"@types/lodash": "^4.17.
|
|
28
|
-
"@types/react": "^19.
|
|
29
|
-
"
|
|
30
|
-
"
|
|
36
|
+
"@testing-library/react": "^16.3.0",
|
|
37
|
+
"@types/lodash": "^4.17.17",
|
|
38
|
+
"@types/react": "^19.2.14",
|
|
39
|
+
"@types/react-dom": "^19.2.3",
|
|
40
|
+
"eslint": "^9.27.0",
|
|
41
|
+
"immutable": "^5.1.2",
|
|
31
42
|
"jiti": "^2.4.2",
|
|
32
|
-
"jsdom": "^26.
|
|
43
|
+
"jsdom": "^26.1.0",
|
|
33
44
|
"lodash": "^4.17.21",
|
|
34
45
|
"p-queue": "^8.1.0",
|
|
35
|
-
"react": "^19.
|
|
36
|
-
"react-dom": "^19.
|
|
46
|
+
"react": "^19.2.5",
|
|
47
|
+
"react-dom": "^19.2.5",
|
|
37
48
|
"rimraf": "^6.0.1",
|
|
49
|
+
"@vanya2h/eslint-config": "^0.4.0",
|
|
50
|
+
"@vanya2h/typescript-config": "^0.4.0",
|
|
38
51
|
"rxjs": "^7.8.2",
|
|
39
|
-
"tsup": "^8.
|
|
40
|
-
"tsx": "^4.19.
|
|
41
|
-
"vitest": "^3.
|
|
42
|
-
"zod": "^3.
|
|
43
|
-
"
|
|
44
|
-
"@vanya2h/eslint-config": "0.2.1",
|
|
45
|
-
"rxfy": "0.2.1"
|
|
52
|
+
"tsup": "^8.5.0",
|
|
53
|
+
"tsx": "^4.19.4",
|
|
54
|
+
"vitest": "^3.1.4",
|
|
55
|
+
"zod": "^3.25.42",
|
|
56
|
+
"rxfy": "0.3.0"
|
|
46
57
|
},
|
|
47
58
|
"peerDependencies": {
|
|
48
59
|
"@types/react": "^18.0.0 || ^19.0.0",
|
|
60
|
+
"lodash": "^4.0.0",
|
|
49
61
|
"react": "^18.0.0 || ^19.0.0",
|
|
50
|
-
"
|
|
62
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
63
|
+
"next": ">=14",
|
|
64
|
+
"rxfy": "0.3.0"
|
|
51
65
|
},
|
|
52
66
|
"publishConfig": {
|
|
53
67
|
"access": "public",
|
|
54
68
|
"registry": "https://registry.npmjs.org"
|
|
55
69
|
},
|
|
70
|
+
"peerDependenciesMeta": {
|
|
71
|
+
"next": {
|
|
72
|
+
"optional": true
|
|
73
|
+
}
|
|
74
|
+
},
|
|
56
75
|
"scripts": {
|
|
57
76
|
"build": "tsup",
|
|
58
77
|
"check-types": "tsc --noEmit",
|
package/dist/index.d.cts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as react from 'react';
|
|
2
|
-
import { IEdge, StatusEnum } from 'rxfy';
|
|
3
|
-
|
|
4
|
-
declare function useEdge<TData>(edge: IEdge<TData>): ({
|
|
5
|
-
type: StatusEnum.IDLE;
|
|
6
|
-
} & {
|
|
7
|
-
type: StatusEnum;
|
|
8
|
-
}) | ({
|
|
9
|
-
type: StatusEnum.PENDING;
|
|
10
|
-
} & {
|
|
11
|
-
type: StatusEnum;
|
|
12
|
-
}) | ({
|
|
13
|
-
type: StatusEnum.REJECTED;
|
|
14
|
-
error: unknown;
|
|
15
|
-
} & {
|
|
16
|
-
type: StatusEnum;
|
|
17
|
-
}) | ({
|
|
18
|
-
type: StatusEnum.FULFILLED;
|
|
19
|
-
value: TData;
|
|
20
|
-
} & {
|
|
21
|
-
type: StatusEnum;
|
|
22
|
-
});
|
|
23
|
-
type IEdgeProps<TData> = {
|
|
24
|
-
edge: IEdge<TData>;
|
|
25
|
-
children: IRenderFn<TData>;
|
|
26
|
-
rejected?: IRenderFn<unknown>;
|
|
27
|
-
pending?: React.ReactNode;
|
|
28
|
-
};
|
|
29
|
-
declare function Edge<TData>({ edge, children, rejected, pending }: IEdgeProps<TData>): react.ReactNode;
|
|
30
|
-
type IRenderFn<TData> = React.ReactNode | ((data: TData) => React.ReactNode);
|
|
31
|
-
|
|
32
|
-
export { Edge, type IRenderFn, useEdge };
|