diff --git a/examples/TodoMVC/src/components/SignIn.tsx b/examples/TodoMVC/src/components/SignIn.tsx index 76542ad..1a87bc6 100644 --- a/examples/TodoMVC/src/components/SignIn.tsx +++ b/examples/TodoMVC/src/components/SignIn.tsx @@ -3,13 +3,15 @@ * @author junbao */ -import { useDispatch } from 'amos/react'; +import { useDispatch, useSelector } from 'amos/react'; import { memo, useState } from 'react'; import { signIn } from '../store/user.actions'; +import { userMapBox } from '../store/user.boxes'; export const SignIn = memo(() => { const [input, setInput] = useState(''); const dispatch = useDispatch(); + const userMap = useSelector(userMapBox); return (
setInput(e.target.value)} /> @@ -17,6 +19,21 @@ export const SignIn = memo(() => { +
+ {userMap.size() > 0 && ( +
+
+ Users:  + {Array.from(userMap.values(), (u) => ( + <> + +   + + ))} +
+ )}
); }); diff --git a/examples/TodoMVC/src/main.tsx b/examples/TodoMVC/src/main.tsx index 47c6dfe..c2fdc60 100644 --- a/examples/TodoMVC/src/main.tsx +++ b/examples/TodoMVC/src/main.tsx @@ -4,21 +4,11 @@ import { StrictMode } from 'react'; import { createRoot } from 'react-dom/client'; import { App } from './App'; import './index.css'; -import { hashCode } from './store/todo.boxes'; -import { currentUserIdBox, userMapBox } from './store/user.boxes'; - -const userId = hashCode('Amos'); const store = createStore( { name: 'Amos - TodoMVC', devtools: true, - preloadedState: { - [currentUserIdBox.key]: userId, - [userMapBox.key]: { - [userId]: { id: userId, name: 'Amos' }, - }, - }, }, withPersist({ storage: new IDBStorage('todo', 'todo'), diff --git a/examples/TodoMVC/src/store/user.boxes.ts b/examples/TodoMVC/src/store/user.boxes.ts index 95ed115..e4180ac 100644 --- a/examples/TodoMVC/src/store/user.boxes.ts +++ b/examples/TodoMVC/src/store/user.boxes.ts @@ -4,6 +4,7 @@ */ import { box, Record, recordMapBox, signal } from 'amos'; +import { hashCode } from './todo.boxes'; export interface UserModel { id: number; @@ -24,7 +25,9 @@ export const signOutSignal = signal('user.signOut'); export const signInSignal = signal('user.signIn'); -export const userMapBox = recordMapBox('users', UserRecord, 'id'); +export const userMapBox = recordMapBox('users', UserRecord, 'id').setInitialState((s) => { + return s.mergeItem(hashCode('Amos'), { name: 'Amos' }); +}); userMapBox.subscribe(signOutSignal, (state, data) => { if (!data.keepData) { @@ -33,4 +36,4 @@ userMapBox.subscribe(signOutSignal, (state, data) => { return state; }); -export const currentUserIdBox = box('users.currentUserId', 0); +export const currentUserIdBox = box('users.currentUserId', hashCode('Amos')); diff --git a/scripts/check_deps.ts b/scripts/check_deps.ts index 56cb4d7..c6db775 100644 --- a/scripts/check_deps.ts +++ b/scripts/check_deps.ts @@ -21,7 +21,7 @@ export const check_deps = autorun( const pj = await fs.readJSON(`packages/${pkg}/package.json`); const files = await glob(`packages/${pkg}/src/**/*.{ts,tsx}`); for (const f of files) { - const isDev = f.includes('.spec.'); + const isDev = f.includes('.spec.') || f.includes('test'); const d = await fs.readFile(f, 'utf-8'); const ms = d.matchAll(/ from ['"]([^'"]+)['"]/g); for (const m of ms) { @@ -76,7 +76,7 @@ export const check_deps = autorun( console.error(`%s should not dev dependents on amos.`, pkg); } if (pkg === 'amos-utils') { - const bad = deps.concat(devDeps).filter((d) => d.startsWith('amos')); + const bad = deps.filter((d) => d.startsWith('amos')); if (bad.length) { console.error('amos-utils no amos deps: ', bad.join(', ')); }