Update dependencies

This commit is contained in:
Tangent 2020-11-06 12:52:28 -05:00
parent f624148464
commit 1ef5565be1
4 changed files with 301 additions and 302 deletions

View file

@ -1,11 +1,10 @@
import { Callbag, Source } from "callbag";
import create from "callbag-create";
import pipe from "callbag-pipe";
import share from "callbag-share";
import { Jsonified } from "../ecs/Data";
import { catchTalkback, defer, interval, makeSubject, map, merge } from "../utilities/Callbag";
import { ClientMessage, MessageTypes, ServerMessage } from "./LockstepClient";
import { catchTalkback, defer } from "../utilities/Callbag";
import { ClientMessage, ServerMessage } from "./LockstepClient";
type Server<LocalInput, State> = Callbag<ClientMessage<LocalInput, State>, ServerMessage<LocalInput[], State>>;
@ -16,13 +15,13 @@ export class Connection<LocalInput, State> {
private url: string
) { }
public readonly socket = defer(() => {
public readonly socket: Server<LocalInput, State> = defer(() => {
const ws = new WebSocket(this.url);
const source: Source<ServerMessage<LocalInput[], State>> = create((data, { }, close) => {
const source: Source<ServerMessage<LocalInput[], State>> = create((next: (data: ServerMessage<LocalInput[], State>) => void, { }, close) => {
ws.onmessage = msg => {
const decoded: Jsonified<ServerMessage<LocalInput[], State>> = JSON.parse(msg.data);
data(decoded as ServerMessage<LocalInput[], State>);
next(decoded as ServerMessage<LocalInput[], State>);
};
ws.onclose = () => {
close();

View file

@ -196,11 +196,11 @@ export function map<I, O, TB>(f: (input: I) => O): (source: Callbag<TB, I>) => C
export function catchTalkback<T, TB>(talkbackHandler: (data: TB) => void): (source: Source<T>) => Callbag<TB, T> {
return (source: Source<T>) => (type: START | DATA | END, data?: Callbag<T, TB> | TB) => {
if (type !== 0) return;
let sourceTalkback: Callbag<void, unknown> | undefined;
let sourceTalkback: Callbag<never, unknown> | undefined;
const sink = data as Callbag<T, TB>;
source(0, (type: START | DATA | END, data?: Callbag<void, unknown> | T) => {
source(0, (type: START | DATA | END, data?: Callbag<never, unknown> | T) => {
if (type === 0) {
sourceTalkback = data as Callbag<void, unknown>;
sourceTalkback = data as Callbag<never, unknown>;
sink(0, (type: START | DATA | END, data?: Callbag<T, TB> | TB) => {
if (type === 1) {
talkbackHandler(data as TB);