diff options
author | bobzel <zzzman@gmail.com> | 2024-05-03 10:23:46 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2024-05-03 10:23:46 -0400 |
commit | 723c8b33ade753764d1d02b130c189fb65e20425 (patch) | |
tree | e278304fdace45a2c38562e72a3ccd2e8e91b759 /src/Utils.ts | |
parent | f410a7b314dd78244e18c9c52140b67b37ab0c87 (diff) | |
parent | 2caf7b7bb80b663b6ba585f88cdbd2d725f8505e (diff) |
Merge branch 'master' into nathan-starter
Diffstat (limited to 'src/Utils.ts')
-rw-r--r-- | src/Utils.ts | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/src/Utils.ts b/src/Utils.ts index 38325a463..291d7c799 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -1,13 +1,12 @@ -import { ColorResult } from 'react-color'; -import * as uuid from 'uuid'; -//import { Socket } from '../node_modules/socket.io-client'; import * as Color from 'color'; +import { ColorResult } from 'react-color'; import * as rp from 'request-promise'; -import { Socket } from '../node_modules/socket.io/dist/index'; +import { Socket } from 'socket.io'; +import * as uuid from 'uuid'; import { DocumentType } from './client/documents/DocumentTypes'; import { Colors } from './client/views/global/globalEnums'; -import { Message } from './server/Message'; import { DocumentView } from './client/views/nodes/DocumentView'; +import { Message } from './server/Message'; export namespace Utils { export let CLICK_TIME = 300; @@ -383,7 +382,7 @@ export namespace Utils { export const loggingEnabled: Boolean = false; export const logFilter: number | undefined = undefined; - function log(prefix: string, messageName: string, message: any, receiving: boolean) { + export function log(prefix: string, messageName: string, message: any, receiving: boolean) { if (!loggingEnabled) { return; } @@ -396,7 +395,7 @@ export namespace Utils { console.log(`${prefix}: ${idString}, ${receiving ? 'receiving' : 'sending'} ${messageName} with data ${JSON.stringify(message)} `); } - function loggingCallback(prefix: string, func: (args: any) => any, messageName: string) { + export function loggingCallback(prefix: string, func: (args: any) => any, messageName: string) { return (args: any) => { log(prefix, messageName, args, true); func(args); @@ -408,17 +407,6 @@ export namespace Utils { socket.emit(message.Message, args); } - export function EmitCallback<T>(socket: Socket, message: Message<T>, args: T): Promise<any>; - export function EmitCallback<T>(socket: Socket, message: Message<T>, args: T, fn: (args: any) => any): void; - export function EmitCallback<T>(socket: Socket, message: Message<T>, args: T, fn?: (args: any) => any): void | Promise<any> { - log('Emit', message.Name, args, false); - if (fn) { - socket.emit(message.Message, args, loggingCallback('Receiving', fn, message.Name)); - } else { - return new Promise<any>(res => socket.emit(message.Message, args, loggingCallback('Receiving', res, message.Name))); - } - } - export function AddServerHandler<T>(socket: Socket, message: Message<T>, handler: (args: T) => any) { socket.on(message.Message, loggingCallback('Incoming', handler, message.Name)); } @@ -653,13 +641,13 @@ export function smoothScroll(duration: number, element: HTMLElement | HTMLElemen const animateScroll = () => { const currentDate = new Date().getTime(); const currentTime = currentDate - startDate; - elements.map((element, i) => (element.scrollTop = easeFunc(transition, currentTime, starts[i], to - starts[i], duration))); - + const setScrollTop = (element: HTMLElement, value: number) => (element.scrollTop = value); if (!_stop) { if (currentTime < duration) { + elements.forEach((element, i) => currentTime && setScrollTop(element, easeFunc(transition, Math.min(currentTime, duration), starts[i], to - starts[i], duration))); requestAnimationFrame(animateScroll); } else { - elements.forEach(element => (element.scrollTop = to)); + elements.forEach(element => setScrollTop(element, to)); } } }; |