larasopp 1.2.19 → 1.2.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/lib/Listener.d.ts CHANGED
@@ -1,26 +1,18 @@
1
- import { type EventListener } from "easy-event-emitter";
1
+ import EventEmmiter from "easy-event-emitter";
2
2
  import type Larasopp from ".";
3
- declare class Listener implements Omit<EventListener, 'events'> {
3
+ declare class Listener extends EventEmmiter.Stack {
4
4
  private readonly context;
5
5
  private channel;
6
- private listeners?;
7
6
  private listener?;
8
7
  private cacheEvents;
9
8
  constructor(channel: string, constext: Larasopp);
10
- get name(): string;
11
- pushListener(object: EventListener<any, string | number | symbol, any>): void;
12
- hasHandler(handler: (data: any) => void): boolean;
13
- onEmit(handlerEmit: () => void): void;
14
- onRemove(handlerRemove: () => void): void;
15
9
  listen(event: string, callback: (data: any) => void, withCache?: boolean): this;
16
10
  here(callback: (data: any) => void, withCache?: boolean): this;
17
11
  joining(callback: (data: any) => void, withCache?: boolean): this;
18
12
  leaving(callback: (data: any) => void, withCache?: boolean): this;
19
13
  unsubscribe(): void;
20
- remove(): void;
21
14
  private hasCache;
22
15
  private getCache;
23
16
  private pushCache;
24
- emit(data: any): void;
25
17
  }
26
18
  export default Listener;
package/lib/Listener.js CHANGED
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- class Listener {
6
+ const easy_event_emitter_1 = __importDefault(require("easy-event-emitter"));
7
+ class Listener extends easy_event_emitter_1.default.Stack {
4
8
  constructor(channel, constext) {
9
+ super([]);
5
10
  Object.defineProperty(this, "context", {
6
11
  enumerable: true,
7
12
  configurable: true,
@@ -14,12 +19,6 @@ class Listener {
14
19
  writable: true,
15
20
  value: void 0
16
21
  });
17
- Object.defineProperty(this, "listeners", {
18
- enumerable: true,
19
- configurable: true,
20
- writable: true,
21
- value: void 0
22
- });
23
22
  Object.defineProperty(this, "listener", {
24
23
  enumerable: true,
25
24
  configurable: true,
@@ -37,38 +36,7 @@ class Listener {
37
36
  this.cacheEvents = {};
38
37
  this.here(() => { }, true);
39
38
  }
40
- get name() {
41
- return '__ws-event';
42
- }
43
- pushListener(object) { }
44
- hasHandler(handler) {
45
- if (this.listeners) {
46
- for (const listener of this.listeners) {
47
- if (listener.hasHandler(handler)) {
48
- return true;
49
- }
50
- }
51
- }
52
- return false;
53
- }
54
- onEmit(handlerEmit) {
55
- if (this.listeners) {
56
- for (const listener of this.listeners) {
57
- listener.onEmit(handlerEmit);
58
- }
59
- }
60
- }
61
- onRemove(handlerRemove) {
62
- if (this.listeners) {
63
- for (const listener of this.listeners) {
64
- listener.onRemove(handlerRemove);
65
- }
66
- }
67
- }
68
39
  listen(event, callback, withCache = false) {
69
- if (!this.listeners) {
70
- this.listeners = [];
71
- }
72
40
  if (withCache && this.hasCache(event))
73
41
  callback(this.getCache(event));
74
42
  const listener = this.context.events.addListener(this.channel + ':' + event, (data) => {
@@ -76,7 +44,7 @@ class Listener {
76
44
  if (withCache)
77
45
  this.pushCache(event, data);
78
46
  });
79
- this.listeners.push(listener);
47
+ this.pushListener(listener);
80
48
  return this;
81
49
  }
82
50
  here(callback, withCache = true) {
@@ -92,11 +60,6 @@ class Listener {
92
60
  this.context.unsubscribe(this.channel);
93
61
  this.remove();
94
62
  }
95
- remove() {
96
- if (!this.listeners)
97
- return;
98
- this.listeners.forEach((listener) => listener.remove());
99
- }
100
63
  hasCache(event) {
101
64
  return event in this.cacheEvents;
102
65
  }
@@ -106,6 +69,5 @@ class Listener {
106
69
  pushCache(event, data) {
107
70
  this.cacheEvents[event] = data;
108
71
  }
109
- emit(data) { }
110
72
  }
111
73
  exports.default = Listener;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "larasopp",
3
- "version": "1.2.19",
3
+ "version": "1.2.20",
4
4
  "description": "Websocket client for laravel",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -37,6 +37,6 @@
37
37
  "typescript": "^5.1.6"
38
38
  },
39
39
  "dependencies": {
40
- "easy-event-emitter": "^1.1.2"
40
+ "easy-event-emitter": "^1.1.4"
41
41
  }
42
42
  }
package/src/Listener.ts CHANGED
@@ -1,4 +1,4 @@
1
- import {
1
+ import EventEmmiter, {
2
2
  type EventListener
3
3
  } from "easy-event-emitter";
4
4
  import type Larasopp from ".";
@@ -7,14 +7,14 @@ type TListenerCacheEvents = {
7
7
  [event: string]: unknown;
8
8
  };
9
9
 
10
- class Listener implements Omit<EventListener, 'events'> {
10
+ class Listener extends EventEmmiter.Stack {
11
11
  private readonly context: Larasopp;
12
12
  private channel: string;
13
- private listeners?: EventListener[];
14
13
  private listener?: EventListener;
15
14
  private cacheEvents: TListenerCacheEvents;
16
15
 
17
16
  constructor(channel: string, constext: Larasopp) {
17
+ super([]);
18
18
  this.channel = channel;
19
19
  this.context = constext;
20
20
  this.cacheEvents = {};
@@ -22,50 +22,15 @@ class Listener implements Omit<EventListener, 'events'> {
22
22
  this.here(()=>{}, true);
23
23
  }
24
24
 
25
- public get name() {
26
- return '__ws-event';
27
- }
28
-
29
- public pushListener(object: EventListener<any, string | number | symbol, any>): void {}
30
-
31
- public hasHandler(handler: (data: any) => void) {
32
- if (this.listeners) {
33
- for (const listener of this.listeners) {
34
- if (listener.hasHandler(handler)) {
35
- return true;
36
- }
37
- }
38
- }
39
- return false;
40
- }
41
-
42
- public onEmit(handlerEmit: () => void) {
43
- if (this.listeners) {
44
- for (const listener of this.listeners) {
45
- listener.onEmit(handlerEmit);
46
- }
47
- }
48
- }
49
-
50
- public onRemove(handlerRemove: () => void) {
51
- if (this.listeners) {
52
- for (const listener of this.listeners) {
53
- listener.onRemove(handlerRemove);
54
- }
55
- }
56
- }
57
-
58
25
  public listen(event: string, callback: (data: any) => void, withCache = false) {
59
- if (!this.listeners) {
60
- this.listeners = [];
61
- }
62
-
26
+
63
27
  if (withCache && this.hasCache(event)) callback(this.getCache(event));
64
28
  const listener = this.context.events.addListener(this.channel + ':' + event, (data) => {
65
29
  callback(data);
66
30
  if (withCache) this.pushCache(event, data);
67
31
  });
68
- this.listeners.push(listener);
32
+
33
+ this.pushListener(listener);
69
34
  return this;
70
35
  }
71
36
 
@@ -86,11 +51,6 @@ class Listener implements Omit<EventListener, 'events'> {
86
51
  this.remove();
87
52
  }
88
53
 
89
- public remove() {
90
- if (!this.listeners) return;
91
- this.listeners.forEach((listener) => listener.remove());
92
- }
93
-
94
54
  private hasCache(event: string) {
95
55
  return event in this.cacheEvents;
96
56
  }
@@ -102,8 +62,6 @@ class Listener implements Omit<EventListener, 'events'> {
102
62
  private pushCache(event: string, data: unknown) {
103
63
  this.cacheEvents[event] = data;
104
64
  }
105
-
106
- public emit(data: any): void {}
107
65
  }
108
66
 
109
67
  export default Listener;