Skip to content

Commit

Permalink
feat: make useModel default to models namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
x8lucas8x committed Aug 8, 2019
1 parent a26f71f commit f3cd4aa
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions __tests__/hooks/useModel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import {combineModelReducers, Model, useModel} from '../../src';
import {createStore} from 'redux';
import {combineReducers, createStore} from 'redux';
import {Provider} from 'react-redux';
import {mount} from 'enzyme';

Expand All @@ -26,7 +26,7 @@ describe('useModel', () => {
scopes: [],
fields: {},
});
store = createStore(combineModelReducers([articleModel]));
store = createStore(combineReducers({ models: combineModelReducers([articleModel])}));
store.dispatch(articleModel.actions().set(articleModel.defaultScope, 1, [{id: 1, title: 'title'}]));
component = mount(
<Provider store={store}>
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Data } from '../data';
export function useModel(model: Model, namespace: string=''): Record<string, (ScopeId) => any> {
const dispatch: DispatchProp = useDispatch();
const state = useSelector(
(state: Record<string, any>) => namespace === '' ? state : state['models']
(state: Record<string, any>) => namespace === '' ? state['models'] : state[namespace]
) as object;

return React.useMemo(() => {
Expand Down

0 comments on commit f3cd4aa

Please sign in to comment.