Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix umi plugin dva #143

Merged
merged 2 commits into from
Feb 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/with-dva/src/models/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@ export default {
};
},
},
effects: {
*throwError() {
throw new Error('hi error');
},
},
};
9 changes: 9 additions & 0 deletions examples/with-dva/src/pages/index/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ function App(props) {
>
Set Title
</Button>
<Button
onClick={() => {
props.dispatch({
type: 'global/throwError',
});
}}
>
Throw error
</Button>
<br />
<div>
<Link to="/list">Go to list.html</Link>
Expand Down
8 changes: 8 additions & 0 deletions examples/with-dva/src/plugins/onError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { message } from 'antd';

export default {
onError(err) {
err.preventDefault();
message.error(err.message);
},
};
12 changes: 10 additions & 2 deletions packages/umi-plugin-dva/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export default function(api) {
}

function getPlugins() {
const pluginPaths = globby.sync('../../plugins/*.js', {
const pluginPaths = globby.sync('plugins/*.js', {
cwd: paths.absSrcPath,
});
return pluginPaths
.map(path =>
`
app.use(require('./${path}').default);
app.use(require('../../${path}').default);
`.trim(),
)
.join('\r\n');
Expand Down Expand Up @@ -83,4 +83,12 @@ ReactDOM.render(React.createElement(
};
return memo;
});

api.register('modifyPageWatchers', ({ memo }) => {
return [
...memo,
join(paths.absSrcPath, 'models'),
join(paths.absSrcPath, 'plugins'),
];
});
}