This repository has been archived by the owner on Jun 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add optional selector support * chore: remove unnecessary code * chore: use lodash.isequal to filter changes * test: add test cases
- Loading branch information
Showing
21 changed files
with
130 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
"src" | ||
], | ||
"dependencies": { | ||
"globby": "7.1.1" | ||
"globby": "7.1.1", | ||
"lodash.isequal": "^4.5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// @ts-ignore | ||
export { default as isEqual } from 'lodash.isequal'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import { useModel } from './.umi/useModel'; | ||
|
||
export default () => { | ||
const ret = useModel('user'); | ||
return (<> | ||
<h2 data-testid="error">component should not break</h2> | ||
<h2 data-testid="ret">{`ret is: ${ret}`}</h2> | ||
</>); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
|
||
export default async function ({ getByTestId }) { | ||
expect(getByTestId('error').innerHTML).toEqual('component should not break'); | ||
expect(getByTestId('ret').innerHTML).toEqual('ret is: undefined'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import { useModel } from './.umi/useModel'; | ||
|
||
export default () => { | ||
const { switchRole } = useModel('auth'); | ||
const message = useModel('message'); | ||
return (<> | ||
<h2 data-testid="message">{message}</h2> | ||
<button onClick={switchRole}>switch</button> | ||
</>); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useState } from 'react'; | ||
|
||
export default () => { | ||
const [ role, setRole ] = useState('admin'); | ||
const switchRole = () => setRole(r => r === 'admin' ? 'user' : 'admin') | ||
return { role, switchRole }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useState } from 'react'; | ||
import { useModel } from '../.umi/useModel'; | ||
|
||
export default () => { | ||
const { role } = useModel('auth'); | ||
return role === 'admin' ? 'Hello admin' : 'Hello user'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
export default async function ({ getByTestId, getByText, fireEvent }) { | ||
expect(getByTestId('message').innerHTML).toEqual('Hello admin'); | ||
fireEvent.click(getByText('switch')); | ||
expect(getByTestId('message').innerHTML).toEqual('Hello user'); | ||
fireEvent.click(getByText('switch')); | ||
expect(getByTestId('message').innerHTML).toEqual('Hello admin'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import { useModel } from './.umi/useModel'; | ||
|
||
export default () => { | ||
const ret = useModel('name'); | ||
return (<> | ||
<h2 data-testid="count">{`${ret}`}</h2> | ||
</>); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { useState } from 'react'; | ||
|
||
export default () => { | ||
const data = {}; | ||
return { name: data.user.name }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
export default async function ({ getByTestId }) { | ||
console.error = jest.fn(); | ||
// expect(console.error).toHaveBeenCalledTimes(1); | ||
expect(getByTestId('count').innerHTML).toEqual('undefined'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import { useModel } from './.umi/useModel'; | ||
|
||
export default () => { | ||
const { isAdult, name } = useModel('user', user => ({ name: user.name, isAdult: user.age > 18 })); | ||
return (<> | ||
<h2 data-testid="user">{name} is {isAdult ? 'an adult' : 'a teen'}</h2> | ||
</>); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useState } from 'react'; | ||
|
||
export default () => { | ||
return { | ||
name: 'Troy', | ||
email: '[email protected]', | ||
gender: 'male', | ||
height: '6\'2', | ||
age: 24, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
export default async function ({ getByTestId }) { | ||
expect(getByTestId('user').innerHTML).toEqual('Troy is an adult'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters