码迷,mamicode.com
首页 > 其他好文 > 详细

[MST] Restore the Model Tree State using Hot Module Reloading when Model Definitions Change

时间:2018-01-29 00:25:08      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:gpo   roo   color   run   mode   pos   init   list   rap   

n this lesson, we will set up Hot Module Reloading(HMR), making it possible to load new definitions for React components and MST models and apply them to a running application.

In this lesson you will learn:

  • How HMR roughly works
  • How to accept changes to components
  • How to accept changes to changing model definitions, while keeping state
let wishList = WishList.create(initialState)

function renderApp() {
    ReactDOM.render(<App wishList={wishList} />, document.getElementById("root"))
}

renderApp()

if (module.hot) {
    module.hot.accept(["./components/App"], () => {
        // new components
        renderApp()
    })

    module.hot.accept(["./models/WishList"], () => {
        // new model definitions
        const snapshot = getSnapshot(wishList)
        wishList = WishList.create(snapshot)
        renderApp()
    })
}

 

[MST] Restore the Model Tree State using Hot Module Reloading when Model Definitions Change

标签:gpo   roo   color   run   mode   pos   init   list   rap   

原文地址:https://www.cnblogs.com/Answer1215/p/8372792.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!