Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dgeibi/dva-hot
HMR plugin for dva without babel
https://github.com/dgeibi/dva-hot
dva hmr-plugin webpack
Last synced: 1 day ago
JSON representation
HMR plugin for dva without babel
- Host: GitHub
- URL: https://github.com/dgeibi/dva-hot
- Owner: dgeibi
- License: isc
- Created: 2018-01-11T10:53:45.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-06-07T14:36:12.000Z (over 5 years ago)
- Last Synced: 2024-12-12T15:02:46.428Z (15 days ago)
- Topics: dva, hmr-plugin, webpack
- Language: JavaScript
- Homepage:
- Size: 352 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dva-hot
[![version][version-badge]][package]
HMR plugin for dva without babel inspired by [babel-plugin-dva-hmr](https://github.com/dvajs/babel-plugin-dva-hmr) and [react-hot-loader](https://github.com/gaearon/react-hot-loader).
## Install
``` sh
$ npm install dva-hot
```## Usage
**Patch App**
``` js
import hot from 'dva-hot'
import dva from 'dva'const app = dva()
hot.patch(app) // you must patch `app` before calling app.{model,router,start}
app.model(require('./models/a').default)
app.model(require('./models/b').default)
app.router(require('./router').default)app.start('#root')
```After `[email protected]`, the usage below should work:
``` js
import hot from 'dva-hot'
import dva from 'dva'
import { createElement } from 'react'
import { render } from 'react-dom'const app = dva()
hot.patch(app) // you can pass container to hot.patch like `hot.patch(app, container)`
app.model(require('./models/a').default)
app.model(require('./models/b').default)
app.router(require('./router').default)// After [email protected]: pass container for HMR
render(createElement(app.start()), hot.setContainer('#root'))
// or
// render(createElement(app.start()), hot.setContainer(document.querySelector('#root')))
```**Self-accepted Router**
``` js
import React from 'react'
import { routerRedux } from 'dva/router'
import { renderRoutes } from 'react-router-config'
import hot from 'dva-hot'
import routes from '../routes'const { ConnectedRouter } = routerRedux
function RouterConfig({ history }) {
return {renderRoutes(routes)}
}export default hot.router(module)(RouterConfig)
```**Self-accepted Model**
``` js
import hot from 'dva-hot'export default hot.model(module)({
namespace: 'a-dva-model'
state: [],
// upgrade to [email protected] if you use models that without `reducers`
})
```## LICENSE
[ISC](LICENSE)
[version-badge]: https://img.shields.io/npm/v/dva-hot.svg
[package]: https://www.npmjs.com/package/dva-hot