ee-core 1.2.2 → 1.2.3

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.
@@ -81,15 +81,15 @@ class IpcServer {
81
81
  for (const key in fns) {
82
82
  let channel = pathName + '.' + key;
83
83
  debug('register channel %s', channel);
84
- ipcMain.on(channel, async (event, params) => {
84
+
85
+ function findFn (app, c) {
85
86
  try {
86
87
  // 找函数
87
- const cmd = channel;
88
- const args = params;
88
+ const cmd = c;
89
89
  let fn = null;
90
90
  if (is.string(cmd)) {
91
91
  const actions = cmd.split('.');
92
- let obj = self.app;
92
+ let obj = app;
93
93
  actions.forEach(key => {
94
94
  obj = obj[key];
95
95
  if (!obj) throw new Error(`class or function '${key}' not exists`);
@@ -98,12 +98,29 @@ class IpcServer {
98
98
  }
99
99
  if (!fn) throw new Error('function not exists');
100
100
 
101
- const result = await fn.call(self.app, args, event);
102
- event.reply(`${channel}`, result)
101
+ return fn;
103
102
  } catch (err) {
104
- self.app.logger.error('[ee:socket:ipcMain] throw error:', err);
103
+ app.logger.error('[ee:socket:ipcMain] throw error:', err);
105
104
  }
106
- })
105
+ return null;
106
+ }
107
+
108
+ // send/on 模型
109
+ ipcMain.on(channel, async (event, params) => {
110
+ const fn = findFn(self.app, channel);
111
+ const result = await fn.call(self.app, params, event);
112
+
113
+ event.returnValue = result;
114
+ event.reply(`${channel}`, result);
115
+ });
116
+
117
+ // invoke/handle 模型
118
+ ipcMain.handle(channel, async (event, params) => {
119
+ const fn = findFn(self.app, channel);
120
+ const result = await fn.call(self.app, params, event);
121
+
122
+ return result;
123
+ });
107
124
  }
108
125
  }
109
126
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ee-core",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "ee core",
5
5
  "main": "index.js",
6
6
  "scripts": {