mirror of
https://gitcode.com/gh_mirrors/re/react-native-pushy.git
synced 2025-09-16 10:21:37 +08:00
ensure logger is ready
This commit is contained in:
@@ -52,6 +52,16 @@ export class Pushy {
|
||||
marked = false;
|
||||
applyingUpdate = false;
|
||||
version = cInfo.pushy;
|
||||
loggerPromise = (() => {
|
||||
let resolve;
|
||||
const promise = new Promise((res) => {
|
||||
resolve = res;
|
||||
});
|
||||
return {
|
||||
promise,
|
||||
resolve
|
||||
}
|
||||
})();
|
||||
|
||||
constructor(options: PushyOptions) {
|
||||
if (Platform.OS === 'ios' || Platform.OS === 'android') {
|
||||
@@ -60,13 +70,6 @@ export class Pushy {
|
||||
}
|
||||
}
|
||||
this.setOptions(options);
|
||||
}
|
||||
|
||||
setOptions = (options: Partial<PushyOptions>) => {
|
||||
for (const [key, value] of Object.entries(options)) {
|
||||
if (value !== undefined) {
|
||||
(this.options as any)[key] = value;
|
||||
if (key === 'logger') {
|
||||
if (isRolledBack) {
|
||||
this.report({
|
||||
type: 'rollback',
|
||||
@@ -76,11 +79,19 @@ export class Pushy {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setOptions = (options: Partial<PushyOptions>) => {
|
||||
for (const [key, value] of Object.entries(options)) {
|
||||
if (value !== undefined) {
|
||||
(this.options as any)[key] = value;
|
||||
if (key === 'logger') {
|
||||
this.loggerPromise.resolve();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
report = ({
|
||||
report = async ({
|
||||
type,
|
||||
message = '',
|
||||
data = {},
|
||||
@@ -90,6 +101,7 @@ export class Pushy {
|
||||
data?: Record<string, string | number>;
|
||||
}) => {
|
||||
log(type + ' ' + message);
|
||||
await this.loggerPromise.promise;
|
||||
const { logger = noop, appKey } = this.options;
|
||||
logger({
|
||||
type,
|
||||
|
Reference in New Issue
Block a user