flash-notifications 0.0.18 → 0.0.19

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.
@@ -0,0 +1,8 @@
1
+ export default class FlashNotificationsListener {
2
+ static current(): any;
3
+ notifications: any[];
4
+ connect(events: any): void;
5
+ findAndPop(argument: any): any;
6
+ onPushNotification: (notification: any) => void;
7
+ }
8
+ //# sourceMappingURL=listener.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../src/listener.js"],"names":[],"mappings":"AAEA;IAGE,sBAQC;IAVD,qBAAkB;IAYlB,2BAEC;IAED,+BA+BC;IAED,gDAEC;CACF"}
@@ -0,0 +1,45 @@
1
+ import events from "./events.js";
2
+ export default class FlashNotificationsListener {
3
+ notifications = [];
4
+ static current() {
5
+ if (!globalThis.flashNotificationsListener) {
6
+ globalThis.flashNotificationsListener = new FlashNotificationsListener();
7
+ globalThis.flashNotificationsListener.connect(events);
8
+ }
9
+ return globalThis.flashNotificationsListener;
10
+ }
11
+ connect(events) {
12
+ events.addListener("pushNotification", this.onPushNotification);
13
+ }
14
+ findAndPop(argument) {
15
+ for (const notificationIndex in this.notifications) {
16
+ const notification = this.notifications[notificationIndex];
17
+ let result;
18
+ if (typeof argument == "function") {
19
+ result = argument(notification);
20
+ }
21
+ else if (typeof argument == "object") {
22
+ let allEqual = true;
23
+ for (const key in argument) {
24
+ const value = argument[key];
25
+ if (value !== notification[key]) {
26
+ allEqual = false;
27
+ }
28
+ }
29
+ result = allEqual;
30
+ }
31
+ else {
32
+ throw new Error(`Unknown type of argument: ${typeof argument}`);
33
+ }
34
+ if (result) {
35
+ delete this.notifications[notificationIndex];
36
+ return notification;
37
+ }
38
+ }
39
+ throw new Error(`Couldn't find the expected notification in: ${JSON.stringify(this.notifications)}`);
40
+ }
41
+ onPushNotification = (notification) => {
42
+ this.notifications.push(notification);
43
+ };
44
+ }
45
+ //# sourceMappingURL=listener.js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BACN,MAAM,IAAI,KAAK,CAAC,6BAA6B,OAAO,QAAQ,EAAE,CAAC,CAAA;YACjE,CAAC;YAED,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,IAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAA;gBAE5C,OAAO,YAAY,CAAA;YACrB,CAAC;QACH,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,+CAA+C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,CAAA;IACtG,CAAC;IAED,kBAAkB,GAAG,CAAC,YAAY,EAAE,EAAE;QACpC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;IACvC,CAAC,CAAA;CACF","sourcesContent":["import events from \"./events.js\"\n\nexport default class FlashNotificationsListener {\n notifications = []\n\n static current() {\n if (!globalThis.flashNotificationsListener) {\n globalThis.flashNotificationsListener = new FlashNotificationsListener()\n\n globalThis.flashNotificationsListener.connect(events)\n }\n\n return globalThis.flashNotificationsListener\n }\n\n connect(events) {\n events.addListener(\"pushNotification\", this.onPushNotification)\n }\n\n findAndPop(argument) {\n for (const notificationIndex in this.notifications) {\n const notification = this.notifications[notificationIndex]\n let result\n\n if (typeof argument == \"function\") {\n result = argument(notification)\n } else if (typeof argument == \"object\") {\n let allEqual = true\n\n for (const key in argument) {\n const value = argument[key]\n\n if (value !== notification[key]) {\n allEqual = false\n }\n }\n\n result = allEqual\n } else {\n throw new Error(`Unknown type of argument: ${typeof argument}`)\n }\n\n if (result) {\n delete this.notifications[notificationIndex]\n\n return notification\n }\n }\n\n throw new Error(`Couldn't find the expected notification in: ${JSON.stringify(this.notifications)}`)\n }\n\n onPushNotification = (notification) => {\n this.notifications.push(notification)\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flash-notifications",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "My new module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -46,7 +46,7 @@
46
46
  "set-state-compare": "^1.0.57"
47
47
  },
48
48
  "devDependencies": {
49
- "@testing-library/react-native": "~13.0.1",
49
+ "@testing-library/react-native": "~13.2.0",
50
50
  "@types/react": "~18.3.12",
51
51
  "expo": "~53.0.9",
52
52
  "expo-module-scripts": "^4.0.2",
@@ -0,0 +1,56 @@
1
+ import events from "./events.js"
2
+
3
+ export default class FlashNotificationsListener {
4
+ notifications = []
5
+
6
+ static current() {
7
+ if (!globalThis.flashNotificationsListener) {
8
+ globalThis.flashNotificationsListener = new FlashNotificationsListener()
9
+
10
+ globalThis.flashNotificationsListener.connect(events)
11
+ }
12
+
13
+ return globalThis.flashNotificationsListener
14
+ }
15
+
16
+ connect(events) {
17
+ events.addListener("pushNotification", this.onPushNotification)
18
+ }
19
+
20
+ findAndPop(argument) {
21
+ for (const notificationIndex in this.notifications) {
22
+ const notification = this.notifications[notificationIndex]
23
+ let result
24
+
25
+ if (typeof argument == "function") {
26
+ result = argument(notification)
27
+ } else if (typeof argument == "object") {
28
+ let allEqual = true
29
+
30
+ for (const key in argument) {
31
+ const value = argument[key]
32
+
33
+ if (value !== notification[key]) {
34
+ allEqual = false
35
+ }
36
+ }
37
+
38
+ result = allEqual
39
+ } else {
40
+ throw new Error(`Unknown type of argument: ${typeof argument}`)
41
+ }
42
+
43
+ if (result) {
44
+ delete this.notifications[notificationIndex]
45
+
46
+ return notification
47
+ }
48
+ }
49
+
50
+ throw new Error(`Couldn't find the expected notification in: ${JSON.stringify(this.notifications)}`)
51
+ }
52
+
53
+ onPushNotification = (notification) => {
54
+ this.notifications.push(notification)
55
+ }
56
+ }