• Stars
    star
    233
  • Rank 172,170 (Top 4 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This is an Angular library for optimizing performance sensitive events and declarative preventDefault, stopPropagation and capture phase listeners.

Angular Event Plugins

npm version npm bundle size Coverage Status angular-open-source-starter telegram chat

@tinkoff/ng-event-plugins is a tiny (1KB gzip) library for optimizing change detection cycles for performance sensitive events (such as touchmove, scroll, drag etc.) and declarative preventDefault() and stopPropagation().

How to use

  1. Add EventPluginsModule to your app module:

    import {NgModule} from '@angular/core';
    import {BrowserModule} from '@angular/platform-browser';
    import {EventPluginsModule} from '@tinkoff/ng-event-plugins'; // <-- THIS
    
    @NgModule({
      bootstrap: [
        /*...*/
      ],
      imports: [
        /*...*/
        BrowserModule,
        EventPluginsModule, // <-- GOES HERE
      ],
      declarations: [
        /*...*/
      ],
    })
    export class AppModule {}

BrowserModule or BrowserAnimationsModule must go first. You will see a warning if you mess the order.

  1. Use new modifiers for events in templates and in @HostListener:

    • .stop to call stopPropagation() on event
    • .prevent to call preventDefault() on event
    • .self to skip bubbled events
    • .silent to call event handler outside Angular's NgZone
    • .capture to listen to events in capture phase
    • .passive to add passive event listener
    • .once to remove event listener after first callback

    For example:

    <div (mousedown.prevent)="onMouseDown()">Clicking on this DIV will not move focus</div>
    <div (click.stop)="onClick()">Clicks on this DIV will not bubble up</div>
    <div (mousemove.silent)="onMouseMove()">Callbacks to mousemove will not trigger change detection</div>
    <div (click.capture.stop)="onClick()">
      <div (click)="never()">Clicks will be stopped before reaching this DIV</div>
    </div>
  2. You can also re-enter NgZone and trigger change detection, using @shouldCall decorator that takes a predicate function as argument:

<div (scroll.silent)="onScroll($event.currentTarget)">
  Scrolling this DIV will only trigger change detection and onScroll callback if it is scrolled to bottom
</div>
import {shouldCall} from '@tinkoff/ng-event-plugins';

export function scrollFilter({
 scrollTop, scrollHeight, clientHeight
}: HTMLElement): boolean {
    return scrollTop === scrollHeight - clientHeight;
}

// ...

@shouldCall(scrollFilter)
onScroll(_element: HTMLElement): void {
    this.someService.requestMoreData();
}

All examples above work the same when used with @HostListener and CustomEvent

Important notes

  • Predicate is called with the same arguments as the decorated method and in the context of class instance (has access to this)

  • Decorated method will be called and change detection triggered if predicate returns true.

  • Predicates must be exported named function for AOT, arrow functions will trigger build error.

  • .silent modifier will not work with built-in keyboard pseudo-events, such as keydown.enter or keydown.arrowDown since Angular re-enters NgZone inside internal handlers.

Observable host bindings

In this library there's also a plugin that enables observable host bindings. Sounds weird to do host binding with event plugin, but the code is actually pretty simple. You can read more about it in this article.

To use it you need to couple @HostListener and @HostBinding on the same Observable property with following syntax:

@HostBinding('$.disabled')
@HostListener('$.disabled')
readonly disabled$ = asCallable(this.service.loading$)

This supports all the native Angular syntax, such as class.class-name or style.width.px.

IMPORTANT NOTES:

  • Until this issue is resolved you would have to use NO_ERRORS_SCHEMA in your module in order to bind to arbitrary properties
  • asCallable is a utility function from this library that simply adds Function to the type so Angular thinks it could be a host listener
  • To bind attributes you need to add .attr modifier in the end, not the beginning like in basic Angular binding. This is due to Angular using regexp to match for attr. string in @HostBinding decorator:
@HostBinding('$.aria-label.attr')
@HostListener('$.aria-label.attr')
readonly label$ = asCallable(this.translations.get$('label'));

Demo

You can try this interactive demo

You can also read this detailed article explaining how this library works

Maintained

@tinkoff/ng-event-plugins is a part of Taiga UI libraries family which is backed and used by a large enterprise. This means you can rely on timely support and continuous development.

License

🆓 Feel free to use our library in your commercial and private applications

All @tinkoff/ng-event-plugins packages are covered by Apache 2.0

Read more about this license here

Open-source

Do you also want to open-source something, but hate the collateral work? Check out this Angular Open-source Library Starter we’ve created for our projects. It got you covered on continuous integration, pre-commit checks, linting, versioning + changelog, code coverage and all that jazz.

More Repositories

1

taiga-ui

Angular UI Kit and components library for awesome people
TypeScript
2,658
star
2

career

Информация о внутренней кухне Тинькофф, включая подготовку к собеседованию
745
star
3

ng-web-apis

A set of common utils for consuming Web APIs with Angular
TypeScript
609
star
4

invest-openapi

Документация для Тинькофф Инвестиции OpenApi
HTML
457
star
5

investAPI

HTML
393
star
6

ng-polymorpheus

Polymorpheus is a tiny library for polymorphic templates in Angular.
TypeScript
335
star
7

invest-python

Tinkoff Invest Python gRPC client
Python
309
star
8

maskito

Collection of libraries to create an input mask which ensures that user types value according to predefined format.
TypeScript
270
star
9

angular-open-source-starter

This is a starter project for creating open-source libraries for Angular. It is a full fledged Angular workspace with demo application and easy library addition. It is designed to be used for open-sourcing libraries on Github and has everything you'd need ready for CI, code coverage, SSR testing, StackBlitz demo deployment and more.
TypeScript
252
star
10

tramvai

A modular framework for universal JS applications
TypeScript
230
star
11

invest-openapi-js-sdk

TypeScript
211
star
12

utils.js

Fast, small and purely functional utility library
TypeScript
179
star
13

invest-openapi-java-sdk

Java
167
star
14

kora

Java
167
star
15

invest-openapi-go-sdk

Go
153
star
16

Nginx-builder

A tool to build deb or rpm package of required Nginx version from the source code, with the ability to connect third-party modules. Nginx parameters are set in the yaml configuration file.
Python
153
star
17

invest-robot-contest

Конкурс разработчиков торговых роботов на API Тинькофф Инвестиций
144
star
18

ng-morph

Code mutations in your project or schematics were never easier than now.
TypeScript
124
star
19

linters

Tinkoff ESlint, Stylelint and Prettier linter configurations
JavaScript
124
star
20

micro-sentry

Tiny Sentry client with idiomatic wrapper for Angular
TypeScript
117
star
21

libvirt-exporter

Prometheus metrics exporter for libvirt.
Go
105
star
22

invest-openapi-csharp-sdk

C#
100
star
23

microzord

Simple and powerful Micro Frontends framework
TypeScript
93
star
24

phobos

Efficient and expressive XML data-binding library for Scala
Scala
91
star
25

stapp

Modular state and side-effects management for microfrontends
TypeScript
90
star
26

jira-helper

Jira Helper - adds visual elements for swimlanes, a button for adding a task description template.
JavaScript
87
star
27

ng-dompurify

Inclusive Angular API for DOMPurify
TypeScript
85
star
28

invest-api-java-sdk

Tinkoff Invest API Java SDK
Java
74
star
29

overhave

Web-framework for BDD: scalable, configurable, easy to use, based on Flask Admin and Pydantic.
JavaScript
71
star
30

gatling-kafka-plugin

Plugin for support Kafka in Gatling
Scala
62
star
31

tinkoff-request

Modular lightweight request library extendable by plugins.
TypeScript
60
star
32

Horarium

Horarium is the .Net library to manage background jobs
C#
56
star
33

voicekit-examples

Examples on how to use Tinkoff Voicekit
C#
55
star
34

mockingbird

Flexible mock server
Scala
55
star
35

invest-api-csharp-sdk

C#
51
star
36

data-detective

Data catalog for everything in your company
Python
50
star
37

QVisual

Tinkoff tool to control quality by visual testing
Java
48
star
38

angular-contenteditable-accessor

This accessor allows you to use Angular forms with contenteditable elements with ease. It has zero dependencies, other than Angular itself as peer and works with Angular 4+ in all modern browsers, including Internet Explorer 11
TypeScript
46
star
39

eclair

Java Spring library for declarative logging
Java
41
star
40

invest-api-go-sdk

SDK для работы с API Тинькофф Инвестиций
Go
41
star
41

aerospike-scala

Typesafe DSL for work with Aerospike Database
Scala
40
star
42

perfectum

A set of tools for working with project performance
TypeScript
40
star
43

cachalot

Cache manager for nodejs with support different cache strategies
TypeScript
39
star
44

gatling-picatinny

Library with a bunch of usefull functions that extend Gatling DSL and make your performance better
Scala
37
star
45

muffin

Mattermost API v4 Client for Scala
Scala
36
star
46

shared-library-webpack-plugin

Webpack plugin for library sharing at runtime between applications
TypeScript
36
star
47

asterisk-voicekit-modules

Non-blocking Asterisk modules for accessing VoiceKit services for speech recognition and speech synthesis.
Shell
35
star
48

dm-knowledgebase

База знаний профессии Деливери менеджер https://tinkoff.github.io/dm-knowledgebase/
JavaScript
34
star
49

go-course-for-students

HTML
33
star
50

gatling-amqp-plugin

Plugin for support performance testing with AMQP in Gatling (3.7.x)
Scala
33
star
51

camunda-delegator-lib

This project provides declarative camunda delegates for Spring based application
Kotlin
32
star
52

Allure.XUnit

Allure.XUnit is a library for displaying xunit .NET Core and .NET 5 tests in Allure reports.
C#
30
star
53

neptune

Test automation framework
Java
29
star
54

gradle-jarjar

Plugin for gradle which allows you to repackage jar-libraries with different package names using JarJar tool
Groovy
28
star
55

pvm

TypeScript
28
star
56

sage-community

Shell
28
star
57

react-styling-hoc

Механизм темизации для React-компонентов, написанных с использованием CSS модулей.
JavaScript
26
star
58

react-render-logger

Simple util for log component updates
JavaScript
24
star
59

uconfig

Lightweight, header-only, C++17 configuration library
C++
22
star
60

react-lazy-hydration-render

TypeScript
22
star
61

stream-client

Lightweight, header-only, Boost-based socket pool library
C++
22
star
62

gatling-template.g8

A Giter8 template for gatling performance test project
Scala
22
star
63

gatling-jdbc-plugin

Simple gatling plugin for JDBC
Scala
21
star
64

argus

GitHub App for screenshots tests in CI
TypeScript
18
star
65

invest-js

TypeScript
18
star
66

ScalaDatabase

Scala Database wrapper based on JDBC
Scala
17
star
67

navigation-skeleton

This component allows you to show skeletons of pages during navigation process.
TypeScript
17
star
68

Ogam3

Data transfer protocol based on a lightweight implementation of Scheme programming language written on C# for .NET enterprise development.
C#
14
star
69

ISA

Information Search Assistant
C#
13
star
70

voicekit_client_python

Tinkoff Voicekit Python client
Python
12
star
71

checkinx-utils

DB execution plan asserts
Kotlin
11
star
72

swagger-types-generator

generate typescript types using a swagger schema
TypeScript
11
star
73

oolong

Oolong - compile-time query generation for document stores
Scala
10
star
74

uri-template

URI Templates expansion and reverse-matching for C++
C++
9
star
75

server-request-timer

A library for analyzing request execution
TypeScript
9
star
76

tui-editor

Rich text editor extension with related Taiga UI components https://tinkoff.github.io/tui-editor
TypeScript
7
star
77

mbclient

Message Broker Client/Server
TypeScript
6
star
78

tui-ngrx-forms-adapter

TypeScript
6
star
79

deimos

Scala
6
star
80

business-openapi

Репозиторий для обратной связи по Tinkoff Business OpenApi
6
star
81

tinkoff-id

HTML
5
star
82

cassandra-ansible-role

Cassandra ansible role with custom libs, backups, and other things
Jinja
3
star
83

tokenizer

TypeScript
3
star
84

sbt-schema-registry-plugin

Sbt plugin for download schemas from schema registry
Scala
3
star
85

tinkoff-asdk-windows

Tinkoff Acquiring SDK for Windows
C#
3
star
86

gatling-samples

Samples gatling scripts with plugins
Scala
3
star
87

receipt2vec

Tool for feature extracting from receipts from Russian stores
Python
3
star
88

AllurePlugin.emceeplugin

Swift
2
star
89

dolyamesdk-ios

Dolyame SDK for iOS
HTML
2
star
90

api_asdk

Interactive API documentation on reDOC for Acquiring SDK
HTML
2
star
91

react-pixi-racing-game

TypeScript
2
star
92

logrus-sage-formatter

Go
1
star
93

tinkoff.github.io

JavaScript
1
star
94

github-analytics

An application to see various charts and stats on GitHub repositories
TypeScript
1
star
95

slack-pr-bot

C#
1
star
96

xk6-output-error

A k6 extension for add more information into StdErr
Go
1
star
97

voicekit-docs

1
star