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

@tony-builder/asyncy

v0.0.8

Published

Are you tired of null checks with `async` pipe ? use `asyncy`

Downloads

128

Readme

asyncy

Are you tired of null checks with async pipe ? use asyncy

What is asyncy

asyncy pipe is a wrapper around async pipe, with small addition. it returns T type instead of T | null . So it avoids *ngIf checks when you need to use it in template or pass async data in children components

Installation

npm install @tony-builder/asyncy --save (npm link)

Getting started

async pipe is standalone, so in order to use it, you need to import it inside component or in module.

Module

@NgModule({
    imports:[
        AsyncyPipe
    ]
  })
  export class SomeModule{}

Component

@Component({
    selector:'some-component',
    imports:[AsyncyPipe]
  })

Usage

it has the same usage as async pipe <h1> {{someAsyncData$ | asyncy}} </h1>

Differnce between async and asyncy pipe

Let's imagine we have user data that we want to pass from AppComponent to UsersComponent with async pipe it looks like this

@Component({
selector:'app-component',
imports:[AsyncyPipe],
template:"
<ng-container *ngIf="users$ | async as users">
<app-users [users]="users"> </app-users>
</ng-container>
"
})
export class AppComponent{
users$= this.userService.getAll();

}

we need to add *ngIf directive because async pipe returns null type and without this check it wont compile. It's an observable hence this is natural return type, because it might have no data upon initialization. But in lots of cases we know that we will have data, so adding *ngIf check only for the compilation fix creates additional elements in templates. In order to avoid that we can use asyncy pipe. Internally it uses async pipe so you can rely on it as you would rely on async pipe. The small difference is that it returns only T type instead of T | null. So there's no need to use *ngIf directive. Our example transforms into this

@Component({
selector:'app-component',
imports:[AsyncyPipe],
template:"
<app-users [users]="users$ | asyncy"> </app-users>
"
})
export class AppComponent{
users$= this.userService.getAll();

}