refactor(core): adjust effect api (#11935)

This commit is contained in:
EYHN
2025-04-24 10:06:11 +00:00
parent 1d38e5787b
commit eaa1bc6bf1
41 changed files with 79 additions and 146 deletions

View File

@@ -10,7 +10,7 @@ import {
onStart,
smartRetry,
} from '@toeverything/infra';
import { EMPTY, mergeMap } from 'rxjs';
import { tap } from 'rxjs';
import type { DocService } from '../../doc';
import type { GlobalCache } from '../../storage';
@@ -47,9 +47,8 @@ export class CloudDocMeta extends Entity {
this.store.fetchCloudDocMeta(this.workspaceId, this.docId)
).pipe(
smartRetry(),
mergeMap(meta => {
tap(meta => {
this.cache.set<CloudDocMetaType>(this.cacheKey, meta);
return EMPTY;
}),
catchErrorInto(this.error$),
onStart(() => this.isRevalidating$.next(true)),

View File

@@ -10,7 +10,7 @@ import {
onStart,
smartRetry,
} from '@toeverything/infra';
import { EMPTY, map, mergeMap } from 'rxjs';
import { map, tap } from 'rxjs';
import type { InvoicesStore } from '../stores/invoices';
@@ -44,10 +44,9 @@ export class Invoices extends Entity {
signal
);
}).pipe(
mergeMap(data => {
tap(data => {
this.invoiceCount$.setValue(data.invoiceCount);
this.pageInvoices$.setValue(data.invoices);
return EMPTY;
}),
smartRetry(),
catchErrorInto(this.error$),

View File

@@ -8,7 +8,7 @@ import {
onComplete,
onStart,
} from '@toeverything/infra';
import { EMPTY, exhaustMap, map, mergeMap } from 'rxjs';
import { exhaustMap, map, tap } from 'rxjs';
import { ServerScope } from '../scopes/server';
import { AuthService } from '../services/auth';
@@ -77,7 +77,7 @@ export class Server extends Entity<{
backoffRetry({
count: Infinity,
}),
mergeMap(config => {
tap(config => {
this.serverListStore.updateServerConfig(this.serverMetadata.id, {
credentialsRequirement: config.credentialsRequirement,
features: config.features,
@@ -87,7 +87,6 @@ export class Server extends Entity<{
version: config.version,
initialized: config.initialized,
});
return EMPTY;
}),
onStart(() => {
this.isConfigRevalidating$.next(true);

View File

@@ -10,7 +10,7 @@ import {
onStart,
} from '@toeverything/infra';
import { isEqual } from 'lodash-es';
import { EMPTY, mergeMap } from 'rxjs';
import { tap } from 'rxjs';
import { validateAndReduceImage } from '../../../utils/reduce-image';
import type { AccountProfile, AuthStore } from '../stores/auth';
@@ -78,11 +78,10 @@ export class AuthSession extends Entity {
backoffRetry({
count: Infinity,
}),
mergeMap(sessionInfo => {
tap(sessionInfo => {
if (!isEqual(this.store.getCachedAuthSession(), sessionInfo)) {
this.store.setCachedAuthSession(sessionInfo);
}
return EMPTY;
}),
onStart(() => {
this.isRevalidating$.next(true);

View File

@@ -15,7 +15,7 @@ import {
onStart,
smartRetry,
} from '@toeverything/infra';
import { EMPTY, map, mergeMap } from 'rxjs';
import { map, tap } from 'rxjs';
import type { AuthService } from '../services/auth';
import type { ServerService } from '../services/server';
@@ -122,7 +122,7 @@ export class Subscription extends Entity {
};
}).pipe(
smartRetry(),
mergeMap(data => {
tap(data => {
if (data) {
this.store.setCachedSubscriptions(
data.userId,
@@ -132,7 +132,6 @@ export class Subscription extends Entity {
} else {
this.subscription$.next(undefined);
}
return EMPTY;
}),
catchErrorInto(this.error$),
onStart(() => this.isRevalidating$.next(true)),

View File

@@ -9,7 +9,7 @@ import {
onStart,
smartRetry,
} from '@toeverything/infra';
import { EMPTY, map, mergeMap } from 'rxjs';
import { map, tap } from 'rxjs';
import type { AuthService } from '../services/auth';
import type { ServerService } from '../services/server';
@@ -54,7 +54,7 @@ export class UserCopilotQuota extends Entity {
return aiQuota;
}).pipe(
smartRetry(),
mergeMap(data => {
tap(data => {
if (data) {
const { limit, used } = data;
this.copilotActionUsed$.next(used);
@@ -65,7 +65,6 @@ export class UserCopilotQuota extends Entity {
this.copilotActionUsed$.next(null);
this.copilotActionLimit$.next(null);
}
return EMPTY;
}),
catchErrorInto(this.error$),
onStart(() => this.isRevalidating$.next(true)),

View File

@@ -10,7 +10,7 @@ import {
onStart,
smartRetry,
} from '@toeverything/infra';
import { EMPTY, map, mergeMap } from 'rxjs';
import { map, tap } from 'rxjs';
import type { AuthService } from '../services/auth';
import type { UserFeatureStore } from '../stores/user-feature';
@@ -64,13 +64,12 @@ export class UserFeature extends Entity {
};
}).pipe(
smartRetry(),
mergeMap(data => {
tap(data => {
if (data) {
this.features$.next(data.features);
} else {
this.features$.next(null);
}
return EMPTY;
}),
catchErrorInto(this.error$),
onStart(() => this.isRevalidating$.next(true)),

View File

@@ -12,7 +12,7 @@ import {
} from '@toeverything/infra';
import { cssVar } from '@toeverything/theme';
import bytes from 'bytes';
import { EMPTY, map, mergeMap } from 'rxjs';
import { map, tap } from 'rxjs';
import type { AuthService } from '../services/auth';
import type { UserQuotaStore } from '../stores/user-quota';
@@ -79,7 +79,7 @@ export class UserQuota extends Entity {
return { quota, used };
}).pipe(
smartRetry(),
mergeMap(data => {
tap(data => {
if (data) {
const { quota, used } = data;
this.quota$.next(quota);
@@ -88,7 +88,6 @@ export class UserQuota extends Entity {
this.quota$.next(null);
this.used$.next(null);
}
return EMPTY;
}),
catchErrorInto(this.error$),
onStart(() => this.isRevalidating$.next(true)),

View File

@@ -10,7 +10,7 @@ import {
onStart,
smartRetry,
} from '@toeverything/infra';
import { EMPTY, map, mergeMap } from 'rxjs';
import { map, tap } from 'rxjs';
import type { WorkspaceService } from '../../workspace';
import type { WorkspaceServerService } from '../services/workspace-server';
@@ -55,10 +55,9 @@ export class WorkspaceInvoices extends Entity {
signal
);
}).pipe(
mergeMap(data => {
tap(data => {
this.invoiceCount$.setValue(data.invoiceCount);
this.pageInvoices$.setValue(data.invoices);
return EMPTY;
}),
smartRetry(),
catchErrorInto(this.error$),

View File

@@ -11,7 +11,7 @@ import {
onStart,
smartRetry,
} from '@toeverything/infra';
import { EMPTY, mergeMap } from 'rxjs';
import { tap } from 'rxjs';
import type { WorkspaceService } from '../../workspace';
import type { WorkspaceServerService } from '../services/workspace-server';
@@ -123,7 +123,7 @@ export class WorkspaceSubscription extends Entity {
};
}).pipe(
smartRetry(),
mergeMap(data => {
tap(data => {
if (data && data.subscription && data.workspaceId && this.store) {
this.store.setCachedWorkspaceSubscription(
data.workspaceId,
@@ -133,7 +133,6 @@ export class WorkspaceSubscription extends Entity {
} else {
this.subscription$.next(undefined);
}
return EMPTY;
}),
catchErrorInto(this.error$),
onStart(() => this.isRevalidating$.next(true)),

View File

@@ -7,7 +7,7 @@ import {
onStart,
Service,
} from '@toeverything/infra';
import { EMPTY, exhaustMap, mergeMap, switchMap } from 'rxjs';
import { exhaustMap, switchMap, tap } from 'rxjs';
import type { ValidatorProvider } from '../provider/validator';
import type { FetchService } from './fetch';
@@ -58,11 +58,10 @@ export class CaptchaService extends Service {
}
return { challenge: data.challenge, token: undefined };
}).pipe(
mergeMap(({ challenge, token }) => {
tap(({ challenge, token }) => {
this.verifyToken$.next(token);
this.challenge$.next(challenge);
this.resetAfter5min();
return EMPTY;
}),
catchErrorInto(this.error$),
onStart(() => {
@@ -83,11 +82,10 @@ export class CaptchaService extends Service {
});
return true;
}).pipe(
mergeMap(_ => {
tap(_ => {
this.challenge$.next(undefined);
this.verifyToken$.next(undefined);
this.isLoading$.next(false);
return EMPTY;
})
);
})

View File

@@ -9,7 +9,7 @@ import {
Service,
smartRetry,
} from '@toeverything/infra';
import { EMPTY, mergeMap, switchMap } from 'rxjs';
import { EMPTY, switchMap, tap } from 'rxjs';
import type { AcceptInviteStore } from '../stores/accept-invite';
import type { InviteInfoStore } from '../stores/invite-info';
@@ -36,9 +36,8 @@ export class InvitationService extends Service {
return fromPromise(async () => {
return await this.inviteInfoStore.getInviteInfo(inviteId);
}).pipe(
mergeMap(res => {
tap(res => {
this.inviteInfo$.setValue(res);
return EMPTY;
}),
smartRetry({
count: 1,

View File

@@ -7,7 +7,7 @@ import {
Service,
smartRetry,
} from '@toeverything/infra';
import { catchError, EMPTY, exhaustMap, groupBy, mergeMap } from 'rxjs';
import { catchError, EMPTY, exhaustMap, groupBy, mergeMap, tap } from 'rxjs';
import type { PublicUserStore } from '../stores/public-user';
@@ -98,10 +98,9 @@ export class PublicUserService extends Service {
this.setError(id, error);
return EMPTY;
}),
mergeMap(user => {
tap(user => {
this.setPublicUser(id, user);
this.setError(id, null); // clear error
return EMPTY;
}),
onStart(() => this.setLoading(id, true)),
onComplete(() => this.setLoading(id, false))

View File

@@ -9,7 +9,7 @@ import {
Service,
smartRetry,
} from '@toeverything/infra';
import { EMPTY, exhaustMap, mergeMap } from 'rxjs';
import { exhaustMap, tap } from 'rxjs';
import type { SelfhostGenerateLicenseStore } from '../stores/selfhost-generate-license';
@@ -27,9 +27,8 @@ export class SelfhostGenerateLicenseService extends Service {
return await this.store.generateKey(sessionId);
}).pipe(
smartRetry(),
mergeMap(key => {
tap(key => {
this.licenseKey$.next(key);
return EMPTY;
}),
catchErrorInto(this.error$),
onStart(() => {

View File

@@ -10,7 +10,7 @@ import {
Service,
smartRetry,
} from '@toeverything/infra';
import { EMPTY, mergeMap } from 'rxjs';
import { tap } from 'rxjs';
import type { WorkspaceService } from '../../workspace';
import type { SelfhostLicenseStore } from '../stores/selfhost-license';
@@ -36,12 +36,10 @@ export class SelfhostLicenseService extends Service {
return await this.store.getLicense(currentWorkspaceId, signal);
}).pipe(
smartRetry(),
mergeMap(data => {
tap(data => {
if (data) {
this.license$.next(data);
}
return EMPTY;
}),
catchErrorInto(this.error$),
onStart(() => this.isRevalidating$.next(true)),

View File

@@ -8,7 +8,7 @@ import {
Service,
smartRetry,
} from '@toeverything/infra';
import { catchError, EMPTY, mergeMap } from 'rxjs';
import { catchError, EMPTY, tap } from 'rxjs';
import type {
UpdateUserSettingsInput,
@@ -33,9 +33,8 @@ export class UserSettingsService extends Service {
return this.store.getUserSettings();
}).pipe(
smartRetry(),
mergeMap(settings => {
tap(settings => {
this.userSettings$.value = settings;
return EMPTY;
}),
catchError(error => {
this.error$.value = error;