@makano/rew 1.4.3 → 1.4.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,
@@ -61,6 +63,10 @@ module.exports.prepareContext = function (
61
63
  ...custom_context,
62
64
  Usage
63
65
  };
66
+ globalEmitter.on('attach_name', (name, object) => {
67
+ context[name] = object;
68
+ });
69
+ globalEmitter.on('detach_name', (name) => delete context[name]);
64
70
  std.prototype = { ns: (cb) => {
65
71
  return new (class extends STDNS {
66
72
  constructor(){
@@ -75,6 +81,7 @@ module.exports.prepareContext = function (
75
81
  this.detach = std.prototype.detach;
76
82
  this.out = std.prototype.out;
77
83
  this.inp = std.prototype.in;
84
+ this.signal = std.prototype.signal;
78
85
  this['@cb'] = cb;
79
86
  }
80
87
  });
@@ -120,17 +127,17 @@ module.exports.prepareContext = function (
120
127
  }
121
128
  if(!name) return false;
122
129
  globalContext[name] = object;
123
- context[name] = object;
130
+ globalEmitter.emit('attach_name', name, object);
124
131
  return true;
125
132
  }, detach: (nameOrObject) => {
126
133
  const name = Object.keys(globalContext).find((key) => key == nameOrObject || globalContext[key] == nameOrObject);
127
134
  if(name) {
128
135
  delete globalContext[name];
129
- delete context[name];
136
+ globalEmitter.emit('detach_name', name);
130
137
  return true;
131
138
  }
132
139
  return false;
133
- } }
140
+ }, signal: globalEmitter }
134
141
  Object.defineProperty(std.prototype, 'void', {
135
142
  get: () => void 0
136
143
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@makano/rew",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "description": "A simple coffescript runtime and app manager",
5
5
  "main": "main.js",
6
6
  "directories": {