Skip to content

Commit 7303b43

Browse files
LabEGCopilot
andcommitted
feat: add Custom Stores and Manual Store documentation screens
Co-authored-by: Copilot <copilot@github.com>
1 parent f6fb549 commit 7303b43

8 files changed

Lines changed: 714 additions & 144 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {type JSX} from "react";
2+
import {Shell} from "../../../src/components/shell/shell.js";
3+
import {CustomStoresScreen} from "../../../src/screens/guides/custom-stores-screen.js";
4+
5+
const Page = (): JSX.Element => (
6+
<Shell>
7+
<CustomStoresScreen />
8+
</Shell>
9+
);
10+
11+
export default Page;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {type JSX} from "react";
2+
import {Shell} from "../../../src/components/shell/shell.js";
3+
import {ManualStoreScreen} from "../../../src/screens/guides/manual-store-screen.js";
4+
5+
const Page = (): JSX.Element => (
6+
<Shell>
7+
<ManualStoreScreen />
8+
</Shell>
9+
);
10+
11+
export default Page;

packages/reca-docs/src/navigation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ export const navigation: INavGroup[] = [
3030
{label: "Repository Pattern", path: "/guides/repository"},
3131
{label: "Using Interfaces", path: "/guides/interfaces"},
3232
{label: "Component Communication", path: "/guides/component-communication"},
33+
{label: "Manual Store", path: "/guides/manual-store"},
34+
{label: "Custom Stores", path: "/guides/custom-stores"},
3335
{label: "SSR & Next.js", path: "/guides/ssr"}
3436
]
3537
},

packages/reca-docs/src/screens/getting-started/first-component-screen.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,21 @@ export const FirstComponentScreen = (): JSX.Element => (
2121

2222
<pre><code>{`// stores/todo.store.ts
2323
import { AutoStore } from "reca";
24-
import type { FormEvent } from "react";
2524
2625
export class TodoStore extends AutoStore {
26+
currentTodo = "";
27+
todos: string[] = [];
2728
28-
public currentTodo: string = "";
29-
30-
public todos: string[] = [];
31-
32-
public handleAddTodo(): void {
29+
addTodo() {
3330
if (this.currentTodo.trim()) {
3431
this.todos.push(this.currentTodo.trim());
3532
this.currentTodo = "";
3633
}
3734
}
3835
39-
public handleDeleteTodo(index: number): void {
36+
deleteTodo(index: number) {
4037
this.todos.splice(index, 1);
4138
}
42-
43-
public handleCurrentEdit(event: FormEvent<HTMLInputElement>): void {
44-
this.currentTodo = event.currentTarget.value;
45-
}
4639
}`}</code></pre>
4740

4841
<Alert severity="info" sx={{my: 2}}>
@@ -70,7 +63,7 @@ export const TodoComponent = () => {
7063
{store.todos.map((todo, index) => (
7164
<div key={index}>
7265
<span>{todo}</span>
73-
<button onClick={() => store.handleDeleteTodo(index)}>
66+
<button onClick={() => store.deleteTodo(index)}>
7467
Delete
7568
</button>
7669
</div>
@@ -80,10 +73,10 @@ export const TodoComponent = () => {
8073
<div>
8174
<input
8275
value={store.currentTodo}
83-
onInput={store.handleCurrentEdit}
76+
onChange={(e) => { store.currentTodo = e.target.value; }}
8477
placeholder="Enter a todo..."
8578
/>
86-
<button onClick={store.handleAddTodo}>
79+
<button onClick={() => store.addTodo()}>
8780
Add
8881
</button>
8982
</div>
@@ -96,7 +89,7 @@ export const TodoComponent = () => {
9689
<li><code>useStore(TodoStore)</code> creates a new instance of <code>TodoStore</code> scoped to this component</li>
9790
<li>The store instance is wrapped with a <code>Proxy</code> that detects property mutations</li>
9891
<li>When <code>todos</code> or <code>currentTodo</code> changes, React automatically re-renders the component</li>
99-
<li>Methods like <code>handleAddTodo</code> are called directly — no dispatching needed</li>
92+
<li>Store properties can be mutated directly (<code>store.currentTodo = ...</code>) or via methods like <code>addTodo()</code></li>
10093
</ol>
10194

10295
<blockquote>

packages/reca-docs/src/screens/getting-started/installation-screen.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,30 @@ ReactDOM.createRoot(
6464
</ul>
6565

6666
<h2>Next.js Setup</h2>
67+
68+
<h3>App Router</h3>
6769
<p>
68-
For Next.js projects, import <code>reflect-metadata</code> in your root layout or
69-
a custom <code>_app.tsx</code>:
70+
Import <code>reflect-metadata</code> at the top of your root layout:
7071
</p>
71-
<pre><code>{`// app/layout.tsx (App Router)
72+
<pre><code>{`// app/layout.tsx
7273
import "reflect-metadata";
7374
74-
export default function RootLayout({ children }) {
75+
export default function RootLayout({ children }: { children: React.ReactNode }) {
7576
return (
7677
<html><body>{children}</body></html>
7778
);
7879
}`}</code></pre>
80+
81+
<h3>Pages Router</h3>
82+
<p>
83+
Import <code>reflect-metadata</code> in your custom <code>_app.tsx</code>:
84+
</p>
85+
<pre><code>{`// pages/_app.tsx
86+
import "reflect-metadata";
87+
import type { AppProps } from "next/app";
88+
89+
export default function App({ Component, pageProps }: AppProps) {
90+
return <Component {...pageProps} />;
91+
}`}</code></pre>
7992
</DocContent>
8093
);

0 commit comments

Comments
 (0)