npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@taiga-ui/event-plugins

v4.3.1

Published

This is a library for optimizing performance sensitive events and declarative preventDefault and stopPropagation

Downloads

17,882

Readme

Angular Event Plugins

npm version npm bundle size Coverage Status telegram chat

@taiga-ui/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 NG_EVENT_PLUGINS to your app providers:

    bootstrapApplication(AppComponent, {
      providers: [NG_EVENT_PLUGINS],
    });
  2. 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
    • resize to watch for elements changing dimensions with ResizeObserver

    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>
  3. 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 '@taiga-ui/event-plugins';

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

// ...

@shouldCall(scrollFilter)
onScroll(_element: HTMLElement): void {
    this.someService.requestMoreData();
}
  1. Angular global events only support body, window and document. You can listen to events on any global object with these plugins by replacing : with > symbol, for example:
@HostListener('visualViewport>resize', ['$event.target'])
onPinchZoom({ scale }: VisualViewport) {
    console.log(scale)
}
  1. iOS currently doesn't support the contextmenu event. Instead, you can use a custom longtap event. This event captures the contextmenu event on non-iOS devices and simulates similar behavior on iOS devices.
<div (longtap)="showContextMenu($event.detail.clientX, $event.detail.clientY)">Div with context menu</div>

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.

  • .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.

Demo

You can try this interactive demo

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

Maintained

@taiga-ui/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 @taiga-ui/event-plugins packages are covered by Apache 2.0

Read more about this license here