Skip to content

Commit 537f6ff

Browse files
author
Guillaume Chau
committed
Fix #142
1 parent d600e90 commit 537f6ff

File tree

5 files changed

+43
-29
lines changed

5 files changed

+43
-29
lines changed

packages/vue-component-dev-client/client/dev-client.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

22
import Vue from 'vue'
3-
import {Reload} from 'meteor/reload'
4-
import {Meteor} from 'meteor/meteor'
5-
import {Tracker} from 'meteor/tracker'
6-
import {Autoupdate} from 'meteor/autoupdate'
7-
import {ReactiveVar} from 'meteor/reactive-var'
3+
import { Reload } from 'meteor/reload'
4+
import { Meteor } from 'meteor/meteor'
5+
import { Tracker } from 'meteor/tracker'
6+
import { Autoupdate } from 'meteor/autoupdate'
7+
import { ReactiveVar } from 'meteor/reactive-var'
88
import VueHot1 from './vue-hot'
99
import VueHot2 from './vue2-hot'
1010

@@ -112,6 +112,7 @@ Meteor.startup(function () {
112112
while (regResult = jsImportsReg.exec(js)) {
113113
args.push(regResult[2])
114114
}
115+
console.log(args, js)
115116
args.push(function (require, exports, module) {
116117
try {
117118
eval(js)
@@ -161,12 +162,17 @@ Meteor.startup(function () {
161162
_socket.on('render', function ({hash, template, path}) {
162163
if (vueVersion === 2) {
163164
console.log('[HMR] Rerendering ' + path)
164-
// console.log(template)
165-
var obj
166-
eval(`obj = ${template};`)
167-
// console.log(obj)
168-
VueHotReloadApi.rerender(hash, obj)
169-
_suppressNextReload = true
165+
console.log(template)
166+
let error = true
167+
try {
168+
var obj
169+
eval(`obj = ${template};`)
170+
// console.log(obj)
171+
VueHotReloadApi.rerender(hash, obj)
172+
} catch (e) {
173+
error = true
174+
}
175+
_suppressNextReload = !error
170176
}
171177
})
172178

packages/vue-component-dev-client/client/vue2-hot.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ var Vue // late bind
22
var version
33
var map = window.__VUE_HOT_MAP__ = Object.create(null)
44
var installed = false
5-
var isBrowserify = false
65
var initHookName = 'beforeCreate'
76

87
exports.install = function (vue, browserify) {
@@ -11,7 +10,6 @@ exports.install = function (vue, browserify) {
1110

1211
Vue = vue.__esModule ? vue.default : vue
1312
version = Vue.version.split('.').map(Number)
14-
isBrowserify = browserify
1513

1614
// compat with < 2.0.0-alpha.7
1715
if (Vue.config._lifecycleHooks.indexOf('init') > -1) {
@@ -45,7 +43,7 @@ exports.createRecord = function (id, options) {
4543
makeOptionsHot(id, options)
4644
map[id] = {
4745
Ctor: Vue.extend(options),
48-
instances: []
46+
instances: [],
4947
}
5048
}
5149

@@ -86,35 +84,45 @@ function injectHook (options, name, hook) {
8684

8785
function tryWrap (fn) {
8886
return function (id, arg) {
89-
try {
90-
return fn(id, arg)
91-
} catch (e) {
87+
try { fn(id, arg) } catch (e) {
9288
console.error(e)
9389
console.warn('Something went wrong during Vue component hot-reload. Full reload required.')
9490
throw e
9591
}
9692
}
9793
}
9894

99-
exports.rerender = tryWrap(function (id, fns) {
95+
exports.rerender = tryWrap(function (id, options) {
10096
var record = map[id]
101-
record.Ctor.options.render = fns.render
102-
record.Ctor.options.staticRenderFns = fns.staticRenderFns
97+
console.log(id, record, map)
98+
if (typeof options === 'function') {
99+
options = options.options
100+
}
101+
console.log(options)
102+
record.Ctor.options.render = options.render
103+
record.Ctor.options.staticRenderFns = options.staticRenderFns
103104
record.instances.slice().forEach(function (instance) {
104-
instance.$options.render = fns.render
105-
instance.$options.staticRenderFns = fns.staticRenderFns
105+
instance.$options.render = options.render
106+
instance.$options.staticRenderFns = options.staticRenderFns
106107
instance._staticTrees = [] // reset static trees
107108
instance.$forceUpdate()
108109
})
109110
})
110111

111112
exports.reload = tryWrap(function (id, options) {
113+
if (typeof options === 'function') {
114+
options = options.options
115+
}
112116
makeOptionsHot(id, options)
113117
var record = map[id]
114-
record.Ctor.extendOptions = options
115-
var newCtor = Vue.extend(options)
118+
if (version[1] < 2) {
119+
// preserve pre 2.2 behavior for global mixin handling
120+
record.Ctor.extendOptions = options
121+
}
122+
var newCtor = record.Ctor.super.extend(options)
116123
record.Ctor.options = newCtor.options
117124
record.Ctor.cid = newCtor.cid
125+
record.Ctor.prototype = newCtor.prototype
118126
if (newCtor.release) {
119127
// temporary global mixin strategy used in < 2.0.0-alpha.6
120128
newCtor.release()
@@ -125,8 +133,8 @@ exports.reload = tryWrap(function (id, options) {
125133
instance.$vnode.context.$forceUpdate()
126134
} else {
127135
console.warn('Root or manually mounted instance modified. Full reload required.')
128-
needsReload = true;
136+
needsReload = true
129137
}
130-
});
138+
})
131139
return needsReload
132140
})

packages/vue-component-dev-client/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'akryum:vue-component-dev-client',
3-
version: '0.2.6',
3+
version: '0.2.7',
44
summary: 'Hot-reloading client for vue components',
55
git: 'https://github.com/Akryum/meteor-vue-component',
66
documentation: 'README.md',

packages/vue-component/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package.describe({
22
name: 'akryum:vue-component',
3-
version: '0.8.13',
3+
version: '0.8.14',
44
summary: 'VueJS single-file components that hot-reloads',
55
git: 'https://github.com/Akryum/meteor-vue-component',
66
documentation: 'README.md'

packages/vue-component/plugin/vue-compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ function generateJs (vueId, inputFile, compileResult, isHotReload = false) {
596596

597597
if (!isHotReload) {
598598
// Hot-reloading
599-
if (isDev && Meteor.isClient) {
599+
if (isDev && inputFile.getArch().indexOf('web') !== -1) {
600600
js += `\nif(!window.__vue_hot__){
601601
window.__vue_hot_pending__ = window.__vue_hot_pending__ || {};
602602
window.__vue_hot_pending__['${vueId}'] = __vue_script__;

0 commit comments

Comments
 (0)