Macil / browserify-hmr

Hot Module Replacement plugin for Browserify
MIT License
373 stars 26 forks source link

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

Open linus-amg opened 8 years ago

linus-amg commented 8 years ago

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?

Macil commented 7 years ago

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.