mirror of
https://github.com/jellyfin/jellyfin-vue.git
synced 2024-12-03 11:41:09 +00:00
perf&fix: some arrays to sets, defaulting state
This commit is contained in:
parent
54f0f5b11f
commit
dba7c34649
@ -333,14 +333,14 @@ class RemotePluginAuth extends CommonStore<AuthState> {
|
||||
};
|
||||
|
||||
public constructor() {
|
||||
super('auth', {
|
||||
super('auth', () => ({
|
||||
servers: [],
|
||||
currentServerIndex: -1,
|
||||
currentUserIndex: -1,
|
||||
users: [],
|
||||
rememberMe: true,
|
||||
accessTokens: {}
|
||||
}, 'localStorage');
|
||||
}), 'localStorage');
|
||||
void this.refreshCurrentUserInfo();
|
||||
void this._refreshServers();
|
||||
}
|
||||
|
@ -81,11 +81,11 @@ class ClientSettingsStore extends SyncedStore<ClientSettingsState> {
|
||||
};
|
||||
|
||||
public constructor() {
|
||||
super('clientSettings', {
|
||||
super('clientSettings', () => ({
|
||||
typography: 'default',
|
||||
darkMode: 'auto',
|
||||
locale: 'auto'
|
||||
}, 'localStorage');
|
||||
}), 'localStorage');
|
||||
/**
|
||||
* == WATCHERS ==
|
||||
*/
|
||||
|
@ -34,20 +34,20 @@ class SubtitleSettingsStore extends SyncedStore<SubtitleSettingsState> {
|
||||
public state = this._state;
|
||||
|
||||
public constructor() {
|
||||
super('subtitleSettings', {
|
||||
super('subtitleSettings', () => ({
|
||||
enabled: false,
|
||||
fontFamily: 'auto',
|
||||
fontSize: 1.5,
|
||||
positionFromBottom: 10,
|
||||
backdrop: true,
|
||||
stroke: false
|
||||
}, 'localStorage', [
|
||||
}), 'localStorage', new Set([
|
||||
'enabled',
|
||||
'fontSize',
|
||||
'positionFromBottom',
|
||||
'backdrop',
|
||||
'stroke'
|
||||
]);
|
||||
]));
|
||||
|
||||
/**
|
||||
* == WATCHERS ==
|
||||
|
@ -1013,7 +1013,7 @@ class PlaybackManagerStore extends CommonStore<PlaybackManagerState> {
|
||||
};
|
||||
|
||||
public constructor() {
|
||||
super('playbackManager', {
|
||||
super('playbackManager', () => ({
|
||||
status: PlaybackStatus.Stopped,
|
||||
currentSourceUrl: undefined,
|
||||
currentItemIndex: undefined,
|
||||
@ -1034,7 +1034,7 @@ class PlaybackManagerStore extends CommonStore<PlaybackManagerState> {
|
||||
playbackInitiator: undefined,
|
||||
playbackInitMode: InitMode.Unknown,
|
||||
playbackSpeed: 1
|
||||
});
|
||||
}));
|
||||
/**
|
||||
* Logic is divided by concerns and scope. Watchers for callbacks
|
||||
* that rely on the same variables might not be together. Categories:
|
||||
|
@ -334,10 +334,10 @@ class PlayerElementStore extends CommonStore<PlayerElementState> {
|
||||
};
|
||||
|
||||
public constructor() {
|
||||
super('playerElement', {
|
||||
super('playerElement', () => ({
|
||||
isStretched: false,
|
||||
currentExternalSubtitleTrack: undefined
|
||||
});
|
||||
}));
|
||||
|
||||
/**
|
||||
* * Move user to the fullscreen page when starting video playback by default
|
||||
|
@ -15,12 +15,12 @@ export abstract class CommonStore<T extends object> {
|
||||
}
|
||||
|
||||
protected readonly _reset = (): void => {
|
||||
Object.assign(this._state, this._defaultState);
|
||||
Object.assign(this._state, this._defaultState());
|
||||
};
|
||||
|
||||
protected constructor(storeKey: string, defaultState: T, persistence?: Persistence) {
|
||||
protected constructor(storeKey: string, defaultState: () => T, persistence?: Persistence) {
|
||||
this._storeKey = storeKey;
|
||||
this._defaultState = () => defaultState;
|
||||
this._defaultState = defaultState;
|
||||
|
||||
let storage;
|
||||
|
||||
|
@ -12,7 +12,7 @@ import { i18n } from '@/plugins/i18n';
|
||||
|
||||
export abstract class SyncedStore<T extends object> extends CommonStore<T> {
|
||||
private readonly _clientSyncName = 'vue';
|
||||
private readonly _syncedKeys: (keyof T)[] = [];
|
||||
private readonly _syncedKeys: Set<(keyof T)>;
|
||||
private readonly _effectScope = new EffectScope();
|
||||
/**
|
||||
* Serializes custom pref values for storage as string
|
||||
@ -130,27 +130,19 @@ export abstract class SyncedStore<T extends object> extends CommonStore<T> {
|
||||
*
|
||||
* @param keys - The keys to be synced with the server. If not provided, all keys will be synced
|
||||
*/
|
||||
protected constructor(storeKey: string, defaultState: T, persistence?: Persistence, keys?: (keyof T)[]) {
|
||||
protected constructor(storeKey: string, defaultState: () => T, persistence?: Persistence, keys?: Set<(keyof T)>) {
|
||||
super(storeKey, defaultState, persistence);
|
||||
this._syncedKeys = keys ?? [];
|
||||
this._syncedKeys = keys ?? new Set(Object.keys(defaultState()) as (keyof T)[]);
|
||||
|
||||
if (!this._syncedKeys.length) {
|
||||
for (const key in defaultState) {
|
||||
this._syncedKeys.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (keys?.length) {
|
||||
for (const key of keys) {
|
||||
this._effectScope.run(() => {
|
||||
this._effectScope.run(() => {
|
||||
if (keys?.size) {
|
||||
for (const key of keys) {
|
||||
watchDeep(() => this._state[key], this._updateState);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
this._effectScope.run(() => {
|
||||
}
|
||||
} else {
|
||||
watchDeep(() => this._state, this._updateState);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Trigger sync when the user logs in
|
||||
|
@ -106,10 +106,10 @@ class TaskManagerStore extends CommonStore<TaskManagerState> {
|
||||
};
|
||||
|
||||
public constructor() {
|
||||
super('taskManager', {
|
||||
super('taskManager', () => ({
|
||||
tasks: [],
|
||||
finishedTasksTimeout: 5000
|
||||
}, 'sessionStorage');
|
||||
}), 'sessionStorage');
|
||||
|
||||
/**
|
||||
* Handle refresh progress update for library items
|
||||
|
Loading…
Reference in New Issue
Block a user