Skip to content

Commit

Permalink
feat: rework condition
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-guerin committed Nov 14, 2024
1 parent cbacb08 commit 3ccb7e7
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { createHttpRepositoryConfiguration } from '../configuration/context/http
import { HTTP_REPOSITORY_CONFIGURATION } from '../configuration/http-repository.configuration';
import { mergeDeep } from '@paddls/utils';
import { HttpRequestQueuedEvent } from './event/http-request-queued.event';
import { HTTP_OFFLINE_QUEUE_METADATA_KEY } from '../decorator/http-offline-queue.decorator';

@Repository(null, {
requestBuilder: HttpRequestBuilder,
Expand Down Expand Up @@ -201,7 +202,7 @@ export class HttpRepository<T, K> extends AbstractRepository<T> implements FindA
query
}));

if (this.isOffline()) {
if (this.withOfflineQueue() && this.isOffline()) {
PublisherService.getInstance().publish(new HttpRequestQueuedEvent({
type: this.resourceType,
operation: 'create',
Expand Down Expand Up @@ -229,7 +230,7 @@ export class HttpRepository<T, K> extends AbstractRepository<T> implements FindA
query
}));

if (this.isOffline()) {
if (this.withOfflineQueue() && this.isOffline()) {
PublisherService.getInstance().publish(new HttpRequestQueuedEvent({
type: this.resourceType,
operation: 'delete',
Expand Down Expand Up @@ -257,7 +258,7 @@ export class HttpRepository<T, K> extends AbstractRepository<T> implements FindA
query
}));

if (this.isOffline()) {
if (this.withOfflineQueue() && this.isOffline()) {
PublisherService.getInstance().publish(new HttpRequestQueuedEvent({
type: this.resourceType,
operation: 'update',
Expand Down Expand Up @@ -285,7 +286,7 @@ export class HttpRepository<T, K> extends AbstractRepository<T> implements FindA
query
}));

if (this.isOffline()) {
if (this.withOfflineQueue() && this.isOffline()) {
PublisherService.getInstance().publish(new HttpRequestQueuedEvent({
type: this.resourceType,
operation: 'patch',
Expand Down Expand Up @@ -316,6 +317,10 @@ export class HttpRepository<T, K> extends AbstractRepository<T> implements FindA
return Reflect.getMetadata(HTTP_LIVE_RESOURCE_METADATA_KEY, this.resourceType) === true;
}

private withOfflineQueue(): boolean {
return !!Reflect.getMetadata(HTTP_OFFLINE_QUEUE_METADATA_KEY, this.resourceType);
}

private isOffline(): boolean {
return !navigator.onLine;
}
Expand Down

0 comments on commit 3ccb7e7

Please sign in to comment.