mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-25 00:20:57 -05:00
chore: clean up the patch from yesterday
This commit is contained in:
parent
cf049bd4ee
commit
ca240fb6d7
1 changed files with 17 additions and 11 deletions
|
@ -63,7 +63,10 @@ export default class State {
|
|||
this.sync = new Sync(this);
|
||||
this.plugins = new Plugins(this);
|
||||
|
||||
makeAutoObservable(this);
|
||||
makeAutoObservable(this, {
|
||||
client: false,
|
||||
});
|
||||
|
||||
this.register();
|
||||
this.setDisabled = this.setDisabled.bind(this);
|
||||
|
||||
|
@ -75,6 +78,10 @@ export default class State {
|
|||
*/
|
||||
private register() {
|
||||
for (const key of Object.keys(this)) {
|
||||
// Skip `client`.
|
||||
if (key === "client") continue;
|
||||
|
||||
// Pull out the relevant object.
|
||||
const obj = (
|
||||
this as unknown as Record<string, Record<string, unknown>>
|
||||
)[key];
|
||||
|
@ -125,20 +132,26 @@ export default class State {
|
|||
* @returns Function to dispose of listeners
|
||||
*/
|
||||
registerListeners(client?: Client) {
|
||||
// If a client is present currently, expose it and provide it to plugins.
|
||||
if (client) {
|
||||
this.client = client;
|
||||
this.plugins.onClient(client);
|
||||
}
|
||||
|
||||
// Register all the listeners required for saving and syncing state.
|
||||
const listeners = this.persistent.map(([id, store]) => {
|
||||
return reaction(
|
||||
() => stringify(store.toJSON()),
|
||||
async (value) => {
|
||||
try {
|
||||
// Save updated store to local storage.
|
||||
await localforage.setItem(id, JSON.parse(value));
|
||||
|
||||
// Skip if meta store or client not available.
|
||||
if (id === "sync") return;
|
||||
if (!client) return;
|
||||
|
||||
// Generate a new revision and upload changes.
|
||||
const revision = +new Date();
|
||||
switch (id) {
|
||||
case "settings": {
|
||||
|
@ -204,17 +217,10 @@ export default class State {
|
|||
});
|
||||
|
||||
return () => {
|
||||
// ! FIXME: quick fix
|
||||
try {
|
||||
try {
|
||||
this.client = undefined;
|
||||
} catch (err) {
|
||||
reportError(err as any, "state_L207");
|
||||
}
|
||||
} catch (err) {
|
||||
/** just for good measure */
|
||||
}
|
||||
// Stop exposing the client.
|
||||
this.client = undefined;
|
||||
|
||||
// Wipe all listeners.
|
||||
listeners.forEach((x) => x());
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue