Skip to content

Commit d93bdc2

Browse files
committed
feat: useSelector dynamic debugValue
1 parent de1925c commit d93bdc2

File tree

23 files changed

+81
-725
lines changed

23 files changed

+81
-725
lines changed

examples/TodoMVC/src/App.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { currentUserIdBox } from './store/user.boxes';
1515
export const App = memo(() => {
1616
const userId = useSelector(currentUserIdBox);
1717
const [, gate] = useQuery(hydrate([currentUserIdBox]));
18+
1819
if (gate.isPending()) {
1920
return <div>Loading...</div>;
2021
}

examples/TodoMVC/src/components/SignIn.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
* @author junbao <[email protected]>
44
*/
55

6-
import { useDispatch, useSelector } from 'amos/react';
7-
import { memo, useState } from 'react';
6+
import { hydrate } from 'amos';
7+
import { useDispatch, useQuery, useSelector } from 'amos/react';
8+
import { Fragment, memo, useState } from 'react';
89
import { signIn } from '../store/user.actions';
910
import { userMapBox } from '../store/user.boxes';
1011

1112
export const SignIn = memo(() => {
1213
const [input, setInput] = useState('');
1314
const dispatch = useDispatch();
15+
useQuery(hydrate([userMapBox]));
1416
const userMap = useSelector(userMapBox);
1517
return (
1618
<div className="sign-in">
@@ -25,12 +27,10 @@ export const SignIn = memo(() => {
2527
<br />
2628
<span>Users:&nbsp;</span>
2729
{Array.from(userMap.values(), (u) => (
28-
<>
29-
<button key={u.id} onClick={() => dispatch(signIn(u.name))}>
30-
{u.name}
31-
</button>
30+
<Fragment key={u.id}>
31+
<button onClick={() => dispatch(signIn(u.name))}>{u.name}</button>
3232
&nbsp;
33-
</>
33+
</Fragment>
3434
))}
3535
</div>
3636
)}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@amos/root",
33
"private": true,
4-
"version": "0.3.0-beta.27",
4+
"version": "0.3.0-beta.30",
55
"license": "MIT",
66
"workspaces": [
77
"packages/*",

packages/amos-babel/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "amos-babel",
3-
"version": "0.3.0-beta.27",
3+
"version": "0.3.0-beta.30",
44
"private": true,
55
"files": [],
66
"peerDependencies": {

packages/amos-boxes/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "amos-boxes",
3-
"version": "0.3.0-beta.27",
3+
"version": "0.3.0-beta.30",
44
"private": true,
55
"files": []
66
}

packages/amos-core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "amos-core",
3-
"version": "0.3.0-beta.27",
3+
"version": "0.3.0-beta.30",
44
"private": true,
55
"files": []
66
}

packages/amos-core/src/action.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
*/
55

66
import { addFourfoldAsync, addTwiceAsync } from 'amos-testing';
7+
import { $amos } from 'amos-utils';
78
import { createStore } from './store';
89

910
describe('action', () => {
1011
it('should create action factory', () => {
1112
expect(addTwiceAsync).toBeInstanceOf(Function);
1213
expect({ ...addTwiceAsync }).toEqual({
14+
[$amos]: 'action_factory',
15+
id: addTwiceAsync(1).id,
16+
key: addTwiceAsync(1).id,
1317
type: 'amos/addTwiceAsync',
1418
select: expect.any(Function),
1519
});
@@ -18,6 +22,9 @@ describe('action', () => {
1822
const a1 = addFourfoldAsync(1);
1923
const a2 = addFourfoldAsync(2);
2024
expect(a2).toEqual({
25+
[$amos]: 'action',
26+
id: a1.id,
27+
key: a1.key,
2128
type: 'amos/addFourfoldAsync',
2229
conflictPolicy: 'always',
2330
conflictKey: void 0,

0 commit comments

Comments
 (0)