@avalon-dota-libs/ui_utils
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

@avalon-dota-libs/ui_utils

UI 中的通用库

hex

hex(buf: string | Uint8Array): string

转换字符串为 HEX 字符串

import { hex } from '@avalon-dota-libs/ui_utils';
$.Msg(hex('test'));

EventEmitter

类似 NodeJS 的 EventEmitter

import { EventEmitter } from '@avalon-dota-libs/ui_utils';

interface MyEventTable {
    down: [key: string, ctrl: boolean];
    up: [key: string, ctrl: boolean];
}

// 创建
const emitter = new EventEmitter<MyEventTable>();
emitter.on('down', $('#MyButton'), function (key, ctrl) {
    $.Msg(key, ' ', ctrl);
});

// 发送事件
emitter.emit('down', 'Q', false);

// 继承
class MyEmitter extends EventEmitter<MyEventTable> {}

on 和 once 的第二个参数是绑定的 Panel,如果 Panel 被删除则不会触发并且自动移除掉,这对于重载非常有用

Readme

Keywords

Package Sidebar

Install

npm i @avalon-dota-libs/ui_utils

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

5.45 kB

Total Files

5

Last publish

Collaborators

  • npm