Skip to content

Commit e163275

Browse files
committed
docs: embed todomvc
1 parent 2efdd6d commit e163275

File tree

8 files changed

+105
-87
lines changed

8 files changed

+105
-87
lines changed

.yarn/install-state.gz

-10 Bytes
Binary file not shown.

examples/TodoMVC/src/TodoMVC.css

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#container {
2+
display: flex;
3+
align-items: center;
4+
justify-content: center;
5+
width: 100dvw;
6+
height: 100dvh;
7+
background: #242424;
8+
color: white;
9+
border: 1px solid white;
10+
box-sizing: border-box;
11+
}
12+
13+
.app {
14+
width: 100%;
15+
height: 100%;
16+
max-width: 640px;
17+
max-height: 800px;
18+
box-sizing: border-box;
19+
padding: 12px;
20+
display: flex;
21+
flex-direction: column;
22+
align-items: stretch;
23+
}
24+
25+
.flex {
26+
display: flex;
27+
}
28+
29+
.expand {
30+
flex: 1;
31+
}
32+
33+
.filter {
34+
align-self: center;
35+
padding: 20px 0;
36+
}
37+
38+
.filter-input {
39+
display: flex;
40+
justify-content: space-around;
41+
padding-bottom: 12px;
42+
}
43+
44+
button {
45+
cursor: pointer;
46+
}
47+
48+
.todo {
49+
padding: 8px 12px;
50+
border-bottom: 1px solid white;
51+
}

examples/TodoMVC/src/TodoMVC.tsx

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* @since 2024-10-18 23:41:18
3+
* @author junbao <[email protected]>
4+
*/
5+
6+
import { createStore, IDBStorage, withPersist } from 'amos';
7+
import { Provider } from 'amos/react';
8+
import { useState } from 'react';
9+
import { App } from './App';
10+
import './TodoMVC.css';
11+
12+
// For compat with website.
13+
export const TodoMVC = () => {
14+
const [store] = useState(() => {
15+
return createStore(
16+
{
17+
name: 'Amos - TodoMVC',
18+
devtools: true,
19+
},
20+
withPersist({
21+
storage: new IDBStorage('todo', 'todo'),
22+
includes: () => true,
23+
}),
24+
);
25+
});
26+
return (
27+
<Provider store={store}>
28+
<div id="container">
29+
<App />
30+
</div>
31+
</Provider>
32+
);
33+
};

examples/TodoMVC/src/index.css

-64
Original file line numberDiff line numberDiff line change
@@ -2,76 +2,12 @@
22
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
33
line-height: 1.5;
44
font-weight: 400;
5-
6-
--back: #000000;
7-
--front: #ffffff;
8-
9-
color-scheme: light dark;
10-
color: var(--front);
11-
background-color: var(--back);
12-
135
font-synthesis: none;
146
text-rendering: optimizeLegibility;
157
-webkit-font-smoothing: antialiased;
168
-moz-osx-font-smoothing: grayscale;
179
}
1810

19-
@media (prefers-color-scheme: light) {
20-
:root {
21-
--back: #ffffff;
22-
--front: #000000;
23-
}
24-
}
25-
2611
body {
2712
margin: 0;
2813
}
29-
30-
#root {
31-
display: flex;
32-
align-items: center;
33-
justify-content: center;
34-
width: 100dvw;
35-
height: 100dvh;
36-
}
37-
38-
.app {
39-
width: 100%;
40-
height: 100%;
41-
max-width: 640px;
42-
max-height: 800px;
43-
border: 1px solid var(--front);
44-
box-sizing: border-box;
45-
padding: 12px;
46-
display: flex;
47-
flex-direction: column;
48-
align-items: stretch;
49-
}
50-
51-
.flex {
52-
display: flex;
53-
}
54-
55-
.expand {
56-
flex: 1;
57-
}
58-
59-
.filter {
60-
align-self: center;
61-
padding: 20px 0;
62-
}
63-
64-
.filter-input {
65-
display: flex;
66-
justify-content: space-around;
67-
padding-bottom: 12px;
68-
}
69-
70-
button {
71-
cursor: pointer;
72-
}
73-
74-
.todo {
75-
padding: 8px 12px;
76-
border-bottom: 1px solid var(--front);
77-
}

examples/TodoMVC/src/main.tsx

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
1-
import { createStore, IDBStorage, withPersist } from 'amos';
2-
import { Provider } from 'amos/react';
31
import { StrictMode } from 'react';
42
import { createRoot } from 'react-dom/client';
5-
import { App } from './App';
3+
import { TodoMVC } from './TodoMVC';
64
import './index.css';
75

8-
const store = createStore(
9-
{
10-
name: 'Amos - TodoMVC',
11-
devtools: true,
12-
},
13-
withPersist({
14-
storage: new IDBStorage('todo', 'todo'),
15-
includes: () => true,
16-
}),
17-
);
18-
196
createRoot(document.getElementById('root')!).render(
207
<StrictMode>
21-
<Provider store={store}>
22-
<App />
23-
</Provider>
8+
<TodoMVC />
249
</StrictMode>,
2510
);
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
# Examples
22

33
## TodoMVC
4+
5+
TodoMVC is a classic example through which we demonstrate many commonly used features of Amos,
6+
including SSR, persistence, useQuery, as well as recommended project structure and data structure
7+
design. You can try the project below, view the complete source
8+
code [here](https://github.com/amos-project/amos/tree/main/examples/TodoMVC), or run it directly.
9+
10+
<iframe width="100%" height="600px" src="/amos/examples/TodoMVC"></iframe>
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* @since 2024-11-01 02:24:07
3+
* @author junbao <[email protected]>
4+
*/
5+
6+
import { TodoMVC } from '../../../../examples/TodoMVC/src/TodoMVC';
7+
8+
export default TodoMVC;

website/src/theme/ReactLiveScope/index.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
import {App} from '../../../../examples/TodoMVC/src/App';
2-
import React from 'react';
31
import * as Amos from 'amos';
42
import * as AmosReact from 'amos/react';
3+
import React from 'react';
54

65
const require = (m: string) => {
76
return {
8-
'amos': Amos,
7+
amos: Amos,
98
'amos/react': AmosReact,
10-
}[m]
11-
}
9+
}[m];
10+
};
1211

1312
// Add react-live imports you need here
1413
const ReactLiveScope = {
1514
React,
1615
...Amos,
1716
...AmosReact,
18-
TodoMVC: App,
1917
require,
2018
};
2119

0 commit comments

Comments
 (0)