ngx-extended-async-pipe
Advanced tools
Comparing version 1.0.1 to 2.0.0
{ | ||
"name": "ngx-extended-async-pipe", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Extended version of Angular's async pipe with customizable default, initial and error behavior", | ||
@@ -23,3 +23,3 @@ "homepage": "https://github.com/dscheerens/ngx-extended-async-pipe", | ||
"peerDependencies": { | ||
"@angular/core": ">=13.0.0", | ||
"@angular/core": ">=14.0.0", | ||
"rxjs": "^6 || ^7" | ||
@@ -32,3 +32,3 @@ }, | ||
"fesm2015": "fesm2015/ngx-extended-async-pipe.mjs", | ||
"typings": "ngx-extended-async-pipe.d.ts", | ||
"typings": "index.d.ts", | ||
"exports": { | ||
@@ -39,3 +39,3 @@ "./package.json": { | ||
".": { | ||
"types": "./ngx-extended-async-pipe.d.ts", | ||
"types": "./index.d.ts", | ||
"esm2020": "./esm2020/ngx-extended-async-pipe.mjs", | ||
@@ -42,0 +42,0 @@ "es2020": "./fesm2020/ngx-extended-async-pipe.mjs", |
@@ -18,3 +18,3 @@ [![Build Status](https://github.com/dscheerens/ngx-extended-async-pipe/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/dscheerens/ngx-extended-async-pipe/actions/workflows/main.yml) [![NPM Version](https://img.shields.io/npm/v/ngx-extended-async-pipe.svg)](https://www.npmjs.com/package/ngx-extended-async-pipe) | ||
## Installation & usage | ||
## Installation | ||
@@ -27,4 +27,15 @@ First you will need to install the `ngx-extended-async-pipe` package and add it as a dependency to your project. | ||
Next simply import the `ExtendedAsyncPipeModule` in the modules where you wish to use it: | ||
### Angular version compatibility matrix | ||
Use the compatibility matrix below to determine which version of this module works with your project's Angular version. | ||
| Library version | Angular version | | ||
| ------------------------------------- | --------------- | | ||
| `ngx-extended-async-pipe` - **1.x.x** | >= **13.0.0** | | ||
| `ngx-extended-async-pipe` - **2.x.x** | >= **14.0.0** | | ||
## Usage | ||
After having installed the package `ngx-extended-async-pipe`, simply import the `ExtendedAsyncPipeModule` in the modules where you wish to use it: | ||
```typescript | ||
@@ -54,2 +65,21 @@ import { CommonModule } from '@angular/common'; | ||
### Usage in standalone components | ||
Since Angular 14 it is possible to define [standalone components](https://angular.io/guide/standalone-components). | ||
For such components rather than using `ExtendedAsyncPipeModule` opt for importing `ExtendedAsyncPipe`: | ||
```typescript | ||
import { Component } from '@angular/core'; | ||
import { ExtendedAsyncPipe } from 'ngx-extended-async-pipe'; | ||
@Component({ | ||
// ... | ||
standalone: true, | ||
imports: [ | ||
ExtendedAsyncPipe, | ||
], | ||
}) | ||
export class MyComponent { } | ||
``` | ||
## Features | ||
@@ -59,3 +89,3 @@ | ||
An inconvenient thing about Angular's async pipe that it returns `null` by default. | ||
An inconvenience of Angular's async pipe that it returns `null` by default. | ||
If you have the [`strictNullChecks`](https://www.typescriptlang.org/tsconfig#strictNullChecks) and [`strictTemplates`](https://angular.io/guide/template-typecheck) compiler options enabled (both of which are highly recommended!) this often leads to conflicts. | ||
@@ -68,3 +98,3 @@ A common example is when it is used when binding (optional) input properties where you frequently end up with expressions such as: | ||
In fact, this happens so frequently that it might make sense for your project to have version of the async pipe that uses `undefined` as default value rather than `null`. | ||
In fact, this happens so frequently that it might make sense for your project to have a version of the async pipe that uses `undefined` as default value rather than `null`. | ||
With `ngx-extended-async-pipe` this is as simple as importing the module in the following way: | ||
@@ -84,2 +114,19 @@ | ||
Note that the above does not work for [standalone components](https://angular.io/guide/standalone-components). | ||
Instead use `ExtendedAsyncPipeWithUndefinedAsDefault`: | ||
```typescript | ||
import { Component } from '@angular/core'; | ||
import { ExtendedAsyncPipeWithUndefinedAsDefault } from 'ngx-extended-async-pipe'; | ||
@Component({ | ||
// ... | ||
standalone: true, | ||
imports: [ | ||
ExtendedAsyncPipeWithUndefinedAsDefault, | ||
], | ||
}) | ||
export class MyComponent { } | ||
``` | ||
### Overriding the initial value | ||
@@ -86,0 +133,0 @@ |
@@ -7,9 +7,15 @@ import { ModuleWithProviders } from '@angular/core'; | ||
* | ||
* Inside standalone components import `ExtendedAsyncPipe` instead. | ||
* | ||
* **If you also import the `CommonModule` from `@angular/common` make sure to place the `ExtendedAsyncPipeModule` after it.** | ||
*/ | ||
export declare class ExtendedAsyncPipeModule { | ||
/** This will use a different version of the extended `async` pipe that uses `undefined` instead of `null` as default value. */ | ||
/** | ||
* This will use a different version of the extended `async` pipe that uses `undefined` instead of `null` as default value. | ||
* | ||
* Inside standalone components import `ExtendedAsyncPipeWithUndefinedAsDefault` instead. | ||
*/ | ||
static withUndefinedAsDefault(): ModuleWithProviders<ɵExtendedAsyncPipeModuleWithUndefinedAsDefault>; | ||
static ɵfac: i0.ɵɵFactoryDeclaration<ExtendedAsyncPipeModule, never>; | ||
static ɵmod: i0.ɵɵNgModuleDeclaration<ExtendedAsyncPipeModule, [typeof i1.ExtendedAsyncPipeWithNullAsDefault], never, [typeof i1.ExtendedAsyncPipeWithNullAsDefault]>; | ||
static ɵmod: i0.ɵɵNgModuleDeclaration<ExtendedAsyncPipeModule, never, [typeof i1.ExtendedAsyncPipe], [typeof i1.ExtendedAsyncPipe]>; | ||
static ɵinj: i0.ɵɵInjectorDeclaration<ExtendedAsyncPipeModule>; | ||
@@ -24,4 +30,4 @@ } | ||
static ɵfac: i0.ɵɵFactoryDeclaration<ɵExtendedAsyncPipeModuleWithUndefinedAsDefault, never>; | ||
static ɵmod: i0.ɵɵNgModuleDeclaration<ɵExtendedAsyncPipeModuleWithUndefinedAsDefault, [typeof i1.ExtendedAsyncPipeWithUndefinedAsDefault], never, [typeof i1.ExtendedAsyncPipeWithUndefinedAsDefault]>; | ||
static ɵmod: i0.ɵɵNgModuleDeclaration<ɵExtendedAsyncPipeModuleWithUndefinedAsDefault, never, [typeof i1.ExtendedAsyncPipeWithUndefinedAsDefault], [typeof i1.ExtendedAsyncPipeWithUndefinedAsDefault]>; | ||
static ɵinj: i0.ɵɵInjectorDeclaration<ɵExtendedAsyncPipeModuleWithUndefinedAsDefault>; | ||
} |
@@ -5,6 +5,3 @@ import { ChangeDetectorRef, OnDestroy, PipeTransform } from '@angular/core'; | ||
import * as i0 from "@angular/core"; | ||
/** | ||
* A drop-in replacement for the `async` pipe from `@angular/common` with additional options. | ||
*/ | ||
export declare abstract class ExtendedAsyncPipe<DefaultValue extends null | undefined> implements OnDestroy, PipeTransform { | ||
export declare abstract class BaseExtendedAsyncPipe<DefaultValue extends null | undefined> implements OnDestroy, PipeTransform { | ||
private readonly changeDetectorRef; | ||
@@ -80,14 +77,25 @@ protected abstract readonly defaultValue: DefaultValue; | ||
private disposeSubscription; | ||
static ɵfac: i0.ɵɵFactoryDeclaration<ExtendedAsyncPipe<any>, never>; | ||
static ɵpipe: i0.ɵɵPipeDeclaration<ExtendedAsyncPipe<any>, "async">; | ||
static ɵfac: i0.ɵɵFactoryDeclaration<BaseExtendedAsyncPipe<any>, never>; | ||
static ɵpipe: i0.ɵɵPipeDeclaration<BaseExtendedAsyncPipe<any>, "async", false>; | ||
} | ||
export declare class ExtendedAsyncPipeWithNullAsDefault extends ExtendedAsyncPipe<null> implements PipeTransform { | ||
/** | ||
* A drop-in replacement for the `async` pipe from `@angular/common` with additional options. | ||
* | ||
* **If you also import the `CommonModule` from `@angular/common` make sure to place `ExtendedAsyncPipe` after it.** | ||
*/ | ||
export declare class ExtendedAsyncPipe extends BaseExtendedAsyncPipe<null> implements PipeTransform { | ||
protected readonly defaultValue: null; | ||
static ɵfac: i0.ɵɵFactoryDeclaration<ExtendedAsyncPipeWithNullAsDefault, never>; | ||
static ɵpipe: i0.ɵɵPipeDeclaration<ExtendedAsyncPipeWithNullAsDefault, "async">; | ||
static ɵfac: i0.ɵɵFactoryDeclaration<ExtendedAsyncPipe, never>; | ||
static ɵpipe: i0.ɵɵPipeDeclaration<ExtendedAsyncPipe, "async", true>; | ||
} | ||
export declare class ExtendedAsyncPipeWithUndefinedAsDefault extends ExtendedAsyncPipe<undefined> implements PipeTransform { | ||
/** | ||
* A drop-in replacement for the `async` pipe from `@angular/common` with additional options. Uses `undefined` rather than `null` as default | ||
* value. | ||
* | ||
* **If you also import the `CommonModule` from `@angular/common` make sure to place `ExtendedAsyncPipeWithUndefinedAsDefault` after it.** | ||
*/ | ||
export declare class ExtendedAsyncPipeWithUndefinedAsDefault extends BaseExtendedAsyncPipe<undefined> implements PipeTransform { | ||
protected readonly defaultValue: undefined; | ||
static ɵfac: i0.ɵɵFactoryDeclaration<ExtendedAsyncPipeWithUndefinedAsDefault, never>; | ||
static ɵpipe: i0.ɵɵPipeDeclaration<ExtendedAsyncPipeWithUndefinedAsDefault, "async">; | ||
static ɵpipe: i0.ɵɵPipeDeclaration<ExtendedAsyncPipeWithUndefinedAsDefault, "async", true>; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138518
990
203