feat: remove loading from model and use DvaModel instead of redundant types such as kAModelType (#47)
* feat: use DvaModel instead of redundant types such as kAModelType * feat: set the type for registerServer * feat: remove loading from model
This commit is contained in:
@@ -1,15 +1,8 @@
|
||||
import React from 'react';
|
||||
import { connect, Dispatch } from 'umi';
|
||||
import type { chatModelState } from './model'
|
||||
import { useSelector } from 'umi';
|
||||
|
||||
interface chatProps {
|
||||
chatModel: chatModelState;
|
||||
dispatch: Dispatch
|
||||
}
|
||||
|
||||
const View: React.FC<chatProps> = ({ chatModel, dispatch }) => {
|
||||
const { name } = chatModel;
|
||||
return <div>chat:{name} </div>;
|
||||
const Chat = () => {
|
||||
const { name } = useSelector((state: any) => state.chatModel);
|
||||
return <div>chat:{name} </div>;
|
||||
};
|
||||
|
||||
export default connect(({ chatModel, loading }) => ({ chatModel, loading }))(View);
|
||||
export default Chat;
|
||||
|
||||
@@ -1,46 +1,32 @@
|
||||
import { Effect, Reducer, Subscription } from 'umi';
|
||||
import { DvaModel } from 'umi';
|
||||
|
||||
export interface chatModelState {
|
||||
name: string;
|
||||
export interface ChatModelState {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface chatModelType {
|
||||
namespace: 'chatModel';
|
||||
state: chatModelState;
|
||||
effects: {
|
||||
query: Effect;
|
||||
};
|
||||
reducers: {
|
||||
save: Reducer<chatModelState>;
|
||||
};
|
||||
subscriptions: { setup: Subscription };
|
||||
}
|
||||
|
||||
const Model: chatModelType = {
|
||||
namespace: 'chatModel',
|
||||
state: {
|
||||
name: 'kate',
|
||||
const model: DvaModel<ChatModelState> = {
|
||||
namespace: 'chatModel',
|
||||
state: {
|
||||
name: 'kate',
|
||||
},
|
||||
reducers: {
|
||||
save(state, action) {
|
||||
return {
|
||||
...state,
|
||||
...action.payload,
|
||||
};
|
||||
},
|
||||
|
||||
effects: {
|
||||
*query({ payload }, { call, put }) { },
|
||||
},
|
||||
reducers: {
|
||||
save(state, action) {
|
||||
return {
|
||||
...state,
|
||||
...action.payload,
|
||||
};
|
||||
},
|
||||
},
|
||||
subscriptions: {
|
||||
setup({ dispatch, history }) {
|
||||
return history.listen((query) => {
|
||||
console.log(query)
|
||||
|
||||
});
|
||||
},
|
||||
},
|
||||
subscriptions: {
|
||||
setup({ dispatch, history }) {
|
||||
return history.listen((query) => {
|
||||
console.log(query);
|
||||
});
|
||||
},
|
||||
},
|
||||
effects: {
|
||||
*query({ payload }, { call, put }) {},
|
||||
},
|
||||
};
|
||||
|
||||
export default Model;
|
||||
export default model;
|
||||
|
||||
Reference in New Issue
Block a user