3.2.1 • Published 12 months ago

brandup-ui v3.2.1

Weekly downloads
10
License
Apache-2.0
Repository
github
Last release
12 months ago

brandup-ui

Build Status

Installation

Install NPM package brandup-ui.

npm i brandup-ui@latest

UIElement

UIElement - wrapper для HTMLElement, который позволяет привязать к нему свою бизнес логику.

Возможности:

  • Обработка комманд вызванных внутри HTMLElement, который связан с UIElement.
  • Обработка событий элемента HTMLElement, который связан с UIElement.
abstract class UIElement {
    abstract typeName: string;
    readonly element: HTMLElement;

    protected setElement(elem: HTMLElement): void;

    protected defineEvent(eventName: string, eventOptions?: IEventOptions): void;
    protected raiseEvent(eventName: string, eventArgs?: any): boolean;

    addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
    removeEventListener(type: string, listener?: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
    dispatchEvent(event: Event): boolean;

    registerCommand(name: string, execute: CommandDelegate, canExecute: CommandCanExecuteDelegate = null): void;
    registerAsyncCommand(name: string, delegate: CommandAsyncDelegate): void;
    hasCommand(name: string): boolean;
    execCommand(name: string, elem: HTMLElement): CommandExecutionResult;
    
    protected _onRenderElement(_elem: HTMLElement);
    protected _onCanExecCommand(_name: string, _elem: HTMLElement): boolean;

    destroy(): void;
}

Command handling

Класс UIElement позволяет регистрировать обработчики комманд, которые определяются в разметке HTML элемента.

<button data-command="send">Send</button>

this.registerCommand("send", (elem: HTMLElement, context: CommandContext) => { elem.innerHTML = "ok"; });

Так же можно регистрировать асинхронные команды:

this.registerAsyncCommand("command1-async", (context: CommandAsyncContext) => {
    context.timeout = 3000;

    context.target.innerHTML = "Loading...";
    const t = window.setTimeout(() => {
        context.target.innerHTML = "Ok";
        context.complate();
    }, 2000);

    context.timeoutCallback = () => {
        clearTimeout(t);
    };
});

Команды вызываются по событию click.

Во время выполнения команды, у элемента добавляется стиль executing.

3.2.1

12 months ago

2.2.1

1 year ago

2.2.3

1 year ago

2.2.2

1 year ago

2.2.4

1 year ago

2.2.7

1 year ago

3.0.4

12 months ago

3.0.3

12 months ago

3.0.1

12 months ago

2.3.8

12 months ago

2.3.7

12 months ago

2.3.2

1 year ago

2.3.1

1 year ago

2.3.3

12 months ago

3.1.3

12 months ago

3.1.2

12 months ago

3.1.1

12 months ago

3.1.5

12 months ago

3.1.4

12 months ago

2.0.9

1 year ago

2.0.8

1 year ago

2.0.7

2 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.6

3 years ago

1.1.14

4 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.1

5 years ago

1.1.2

5 years ago

1.0.47

5 years ago

1.0.46

5 years ago

1.0.45

5 years ago

1.0.43

5 years ago

1.0.42

5 years ago

1.0.41

5 years ago

1.0.34

6 years ago

1.0.33

6 years ago

1.0.29

6 years ago

1.0.28

6 years ago

1.0.27

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.15

6 years ago