You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@weex.apache.org by GitBox <gi...@apache.org> on 2018/08/02 07:40:36 UTC

[GitHub] Hanks10100 closed pull request #1389: [WEEX-547][jsfm] Remove module proxy cache of weex.requireModule

Hanks10100 closed pull request #1389: [WEEX-547][jsfm] Remove module proxy cache of weex.requireModule
URL: https://github.com/apache/incubator-weex/pull/1389
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/runtime/api/WeexInstance.js b/runtime/api/WeexInstance.js
index 38dab1e9df..fda0c3f6ad 100644
--- a/runtime/api/WeexInstance.js
+++ b/runtime/api/WeexInstance.js
@@ -22,8 +22,6 @@ import { isRegisteredModule, getModuleDescription } from './module'
 import { isRegisteredComponent } from './component'
 import { getTaskCenter } from '../vdom/operation'
 
-const moduleProxies = {}
-
 function setId (weex, id) {
   Object.defineProperty(weex, '[[CurrentInstanceId]]', { value: id })
 }
@@ -79,37 +77,19 @@ export default class WeexInstance {
       return
     }
 
-    // create new module proxy
-    const proxyName = `${moduleName}#${id}`
-    if (!moduleProxies[proxyName]) {
-      // create registered module apis
-      const moduleDefine = getModuleDescription(moduleName)
-      const moduleApis = {}
-      for (const methodName in moduleDefine) {
-        Object.defineProperty(moduleApis, methodName, {
-          enumerable: true,
-          configurable: true,
-          get: () => moduleGetter(id, moduleName, methodName),
-          set: fn => moduleSetter(id, moduleName, methodName, fn)
-        })
-      }
-
-      // create module Proxy
-      // if (typeof Proxy === 'function') {
-      //   moduleProxies[proxyName] = new Proxy(moduleApis, {
-      //     get (target, methodName) {
-      //       if (methodName in target) {
-      //         return target[methodName]
-      //       }
-      //       console.warn(`[JS Framework] using unregistered method "${moduleName}.${methodName}"`)
-      //       return moduleGetter(id, moduleName, methodName)
-      //     }
-      //   })
-      // }
-      moduleProxies[proxyName] = moduleApis
+    // create registered module apis
+    const moduleProxy = Object.create(null)
+    const moduleDefine = getModuleDescription(moduleName)
+    for (const methodName in moduleDefine) {
+      Object.defineProperty(moduleProxy, methodName, {
+        enumerable: true,
+        configurable: true,
+        get: () => moduleGetter(id, moduleName, methodName),
+        set: fn => moduleSetter(id, moduleName, methodName, fn)
+      })
     }
 
-    return moduleProxies[proxyName]
+    return moduleProxy
   }
 
   supports (condition) {
@@ -132,7 +112,7 @@ export default class WeexInstance {
   importScript (src, options = {}) {
     const id = getId(this)
     const taskCenter = getTaskCenter(id)
-    return new Promise((resolve, reject) => {
+    return new Promise(function (resolve, reject) {
       if (!taskCenter || typeof taskCenter.send !== 'function') {
         reject(new Error(`[JS Framework] Failed to import script "${src}", `
           + `no taskCenter (${id}) matched.`))


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services