browserify-hmr icon indicating copy to clipboard operation
browserify-hmr copied to clipboard

how can i define a one accept method for all enabled modules?

Open linus-amg opened this issue 9 years ago • 1 comments

i work with backbone/marionette and i want to try out what i can do to re-render a view on code/module change, or is that a bad idea?

also my setup includes gulp, browserify, rollupify, latest babel, not sure if thats of high importance. What i got so far is this:

import AppLayout from 'Views/AppLayout';
const appLayout = new AppLayout();
appLayout.render();

if (module.hot) {
  module.hot.accept('Views/AppLayout', deps => {
    console.log(deps);
  });
}

so now every time the AppLayout changes, the console log gets triggered, i guess i now can appLayout.render() again (forget the state right now..)

EDIT: id like to define some kind of switch/case for all the different kind of modules which can enter the accept, could be a view, could be a model, etc. i dont want to define the accept for every module by hand, i want to define one accept per lets say instanceof (Backbone.View, Backbone.Model, etc.)

EDIT2: also, if this is not the place to discuss that, where would the common hmr-api-discuccion-place be?

linus-amg avatar Aug 27 '16 16:08 linus-amg

Sorry for the late response!

I don't believe your use case is supported by the HMR API that browserify-hmr implements. I think the best thing for your use-case would be to make your own code transform like https://github.com/gaearon/react-transform-hmr.

Macil avatar Sep 15 '16 23:09 Macil