chore: rename AppSidebarLocalState to AppSidebarState

This commit is contained in:
Jimmfly
2024-09-26 10:36:27 +08:00
parent 17182fc763
commit b9e5a72cc1
4 changed files with 16 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
import { Entity, LiveData } from '@toeverything/infra';
import { map } from 'rxjs';
import type { AppSidebarLocalState } from '../providers/storage';
import type { AppSidebarState } from '../providers/storage';
const isMobile = !BUILD_CONFIG.isElectron && window.innerWidth < 768;
@@ -11,19 +11,19 @@ enum APP_SIDEBAR_STATE {
}
export class AppSidebar extends Entity {
constructor(private readonly appSidebarLocalState: AppSidebarLocalState) {
constructor(private readonly appSidebarState: AppSidebarState) {
super();
}
open$ = LiveData.from(
this.appSidebarLocalState
this.appSidebarState
.watch<boolean>(APP_SIDEBAR_STATE.OPEN)
.pipe(map(value => value ?? !isMobile)),
!isMobile
);
width$ = LiveData.from(
this.appSidebarLocalState
this.appSidebarState
.watch<number>(APP_SIDEBAR_STATE.WIDTH)
.pipe(map(value => value ?? 248)),
248
@@ -33,7 +33,7 @@ export class AppSidebar extends Entity {
resizing$ = new LiveData<boolean>(false);
getCachedAppSidebarOpenState = () => {
return this.appSidebarLocalState.get<boolean>(APP_SIDEBAR_STATE.OPEN);
return this.appSidebarState.get<boolean>(APP_SIDEBAR_STATE.OPEN);
};
toggleSidebar = () => {
@@ -41,7 +41,7 @@ export class AppSidebar extends Entity {
};
setOpen = (open: boolean) => {
this.appSidebarLocalState.set(APP_SIDEBAR_STATE.OPEN, open);
this.appSidebarState.set(APP_SIDEBAR_STATE.OPEN, open);
if (!open && this.hoverFloating$.value) {
const timeout = setTimeout(() => {
this.setHoverFloating(false);
@@ -66,6 +66,6 @@ export class AppSidebar extends Entity {
};
setWidth = (width: number) => {
this.appSidebarLocalState.set(APP_SIDEBAR_STATE.WIDTH, width);
this.appSidebarState.set(APP_SIDEBAR_STATE.WIDTH, width);
};
}

View File

@@ -4,9 +4,9 @@ import {
wrapMemento,
} from '@toeverything/infra';
import type { AppSidebarLocalState } from '../providers/storage';
import type { AppSidebarState } from '../providers/storage';
export class AppSidebarLocalStateImpl implements AppSidebarLocalState {
export class AppSidebarStateImpl implements AppSidebarState {
wrapped: Memento;
constructor(globalState: GlobalState) {
this.wrapped = wrapMemento(globalState, `app-sidebar-state:`);

View File

@@ -1,8 +1,8 @@
import { type Framework, GlobalState } from '@toeverything/infra';
import { AppSidebar } from './entities/app-sidebar';
import { AppSidebarLocalStateImpl } from './impls/storage';
import { AppSidebarLocalState } from './providers/storage';
import { AppSidebarStateImpl } from './impls/storage';
import { AppSidebarState } from './providers/storage';
import { AppSidebarService } from './services/app-sidebar';
export * from './services/app-sidebar';
@@ -10,6 +10,6 @@ export * from './services/app-sidebar';
export function configureAppSidebarModule(framework: Framework) {
framework
.service(AppSidebarService)
.entity(AppSidebar, [AppSidebarLocalState])
.impl(AppSidebarLocalState, AppSidebarLocalStateImpl, [GlobalState]);
.entity(AppSidebar, [AppSidebarState])
.impl(AppSidebarState, AppSidebarStateImpl, [GlobalState]);
}

View File

@@ -1,7 +1,6 @@
import { createIdentifier, type Memento } from '@toeverything/infra';
export interface AppSidebarLocalState extends Memento {}
export interface AppSidebarState extends Memento {}
export const AppSidebarLocalState = createIdentifier<AppSidebarLocalState>(
'AppSidebarLocalState'
);
export const AppSidebarState =
createIdentifier<AppSidebarState>('AppSidebarState');