Skip to content

Commit

Permalink
feat: useSelector dynamic debugValue
Browse files Browse the repository at this point in the history
  • Loading branch information
acrazing committed Nov 1, 2024
1 parent de1925c commit 4ef289f
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 711 deletions.
1 change: 1 addition & 0 deletions examples/TodoMVC/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { currentUserIdBox } from './store/user.boxes';
export const App = memo(() => {
const userId = useSelector(currentUserIdBox);
const [, gate] = useQuery(hydrate([currentUserIdBox]));

if (gate.isPending()) {
return <div>Loading...</div>;
}
Expand Down
14 changes: 7 additions & 7 deletions examples/TodoMVC/src/components/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
* @author junbao <[email protected]>
*/

import { useDispatch, useSelector } from 'amos/react';
import { memo, useState } from 'react';
import { hydrate } from 'amos';
import { useDispatch, useQuery, useSelector } from 'amos/react';
import { Fragment, 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();
useQuery(hydrate([userMapBox]));
const userMap = useSelector(userMapBox);
return (
<div className="sign-in">
Expand All @@ -25,12 +27,10 @@ export const SignIn = memo(() => {
<br />
<span>Users:&nbsp;</span>
{Array.from(userMap.values(), (u) => (
<>
<button key={u.id} onClick={() => dispatch(signIn(u.name))}>
{u.name}
</button>
<Fragment key={u.id}>
<button onClick={() => dispatch(signIn(u.name))}>{u.name}</button>
&nbsp;
</>
</Fragment>
))}
</div>
)}
Expand Down
7 changes: 7 additions & 0 deletions packages/amos-core/src/action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
*/

import { addFourfoldAsync, addTwiceAsync } from 'amos-testing';
import { $amos } from 'amos-utils';
import { createStore } from './store';

describe('action', () => {
it('should create action factory', () => {
expect(addTwiceAsync).toBeInstanceOf(Function);
expect({ ...addTwiceAsync }).toEqual({
[$amos]: 'action_factory',
id: addTwiceAsync(1).id,
key: addTwiceAsync(1).id,
type: 'amos/addTwiceAsync',
select: expect.any(Function),
});
Expand All @@ -18,6 +22,9 @@ describe('action', () => {
const a1 = addFourfoldAsync(1);
const a2 = addFourfoldAsync(2);
expect(a2).toEqual({
[$amos]: 'action',
id: a1.id,
key: a1.key,
type: 'amos/addFourfoldAsync',
conflictPolicy: 'always',
conflictKey: void 0,
Expand Down
Loading

0 comments on commit 4ef289f

Please sign in to comment.