3

I'm trying to get HMR to work for my knockout application and currently struggling to get HMR to reload whenever I change something inside the viewModel itself, but anything outside the scope will work.

Example:

//hmr.js

require('mymodule');

if(module.hot)
  module.hot.accept();

// mymodule.js
function myViewModel(params) {
  console.log('this will only be logged once'); // This one doesn't change after saving
}

console.log('I can get this to be logged multiple times without reload');

module.exports = {
  viewModel: myViewModel,
  template: '<div>just some stuff here</div>'
};

I'm wondering if I need to do something else to tell HMR to retrigger things inside the viewModel? currently in my main.js file I have ko.applyBindings(new AppViewModel()); which only being fired once and I have ko.components.register() inside my main.js file as well which require in my mymodule file.

Ali
  • 9,997
  • 20
  • 70
  • 105

0 Answers0