forked from OneSignal/OneSignal-Cordova-SDK
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- having the object creation was leading to bugs on the OutSystems side, as it wasn't a singleton, new instances of the object kept being created - fixes unit tests accordingly https://outsystemsrd.atlassian.net/browse/RMET-3477
- Loading branch information
1 parent
ee16feb
commit caf4d5a
Showing
7 changed files
with
116 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,26 @@ | ||
import { OneSignalCallback } from './definitions'; | ||
|
||
declare class OneSignalManagerClass { | ||
#private; | ||
/** | ||
* Public delegate for OneSignal's handleNotificationReceived | ||
*/ | ||
notificationReceivedDelegate(jsonData: any): void; | ||
/** | ||
* Public delegate for OneSignal's handleNotificationOpened | ||
*/ | ||
notificationOpenedDelegate(jsonData: any): void; | ||
/** | ||
* Sets the current callback for OneSignal's Notification Received events. | ||
*/ | ||
setNotificationReceivedCallback(callback: OneSignalCallback): void; | ||
/** | ||
* Sets the current callback for OneSignal's Notification Opened events. | ||
*/ | ||
setNotificationOpenedCallback(callback: OneSignalCallback): void; | ||
/** | ||
* Unregister the old callback of OneSignal's Notification Received | ||
*/ | ||
unregisterReceivedCallback(callback: OneSignalCallback): void; | ||
/** | ||
* Unregister the old callback of OneSignal's Notification Opened | ||
*/ | ||
unregisterOpenedCallback(callback: OneSignalCallback): void; | ||
} | ||
export declare const Manager: OneSignalManagerClass; | ||
export {}; | ||
/** | ||
* Public delegate for OneSignal's handleNotificationReceived | ||
*/ | ||
export declare function notificationReceivedDelegate(jsonData: any): void; | ||
/** | ||
* Public delegate for OneSignal's handleNotificationOpened | ||
*/ | ||
export declare function notificationOpenedDelegate(jsonData: any): void; | ||
/** | ||
* Sets the current callback for OneSignal's Notification Received events. | ||
*/ | ||
export declare function setNotificationReceivedCallback(callback: OneSignalCallback): void; | ||
/** | ||
* Sets the current callback for OneSignal's Notification Opened events. | ||
*/ | ||
export declare function setNotificationOpenedCallback(callback: OneSignalCallback): void; | ||
/** | ||
* Unregister the old callback of OneSignal's Notification Received | ||
*/ | ||
export declare function unregisterReceivedCallback(callback: OneSignalCallback): void; | ||
/** | ||
* Unregister the old callback of OneSignal's Notification Opened | ||
*/ | ||
export declare function unregisterOpenedCallback(callback: OneSignalCallback): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,42 @@ | ||
(function(global, factory) { | ||
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.OSOneSignal = {})); | ||
})(this, function(exports2) { | ||
"use strict";var __typeError = (msg) => { | ||
throw TypeError(msg); | ||
}; | ||
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); | ||
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); | ||
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); | ||
|
||
var _notificationReceivedCallback, _notificationOpenedCallback; | ||
class OneSignalManagerClass { | ||
constructor() { | ||
__privateAdd(this, _notificationReceivedCallback, []); | ||
__privateAdd(this, _notificationOpenedCallback, []); | ||
} | ||
/** | ||
* Public delegate for OneSignal's handleNotificationReceived | ||
*/ | ||
notificationReceivedDelegate(jsonData) { | ||
__privateGet(this, _notificationReceivedCallback).forEach(function(callback) { | ||
callback.call(void 0, jsonData); | ||
}); | ||
} | ||
/** | ||
* Public delegate for OneSignal's handleNotificationOpened | ||
*/ | ||
notificationOpenedDelegate(jsonData) { | ||
__privateGet(this, _notificationOpenedCallback).forEach(function(callback) { | ||
callback.call(void 0, jsonData); | ||
}); | ||
} | ||
/** | ||
* Sets the current callback for OneSignal's Notification Received events. | ||
*/ | ||
setNotificationReceivedCallback(callback) { | ||
__privateGet(this, _notificationReceivedCallback).push(callback); | ||
} | ||
/** | ||
* Sets the current callback for OneSignal's Notification Opened events. | ||
*/ | ||
setNotificationOpenedCallback(callback) { | ||
__privateGet(this, _notificationOpenedCallback).push(callback); | ||
} | ||
/** | ||
* Unregister the old callback of OneSignal's Notification Received | ||
*/ | ||
unregisterReceivedCallback(callback) { | ||
var cbIndex = __privateGet(this, _notificationReceivedCallback).indexOf(callback); | ||
if (cbIndex >= 0) { | ||
delete __privateGet(this, _notificationReceivedCallback)[cbIndex]; | ||
} | ||
"use strict"; | ||
var notificationReceivedCallback = []; | ||
var notificationOpenedCallback = []; | ||
function notificationReceivedDelegate(jsonData) { | ||
notificationReceivedCallback.forEach(function(callback) { | ||
callback(jsonData); | ||
}); | ||
} | ||
function notificationOpenedDelegate(jsonData) { | ||
notificationOpenedCallback.forEach(function(callback) { | ||
callback(jsonData); | ||
}); | ||
} | ||
function setNotificationReceivedCallback(callback) { | ||
notificationReceivedCallback.push(callback); | ||
} | ||
function setNotificationOpenedCallback(callback) { | ||
notificationOpenedCallback.push(callback); | ||
} | ||
function unregisterReceivedCallback(callback) { | ||
var cbIndex = notificationReceivedCallback.indexOf(callback); | ||
if (cbIndex >= 0) { | ||
delete notificationReceivedCallback[cbIndex]; | ||
} | ||
/** | ||
* Unregister the old callback of OneSignal's Notification Opened | ||
*/ | ||
unregisterOpenedCallback(callback) { | ||
var cbIndex = __privateGet(this, _notificationOpenedCallback).indexOf(callback); | ||
if (cbIndex >= 0) { | ||
delete __privateGet(this, _notificationOpenedCallback)[cbIndex]; | ||
} | ||
} | ||
function unregisterOpenedCallback(callback) { | ||
var cbIndex = notificationOpenedCallback.indexOf(callback); | ||
if (cbIndex >= 0) { | ||
delete notificationOpenedCallback[cbIndex]; | ||
} | ||
} | ||
_notificationReceivedCallback = new WeakMap(); | ||
_notificationOpenedCallback = new WeakMap(); | ||
const Manager = new OneSignalManagerClass(); | ||
exports2.Manager = Manager; | ||
exports2.notificationOpenedDelegate = notificationOpenedDelegate; | ||
exports2.notificationReceivedDelegate = notificationReceivedDelegate; | ||
exports2.setNotificationOpenedCallback = setNotificationOpenedCallback; | ||
exports2.setNotificationReceivedCallback = setNotificationReceivedCallback; | ||
exports2.unregisterOpenedCallback = unregisterOpenedCallback; | ||
exports2.unregisterReceivedCallback = unregisterReceivedCallback; | ||
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,59 @@ | ||
import { OneSignalCallback } from "./definitions"; | ||
|
||
class OneSignalManagerClass { | ||
|
||
#notificationReceivedCallback: OneSignalCallback[] = []; | ||
#notificationOpenedCallback: OneSignalCallback[] = []; | ||
|
||
/** | ||
* Public delegate for OneSignal's handleNotificationReceived | ||
*/ | ||
notificationReceivedDelegate(jsonData: any) { | ||
this.#notificationReceivedCallback.forEach(function(callback:OneSignalCallback){ | ||
callback.call(undefined, jsonData); | ||
}); | ||
} | ||
var notificationReceivedCallback: OneSignalCallback[] = []; | ||
var notificationOpenedCallback: OneSignalCallback[] = []; | ||
|
||
/** | ||
* Public delegate for OneSignal's handleNotificationReceived | ||
*/ | ||
export function notificationReceivedDelegate(jsonData: any) { | ||
notificationReceivedCallback.forEach(function(callback:OneSignalCallback){ | ||
callback(jsonData); | ||
}); | ||
} | ||
|
||
/** | ||
* Public delegate for OneSignal's handleNotificationOpened | ||
*/ | ||
notificationOpenedDelegate(jsonData: any) { | ||
this.#notificationOpenedCallback.forEach(function(callback:OneSignalCallback){ | ||
callback.call(undefined, jsonData); | ||
}); | ||
} | ||
/** | ||
* Public delegate for OneSignal's handleNotificationOpened | ||
*/ | ||
export function notificationOpenedDelegate(jsonData: any) { | ||
notificationOpenedCallback.forEach(function(callback:OneSignalCallback){ | ||
callback(jsonData); | ||
}); | ||
} | ||
|
||
/** | ||
* Sets the current callback for OneSignal's Notification Received events. | ||
*/ | ||
setNotificationReceivedCallback(callback:OneSignalCallback) { | ||
this.#notificationReceivedCallback.push(callback); | ||
} | ||
/** | ||
* Sets the current callback for OneSignal's Notification Received events. | ||
*/ | ||
export function setNotificationReceivedCallback(callback:OneSignalCallback) { | ||
notificationReceivedCallback.push(callback); | ||
} | ||
|
||
/** | ||
* Sets the current callback for OneSignal's Notification Opened events. | ||
*/ | ||
setNotificationOpenedCallback(callback:OneSignalCallback) { | ||
this.#notificationOpenedCallback.push(callback); | ||
} | ||
/** | ||
* Sets the current callback for OneSignal's Notification Opened events. | ||
*/ | ||
export function setNotificationOpenedCallback(callback:OneSignalCallback) { | ||
notificationOpenedCallback.push(callback); | ||
} | ||
|
||
/** | ||
* Unregister the old callback of OneSignal's Notification Received | ||
*/ | ||
unregisterReceivedCallback(callback:OneSignalCallback) { | ||
var cbIndex = this.#notificationReceivedCallback.indexOf(callback); | ||
if(cbIndex >= 0) { | ||
//this.#notificationReceivedCallback[cbIndex] = undefined; | ||
delete this.#notificationReceivedCallback[cbIndex]; | ||
} | ||
/** | ||
* Unregister the old callback of OneSignal's Notification Received | ||
*/ | ||
export function unregisterReceivedCallback(callback:OneSignalCallback) { | ||
var cbIndex = notificationReceivedCallback.indexOf(callback); | ||
if(cbIndex >= 0) { | ||
//notificationReceivedCallback[cbIndex] = undefined; | ||
delete notificationReceivedCallback[cbIndex]; | ||
} | ||
} | ||
|
||
/** | ||
* Unregister the old callback of OneSignal's Notification Opened | ||
*/ | ||
unregisterOpenedCallback(callback:OneSignalCallback) { | ||
var cbIndex = this.#notificationOpenedCallback.indexOf(callback); | ||
if(cbIndex >= 0) { | ||
//this.#notificationOpenedCallback[cbIndex] = undefined; | ||
delete this.#notificationOpenedCallback[cbIndex]; | ||
} | ||
/** | ||
* Unregister the old callback of OneSignal's Notification Opened | ||
*/ | ||
export function unregisterOpenedCallback(callback:OneSignalCallback) { | ||
var cbIndex = notificationOpenedCallback.indexOf(callback); | ||
if(cbIndex >= 0) { | ||
//notificationOpenedCallback[cbIndex] = undefined; | ||
delete notificationOpenedCallback[cbIndex]; | ||
} | ||
} | ||
|
||
export const Manager = new OneSignalManagerClass(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters