@lvce-editor/json-rpc 5.2.0 → 5.4.0

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.
Files changed (2) hide show
  1. package/dist/index.js +19 -20
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -13,17 +13,15 @@ const JsonRpcEvent = {
13
13
  create: create$4
14
14
  };
15
15
 
16
- const state = {
17
- callbacks: Object.create(null)
18
- };
16
+ const callbacks = Object.create(null);
19
17
  const set = (id, fn) => {
20
- state.callbacks[id] = fn;
18
+ callbacks[id] = fn;
21
19
  };
22
20
  const get = id => {
23
- return state.callbacks[id];
21
+ return callbacks[id];
24
22
  };
25
23
  const remove = id => {
26
- delete state.callbacks[id];
24
+ delete callbacks[id];
27
25
  };
28
26
 
29
27
  let id = 0;
@@ -31,10 +29,6 @@ const create$3 = () => {
31
29
  return ++id;
32
30
  };
33
31
 
34
- const warn = (...args) => {
35
- console.warn(...args);
36
- };
37
-
38
32
  const registerPromise = () => {
39
33
  const id = create$3();
40
34
  const {
@@ -47,16 +41,6 @@ const registerPromise = () => {
47
41
  promise
48
42
  };
49
43
  };
50
- const resolve = (id, response) => {
51
- const fn = get(id);
52
- if (!fn) {
53
- console.log(response);
54
- warn(`callback ${id} may already be disposed`);
55
- return;
56
- }
57
- fn(response);
58
- remove(id);
59
- };
60
44
 
61
45
  const create$2 = (method, params) => {
62
46
  const {
@@ -223,6 +207,21 @@ const unwrapJsonRpcResult = responseMessage => {
223
207
  throw new JsonRpcError('unexpected response message');
224
208
  };
225
209
 
210
+ const warn = (...args) => {
211
+ console.warn(...args);
212
+ };
213
+
214
+ const resolve = (id, response) => {
215
+ const fn = get(id);
216
+ if (!fn) {
217
+ console.log(response);
218
+ warn(`callback ${id} may already be disposed`);
219
+ return;
220
+ }
221
+ fn(response);
222
+ remove(id);
223
+ };
224
+
226
225
  const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
227
226
 
228
227
  const getErrorType = prettyError => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/json-rpc",
3
- "version": "5.2.0",
3
+ "version": "5.4.0",
4
4
  "description": "JsonRpc implementation",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",