apache / incubator-weex-loader

Apache License 2.0
65 stars 32 forks source link

Hot Module Replacement? #54

Open dts opened 7 years ago

dts commented 7 years ago

I have a pretty technical pickle I've waded myself into. I've gotten myself in an insane project of trying to get hot loading working in Weex. I'm so close I can taste it - but I'm missing something fundamental and I've already spent more time than I can justify. The steps I've already done:

0) Patched an existing ObjC eventsource client to support HMR (It didn't work with large frames. sigh).

1) Created a "Weex" target mode for Webpack (by cloning the webworker target and changing things around to use the stream.fetch() mechanism) so that the webpack modules can fetch things reasonably.

2) Created a weex-aware HMR client (pretty easy, if you throw away all checks & safety)

3) Created a layer on top of the weex-loader that turns on hot reloading on a per-file basis

4) Copypasta'd vue-hot-reload-api, and am trying to modify it to work. I'm stuck trying to understand what's going on here:

if (version[1] < 2) {
  // preserve pre 2.2 behavior for global mixin handling
  record.Ctor.extendOptions = options
}

var newCtor = record.Ctor.super.extend(options);
// var newCtor = Vue.extend(options)

record.Ctor.options = newCtor.options

I don't understand the "pre 2.2 behavior" note, and I cant find any references to extendOptions in the docs. I also don't understand why the super.extend( call doesn't work - the render call in newCtor.options afterwards is the same as record.Ctor, not the same as options.render. What's going on? What am I missing? How soon is someone competent going to add hot-module-replacement-aware Weex support?

It occurs to me after sleeping on it, that part of the issue could be that I'm using the version of the WeexSDK that ships with weex-hackernews, and not the latest (presumably newer versions of WeexSDK come with more modern versions of Vue).

dts commented 7 years ago

I think I've figured it out. I believe something inside __weex_require_module__ is causing the options hash to have the _Ctor of the original element. By deleting the _Ctor element off of options before extending it, hot module replacement works like a charm.