Skip to content
This repository was archived by the owner on Feb 12, 2022. It is now read-only.

Commit 8a1b976

Browse files
authored
Generic is added to show action (#110)
* Generic is added to `show` action * Fix test
1 parent 7b93e65 commit 8a1b976

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default combineReducers({
6262
})
6363
```
6464

65-
## show(name, props)
65+
## show(name, props) | show<T>(name, props: T)
6666

6767
The show modal action creator.
6868

@@ -71,6 +71,14 @@ The show modal action creator.
7171
* `name`(String) The name of modal to show.
7272
* `props`(Object) Props pass to your modal.
7373

74+
### Example
75+
76+
```javascript
77+
import { MyModalProps } from '...'
78+
79+
show<MyModalProps>('modalName', {prop1: 'example'})
80+
```
81+
7482
## hide(name)
7583

7684
The hide modal action creator.

src/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { SHOW, HIDE, DESTROY } from './actionTypes';
22

3-
export function show(modal: string, props = {}) {
3+
export function show<T = {}>(modal: string, props?: T) {
44
return {
55
type: SHOW,
66
payload: {
77
modal,
8-
props,
8+
props: props || {},
99
},
1010
};
1111
}

test/connectModal.spec.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ describe('connectModal', () => {
3939
WrappedMyModal = SampleModal;
4040
});
4141

42+
it('works correctly with generic', () => {
43+
show<{ test: boolean }>('myModal', { test: true });
44+
});
45+
4246
it('render null at first mount', () => {
4347
const finalReducer = () => ({ modal: {} });
4448
const store = createStore(finalReducer);
@@ -49,7 +53,7 @@ describe('connectModal', () => {
4953
</Provider>
5054
);
5155

52-
expect(wrapper.html()).toEqual('');
56+
expect(wrapper.html()).toEqual(null);
5357
});
5458

5559
it('mount modal after dispatch show action', () => {
@@ -62,7 +66,7 @@ describe('connectModal', () => {
6266
</Provider>
6367
);
6468

65-
expect(wrapper.html()).toEqual('');
69+
expect(wrapper.html()).toEqual(null);
6670

6771
store.dispatch(show('myModal'));
6872
wrapper.update();
@@ -86,7 +90,7 @@ describe('connectModal', () => {
8690
store.dispatch(show('myModal'));
8791
store.dispatch(hide('myModal'));
8892

89-
expect(wrapper.html()).toEqual('');
93+
expect(wrapper.html()).toEqual(null);
9094
});
9195

9296
it('can mount modal reducer to a custom location in state', () => {
@@ -103,7 +107,7 @@ describe('connectModal', () => {
103107
</Provider>
104108
);
105109

106-
expect(wrapper.html()).toEqual('');
110+
expect(wrapper.html()).toEqual(null);
107111

108112
store.dispatch(show('myModal'));
109113
wrapper.update();

0 commit comments

Comments
 (0)