Browse Source

fix: add prefix to getUniqId

Gerald 8 years ago
parent
commit
486f2375c9
2 changed files with 6 additions and 6 deletions
  1. 2 2
      src/common/index.js
  2. 4 4
      src/injected/web/index.js

+ 2 - 2
src/common/index.js

@@ -75,8 +75,8 @@ export function zfill(input, length) {
   return num;
 }
 
-export function getUniqId() {
-  return Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
+export function getUniqId(prefix) {
+  return (prefix || '') + Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
 }
 
 /**

+ 4 - 4
src/injected/web/index.js

@@ -117,13 +117,13 @@ function onLoadScripts(data) {
     const name = script.custom.name || script.meta.name || script.props.id;
     const args = map(argNames, key => wrapper[key]);
     const thisObj = wrapper.window || wrapper;
-    const id = `VMin${getUniqId()}`;
-    const callbackId = `VMcb${getUniqId()}`;
-    attachFunction(callbackId, () => {
+    const id = getUniqId('VMin');
+    const fnId = getUniqId('VMfn');
+    attachFunction(fnId, () => {
       const func = window[id];
       if (func) runCode(name, func, args, thisObj);
     });
-    bridge.post({ cmd: 'Inject', data: [id, argNames, codeConcat, callbackId] });
+    bridge.post({ cmd: 'Inject', data: [id, argNames, codeConcat, fnId] });
   }
   function run(list) {
     while (list.length) buildCode(list.shift());