Evan You 9 лет назад
Родитель
Сommit
d99637b7f3
2 измененных файлов с 8 добавлено и 17 удалено
  1. 8 9
      src/platforms/weex/framework.js
  2. 0 8
      test/weex/runtime/framework.spec.js

+ 8 - 9
src/platforms/weex/framework.js

@@ -114,8 +114,8 @@ export function createInstance (
  * @param {string} instanceId
  */
 export function destroyInstance (instanceId) {
-  const instance = instances[instanceId] || {}
-  if (instance.app instanceof instance.Vue) {
+  const instance = instances[instanceId]
+  if (instance && instance.app instanceof instance.Vue) {
     instance.app.$destroy()
   }
   delete instances[instanceId]
@@ -129,8 +129,8 @@ export function destroyInstance (instanceId) {
  * @param {object} data
  */
 export function refreshInstance (instanceId, data) {
-  const instance = instances[instanceId] || {}
-  if (!(instance.app instanceof instance.Vue)) {
+  const instance = instances[instanceId]
+  if (!instance || !(instance.app instanceof instance.Vue)) {
     return new Error(`refreshInstance: instance ${instanceId} not found!`)
   }
   for (const key in data) {
@@ -145,8 +145,8 @@ export function refreshInstance (instanceId, data) {
  * @param {string} instanceId
  */
 export function getRoot (instanceId) {
-  const instance = instances[instanceId] || {}
-  if (!(instance.app instanceof instance.Vue)) {
+  const instance = instances[instanceId]
+  if (!instance || !(instance.app instanceof instance.Vue)) {
     return new Error(`getRoot: instance ${instanceId} not found!`)
   }
   return instance.app.$el.toJSON()
@@ -160,8 +160,8 @@ export function getRoot (instanceId) {
  * @param {array}  tasks
  */
 export function receiveTasks (instanceId, tasks) {
-  const instance = instances[instanceId] || {}
-  if (!(instance.app instanceof instance.Vue)) {
+  const instance = instances[instanceId]
+  if (!instance || !(instance.app instanceof instance.Vue)) {
     return new Error(`receiveTasks: instance ${instanceId} not found!`)
   }
   const { callbacks, document } = instance
@@ -275,7 +275,6 @@ function createVueModuleInstance (instanceId, moduleGetter) {
    * @return {object}
    */
   Vue.prototype.$getConfig = function () {
-    const instance = instances[this.$instanceId] || {}
     if (instance.app instanceof Vue) {
       return instance.config
     }

+ 0 - 8
test/weex/runtime/framework.spec.js

@@ -608,8 +608,6 @@ describe('framework APIs', () => {
       type: 'div',
       children: [{ type: 'text', attr: { value: 'Hello' }}]
     })
-    // ensure base Vue is unaffected
-    expect(framework.Vue.options.components.test).toBeUndefined()
   })
 
   it('adding prototype methods', () => {
@@ -632,8 +630,6 @@ describe('framework APIs', () => {
       type: 'div',
       children: [{ type: 'text', attr: { value: 'Hello' }}]
     })
-    // ensure base Vue is unaffected
-    expect(framework.Vue.prototype.$test).toBeUndefined()
   })
 
   it('using global mixins', () => {
@@ -662,9 +658,5 @@ describe('framework APIs', () => {
       type: 'div',
       children: [{ type: 'text', attr: { value: 'Hello' }}]
     })
-    const vm = new framework.Vue({
-      data: { test: false }
-    })
-    expect(vm.test).toBe(false)
   })
 })