Add MobX store, create observable User.

This commit is contained in:
Paul
2021-07-29 12:41:28 +01:00
parent 781fa5de10
commit cf3930b094
10 changed files with 247 additions and 61 deletions

View File

@@ -14,6 +14,7 @@ import { AuthState } from "../../redux/reducers/auth";
import Preloader from "../../components/ui/Preloader";
import { useData } from "../../mobx/State";
import { Children } from "../../types/Preact";
import { useIntermediate } from "../intermediate/Intermediate";
import { registerEvents, setReconnectDisallowed } from "./events";
@@ -157,9 +158,10 @@ function Context({ auth, children }: Props) {
};
}, [client, auth.active]);
const store = useData();
useEffect(
() => registerEvents({ operations }, setStatus, client),
[client],
() => registerEvents({ operations }, setStatus, client, store),
[client, store],
);
useEffect(() => {

View File

@@ -5,6 +5,8 @@ import { StateUpdater } from "preact/hooks";
import { dispatch } from "../../redux";
import { DataStore } from "../../mobx";
import { useData } from "../../mobx/State";
import { ClientOperations, ClientStatus } from "./RevoltClient";
export var preventReconnect = false;
@@ -18,6 +20,7 @@ export function registerEvents(
{ operations }: { operations: ClientOperations },
setStatus: StateUpdater<ClientStatus>,
client: Client,
store: DataStore,
) {
function attemptReconnect() {
if (preventReconnect) return;
@@ -45,6 +48,7 @@ export function registerEvents(
},
packet: (packet: ClientboundNotification) => {
store.packet(packet);
switch (packet.type) {
case "ChannelStartTyping": {
if (packet.user === client.user?._id) return;

View File

@@ -5,7 +5,7 @@ import Collection from "revolt.js/dist/maps/Collection";
import { useContext, useEffect, useState } from "preact/hooks";
//#region Hooks v1
//#region Hooks v1 (deprecated)
import { AppContext } from "./RevoltClient";
export interface HookContext {
@@ -238,7 +238,7 @@ export function useServerPermission(id: string, context?: HookContext) {
}
//#endregion
//#region Hooks v2
//#region Hooks v2 (deprecated)
type CollectionKeys = Exclude<
keyof PickProperties<Client, Collection<any>>,
undefined
@@ -249,7 +249,7 @@ interface Depedency {
id?: string;
}
export function useData<T>(
export function useDataDeprecated<T>(
cb: (client: Client) => T,
dependencies: Depedency[],
): T {