@cordova-plugin-agconnect/clouddb
Version:
Cordova AGC CloudDB Plugin
48 lines (41 loc) • 1.34 kB
text/typescript
/*
* Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
*/
import { exec } from 'cordova';
export function asyncExec(clazz: string, ref: string, args: any[] = []): Promise<any> {
return new Promise((resolve, reject) => {
exec(resolve, reject, clazz, ref, args);
});
}
export function randomNumber(seed: number = Date.now()){
seed ^= seed << 13;
seed ^= seed >> 17;
seed ^= seed << 5;
return seed;
}
declare global {
interface Window {
AGCEvents: {
[key: string]: (data: any, data2?: any) => void
},
runAGCEvent: (eventName: string, data: any, data2?: any) => void,
subscribeAGCEvent: (eventName: string, callback: (data: any, data2?: any) => void) => void
[key: string]: any
}
}
function initEventHandler() {
if (window.AGCEvents != null) return;
window.AGCEvents = {};
window.runAGCEvent = (eventName, data, data2) => {
if (Object.prototype.hasOwnProperty.call(window.AGCEvents, eventName)) {
if (data2)
window.AGCEvents[eventName](data, data2);
else
window.AGCEvents[eventName](data);
}
};
window.subscribeAGCEvent = (eventName, handler) => {
window.AGCEvents[eventName] = handler;
};
}
initEventHandler()