首页 > 其他 > 详细

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

时间:2018-01-29 00:13:19      阅读:279      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!