import { Component, createElement } from 'rax';
import dva, { connect } from '@ali/rax-dva';
const app = new dva();
const sleep = ms => new Promise(r => setTimeout(r, ms));
app.model({
namespace: 'global',
state: {
loading: true,
},
subscriptions: {
setup({ dispatch }) {
dispatch({
type: 'init',
});
},
},
effects: {
* init(_, { put }) {
yield sleep(3000);
yield put({
type: 'toggleLoading',
payload: false,
});
},
},
reducers: {
toggleLoading: (state, { payload }) => {
return {
...state,
loading: payload,
};
},
},
});
const App = (props) => {
const { loading } = props;
return (
<div>{ loading ? 'Loading' : 'Hello world' }</div>
);
};
const ConnectedApp = connect(({
global,
dispatch,
}) => {
return {
loading: global.loading,
dispatch,
};
})(App);
app.router(() => <ConnectedApp />);
app.start();