Skip to content

Commit bc0cdc3

Browse files
committed
refactor(react): update client runtime components to use base components
1 parent ca9c3a9 commit bc0cdc3

4 files changed

Lines changed: 29 additions & 69 deletions

File tree

packages/react/src/client/chunk.tsx

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,20 @@
22

33
import { useContext } from "react";
44
import { replexicaContext } from "./context";
5-
import { ReplexicaChunkGetterArgs, ReplexicaChunkProps } from "../types";
5+
import { ReplexicaBaseChunk, ReplexicaBaseChunkProps } from "../shared";
66

7-
export function ReplexicaClientChunk(props: ReplexicaChunkProps) {
8-
const r = useContext(replexicaContext)!;
9-
10-
const result = getReplexicaChunkContent({
11-
data: r.data,
12-
selector: props,
13-
});
7+
export type ReplexicaChunkProps = Omit<ReplexicaBaseChunkProps, 'data'>;
148

15-
return result;
9+
export function ReplexicaClientChunk(props: ReplexicaChunkProps) {
10+
const r = useContext(replexicaContext);
11+
const data = r?.data || {};
12+
13+
return (
14+
<ReplexicaBaseChunk
15+
data={data}
16+
fileId={props.fileId}
17+
scopeId={props.scopeId}
18+
chunkId={props.chunkId}
19+
/>
20+
);
1621
}
17-
18-
export function getReplexicaChunkContent(args: ReplexicaChunkGetterArgs) {
19-
const fileData = args.data?.[args.selector.fileId];
20-
const scopeData = fileData?.[args.selector.scopeId];
21-
const chunkData = scopeData?.[args.selector.chunkId];
22-
23-
const fallback = `chunk#${args.selector.fileId}:${args.selector.scopeId}.${args.selector.chunkId}`;
24-
25-
const result = chunkData || fallback;
26-
27-
return result;
28-
}
Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,20 @@
11
'use client';
22

3-
import { createElement, useContext } from "react";
4-
import { ReplexicaChunkSelector, ReplexicaProxyProps } from "../types";
5-
import { replexicaContext } from "./context";
6-
import { getReplexicaChunkContent } from "./chunk";
3+
import { useContext } from 'react';
4+
import { ReplexicaBaseProxy, ReplexicaBaseProxyProps } from "../shared";
5+
import { replexicaContext } from './context';
76

8-
export function ReplexicaClientProxy<P extends {}>(props: ReplexicaProxyProps<P>) {
9-
// const r = useContext(replexicaContext)!;
10-
// const data = r.data;
7+
export type ReplexicaClientProxyProps<P extends {}> =
8+
& Omit<ReplexicaBaseProxyProps<P>, 'data'>;
119

12-
// const propsPatch: Partial<P> = Object
13-
// .entries(props.attributes || {})
14-
// .reduce((acc, [key, value]) => {
15-
// const result = getReplexicaChunkContent({
16-
// data: data,
17-
// selector: value as ReplexicaChunkSelector,
18-
// });
10+
export async function ReplexicaClientProxy<P extends {}>(props: ReplexicaClientProxyProps<P>) {
11+
const r = useContext(replexicaContext)!;
12+
const data = r.data || {};
1913

20-
// return {
21-
// ...acc,
22-
// [key]: result,
23-
// };
24-
// }, {});
25-
26-
// const modifiedProps: P = {
27-
// ...props.targetProps,
28-
// ...propsPatch,
29-
// };
30-
31-
// return createElement(
32-
// props.target,
33-
// modifiedProps,
34-
// );
35-
return null;
14+
return (
15+
<ReplexicaBaseProxy<P>
16+
data={data as any}
17+
{...props as any}
18+
/>
19+
);
3620
}

packages/react/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const value = 42;
1+
export {};

packages/react/src/types.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)