Skip to content

Commit d3933c0

Browse files
Hanks10100yxping
authored andcommitted
[WEEX-547][jsfm] Remove module proxy cache of weex.requireModule (apache#1389)
1 parent 2cc0670 commit d3933c0

File tree

1 file changed

+12
-32
lines changed

1 file changed

+12
-32
lines changed

runtime/api/WeexInstance.js

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import { isRegisteredModule, getModuleDescription } from './module'
2222
import { isRegisteredComponent } from './component'
2323
import { getTaskCenter } from '../vdom/operation'
2424

25-
const moduleProxies = {}
26-
2725
function setId (weex, id) {
2826
Object.defineProperty(weex, '[[CurrentInstanceId]]', { value: id })
2927
}
@@ -79,37 +77,19 @@ export default class WeexInstance {
7977
return
8078
}
8179

82-
// create new module proxy
83-
const proxyName = `${moduleName}#${id}`
84-
if (!moduleProxies[proxyName]) {
85-
// create registered module apis
86-
const moduleDefine = getModuleDescription(moduleName)
87-
const moduleApis = {}
88-
for (const methodName in moduleDefine) {
89-
Object.defineProperty(moduleApis, methodName, {
90-
enumerable: true,
91-
configurable: true,
92-
get: () => moduleGetter(id, moduleName, methodName),
93-
set: fn => moduleSetter(id, moduleName, methodName, fn)
94-
})
95-
}
96-
97-
// create module Proxy
98-
// if (typeof Proxy === 'function') {
99-
// moduleProxies[proxyName] = new Proxy(moduleApis, {
100-
// get (target, methodName) {
101-
// if (methodName in target) {
102-
// return target[methodName]
103-
// }
104-
// console.warn(`[JS Framework] using unregistered method "${moduleName}.${methodName}"`)
105-
// return moduleGetter(id, moduleName, methodName)
106-
// }
107-
// })
108-
// }
109-
moduleProxies[proxyName] = moduleApis
80+
// create registered module apis
81+
const moduleProxy = Object.create(null)
82+
const moduleDefine = getModuleDescription(moduleName)
83+
for (const methodName in moduleDefine) {
84+
Object.defineProperty(moduleProxy, methodName, {
85+
enumerable: true,
86+
configurable: true,
87+
get: () => moduleGetter(id, moduleName, methodName),
88+
set: fn => moduleSetter(id, moduleName, methodName, fn)
89+
})
11090
}
11191

112-
return moduleProxies[proxyName]
92+
return moduleProxy
11393
}
11494

11595
supports (condition) {
@@ -132,7 +112,7 @@ export default class WeexInstance {
132112
importScript (src, options = {}) {
133113
const id = getId(this)
134114
const taskCenter = getTaskCenter(id)
135-
return new Promise((resolve, reject) => {
115+
return new Promise(function (resolve, reject) {
136116
if (!taskCenter || typeof taskCenter.send !== 'function') {
137117
reject(new Error(`[JS Framework] Failed to import script "${src}", `
138118
+ `no taskCenter (${id}) matched.`))

0 commit comments

Comments
 (0)