soonjs 0.0.19 → 0.0.20

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/dist/index.d.ts CHANGED
@@ -126,6 +126,7 @@ export declare function useSSE<T>({ pingTime, action, }: {
126
126
  }): void;
127
127
  error(message: string): void;
128
128
  close(): void;
129
+ onClosed(cb: () => void): void;
129
130
  }) => any | Promise<any>;
130
131
  }): Observable<{
131
132
  event: string;
package/dist/index.js CHANGED
@@ -54479,41 +54479,44 @@ function Aue({
54479
54479
  const n = new SE((i) => {
54480
54480
  let s;
54481
54481
  e > 0 && (s = setInterval(() => {
54482
- a.closed ? clearInterval(s) : i.next({ event: "ping", message: `: ping
54482
+ o.closed ? clearInterval(s) : i.next({ event: "ping", message: `: ping
54483
54483
 
54484
54484
  ` });
54485
54485
  }, e));
54486
- const a = {
54487
- send(o) {
54486
+ const a = [], o = {
54487
+ send(u) {
54488
54488
  try {
54489
54489
  i.next({
54490
- ...o,
54491
- message: `${o.event ? `event: ${o.event}
54492
- ` : ""}data: ${typeof o.data == "string" ? o.data : JSON.stringify(o.data)}
54490
+ ...u,
54491
+ message: `${u.event ? `event: ${u.event}
54492
+ ` : ""}data: ${typeof u.data == "string" ? u.data : JSON.stringify(u.data)}
54493
54493
 
54494
54494
  `
54495
54495
  });
54496
- } catch (u) {
54497
- a.error(u.message);
54496
+ } catch (l) {
54497
+ o.error(l.message);
54498
54498
  }
54499
54499
  },
54500
- error(o) {
54501
- i.next({ event: "error", data: o, message: `event: error
54502
- data: ${o}
54500
+ error(u) {
54501
+ i.next({ event: "error", data: u, message: `event: error
54502
+ data: ${u}
54503
54503
 
54504
- ` }), i.complete(), a.closed = !0;
54504
+ ` }), i.complete(), o.closed = !0, a.forEach((l) => l == null ? void 0 : l());
54505
54505
  },
54506
54506
  close() {
54507
54507
  i.next({ event: "close", message: `event: close
54508
54508
  data:
54509
54509
 
54510
- ` }), i.complete(), a.closed = !0, s && clearInterval(s);
54510
+ ` }), i.complete(), o.closed = !0, s && clearInterval(s), a.forEach((u) => u == null ? void 0 : u());
54511
54511
  },
54512
- closed: !1
54512
+ closed: !1,
54513
+ onClosed(u) {
54514
+ a.push(u);
54515
+ }
54513
54516
  };
54514
54517
  r = () => {
54515
- a.closed || a.close();
54516
- }, t(a);
54518
+ o.closed || o.close();
54519
+ }, t(o);
54517
54520
  });
54518
54521
  return n.streamClose = () => r == null ? void 0 : r(), n;
54519
54522
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soonjs",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",