@makano/rew 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/rew/modules/context.js +11 -3
- package/package.json +1 -1
@@ -13,10 +13,12 @@ const runtime = require("./runtime");
|
|
13
13
|
const { straceLog } = require("../misc/strace");
|
14
14
|
const reval = require("../functions/reval");
|
15
15
|
const STDNS = require("../const/stdns");
|
16
|
+
const emitter = require("../functions/emitter");
|
16
17
|
|
17
18
|
let mainFile = "";
|
18
19
|
const isMainFile = (filepath) => filepath == mainFile;
|
19
20
|
const globalContext = {};
|
21
|
+
const globalEmitter = emitter();
|
20
22
|
module.exports.prepareContext = function (
|
21
23
|
custom_context,
|
22
24
|
options,
|
@@ -75,6 +77,7 @@ module.exports.prepareContext = function (
|
|
75
77
|
this.detach = std.prototype.detach;
|
76
78
|
this.out = std.prototype.out;
|
77
79
|
this.inp = std.prototype.in;
|
80
|
+
this.signal = std.prototype.signal;
|
78
81
|
this['@cb'] = cb;
|
79
82
|
}
|
80
83
|
});
|
@@ -120,17 +123,17 @@ module.exports.prepareContext = function (
|
|
120
123
|
}
|
121
124
|
if(!name) return false;
|
122
125
|
globalContext[name] = object;
|
123
|
-
|
126
|
+
globalEmitter.emit('attach_name', name, object);
|
124
127
|
return true;
|
125
128
|
}, detach: (nameOrObject) => {
|
126
129
|
const name = Object.keys(globalContext).find((key) => key == nameOrObject || globalContext[key] == nameOrObject);
|
127
130
|
if(name) {
|
128
131
|
delete globalContext[name];
|
129
|
-
|
132
|
+
globalEmitter.emit('detach_name', name);
|
130
133
|
return true;
|
131
134
|
}
|
132
135
|
return false;
|
133
|
-
} }
|
136
|
+
}, signal: globalEmitter }
|
134
137
|
Object.defineProperty(std.prototype, 'void', {
|
135
138
|
get: () => void 0
|
136
139
|
})
|
@@ -240,6 +243,11 @@ module.exports.prepareContext = function (
|
|
240
243
|
}
|
241
244
|
}
|
242
245
|
|
246
|
+
globalEmitter.on('attach_name', (name, object) => {
|
247
|
+
context[name] = object;
|
248
|
+
});
|
249
|
+
globalEmitter.on('detach_name', (name) => delete context[name]);
|
250
|
+
|
243
251
|
if(!context.app){
|
244
252
|
straceLog('==> APP NOT FOUND');
|
245
253
|
context.appPackage = (packageName) => context.app = { config: { manifest: { package: packageName } } }
|