chore: add type for connection
This commit is contained in:
parent
3d39daff8c
commit
93e80353eb
4 changed files with 22 additions and 16 deletions
|
@ -43,7 +43,7 @@
|
|||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, onUnmounted, ref } from "vue";
|
||||
import type { entities, notificationTypes } from "firefish-js";
|
||||
import type { StreamTypes, entities, notificationTypes } from "firefish-js";
|
||||
import MkPagination from "@/components/MkPagination.vue";
|
||||
import XNotification from "@/components/MkNotification.vue";
|
||||
import XList from "@/components/MkDateSeparatedList.vue";
|
||||
|
@ -98,7 +98,7 @@ const onNotification = (notification: entities.Notification) => {
|
|||
}
|
||||
};
|
||||
|
||||
let connection;
|
||||
let connection: StreamTypes.ChannelOf<"main"> | undefined;
|
||||
|
||||
onMounted(() => {
|
||||
connection = stream.useChannel("main");
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onUnmounted, provide, ref } from "vue";
|
||||
import type { entities } from "firefish-js";
|
||||
import type { entities, StreamTypes } from "firefish-js";
|
||||
import MkPullToRefresh from "@/components/MkPullToRefresh.vue";
|
||||
import XNotes from "@/components/MkNotes.vue";
|
||||
import MkInfo from "@/components/MkInfo.vue";
|
||||
|
@ -97,13 +97,16 @@ let query: {
|
|||
} = {};
|
||||
|
||||
// FIXME: The type defination is wrong here, need fix
|
||||
let connection: {
|
||||
on: (
|
||||
arg0: string,
|
||||
arg1: { (note: any): void; (note: any): void; (note: any): void },
|
||||
) => void;
|
||||
dispose: () => void;
|
||||
};
|
||||
let connection:
|
||||
| StreamTypes.ChannelOf<"antenna">
|
||||
| StreamTypes.ChannelOf<"homeTimeline">
|
||||
| StreamTypes.ChannelOf<"recommendedTimeline">
|
||||
| StreamTypes.ChannelOf<"hybridTimeline">
|
||||
| StreamTypes.ChannelOf<"globalTimeline">
|
||||
| StreamTypes.ChannelOf<"main">
|
||||
| StreamTypes.ChannelOf<"userList">
|
||||
| StreamTypes.ChannelOf<"channel">
|
||||
|
||||
let connection2: { dispose: () => void } | null;
|
||||
|
||||
let tlHint: string;
|
||||
|
|
|
@ -236,14 +236,14 @@ export default class Stream extends EventEmitter<StreamEvents> {
|
|||
// TODO: これらのクラスを Stream クラスの内部クラスにすれば余計なメンバをpublicにしないで済むかも?
|
||||
// もしくは @internal を使う? https://www.typescriptlang.org/tsconfig#stripInternal
|
||||
class Pool {
|
||||
public channel: string;
|
||||
public channel: keyof Channels;
|
||||
public id: string;
|
||||
protected stream: Stream;
|
||||
public users = 0;
|
||||
private disposeTimerId: any;
|
||||
private isConnected = false;
|
||||
|
||||
constructor(stream: Stream, channel: string, id: string) {
|
||||
constructor(stream: Stream, channel: keyof Channels, id: string) {
|
||||
this.channel = channel;
|
||||
this.stream = stream;
|
||||
this.id = id;
|
||||
|
@ -301,7 +301,7 @@ class Pool {
|
|||
export abstract class Connection<
|
||||
Channel extends AnyOf<Channels> = any,
|
||||
> extends EventEmitter<Channel["events"]> {
|
||||
public channel: string;
|
||||
public channel: keyof Channels;
|
||||
protected stream: Stream;
|
||||
public abstract id: string;
|
||||
|
||||
|
@ -309,7 +309,7 @@ export abstract class Connection<
|
|||
public inCount = 0; // for debug
|
||||
public outCount = 0; // for debug
|
||||
|
||||
constructor(stream: Stream, channel: string, name?: string) {
|
||||
constructor(stream: Stream, channel: keyof Channels, name?: string) {
|
||||
super();
|
||||
|
||||
this.stream = stream;
|
||||
|
@ -342,7 +342,7 @@ class SharedConnection<
|
|||
return this.pool.id;
|
||||
}
|
||||
|
||||
constructor(stream: Stream, channel: string, pool: Pool, name?: string) {
|
||||
constructor(stream: Stream, channel: keyof Channels, pool: Pool, name?: string) {
|
||||
super(stream, channel, name);
|
||||
|
||||
this.pool = pool;
|
||||
|
@ -364,7 +364,7 @@ class NonSharedConnection<
|
|||
|
||||
constructor(
|
||||
stream: Stream,
|
||||
channel: string,
|
||||
channel: keyof Channels,
|
||||
id: string,
|
||||
params: Channel["params"],
|
||||
) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import type {
|
|||
User,
|
||||
UserGroup,
|
||||
} from "./entities";
|
||||
import type { Connection } from "./streaming";
|
||||
|
||||
type FIXME = any;
|
||||
|
||||
|
@ -199,3 +200,5 @@ export type BroadcastEvents = {
|
|||
emoji: CustomEmoji;
|
||||
}) => void;
|
||||
};
|
||||
|
||||
export type ChannelOf<C extends keyof Channels> = Connection<Channels[C]>;
|
||||
|
|
Loading…
Reference in a new issue