1.0.1 • Published 2 years ago

@novyk/ing v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

npm version

🦥 Ing

Simple async state container for RxJS and Angular.

Features

  • Stores multiple async operation states: New, Ongoing, Succeed, Failed.
  • Gives Observables with the state.
  • Has a helper operator for RxJS integration.
  • Adapted for using in Angular templates.
  • Easily integrates with your custom services and components.
  • Has no additional dependencies and complex abstractions.

Installation

$ npm i @novyk/ing

Usage

Create instance of container

import { ing, Ing } from '@novyk/ing';
...

component MyCompontent {
  loading = new Ing();
  ...
}

Handle state when making requests

import { ing, Ing } from '@novyk/ing';
...

component MyCompontent {
  ...
  loadData() {
    this.loading.start();
    this.dataService
      .load()
      .pipe(
        ing(this.loading),
      )
      ...
  }
}

Use container in templates

<div *ngIf="loading.ongoing">
  Data is loading...
</div>
<div *ngIf="loading.succeed">
  ...
</div>

Or subscribe to streams to improve performance:

<div *ngIf="loading.ongoing$ | async">
  Data is loading...
</div>
<div *ngIf="loading.succeed$ | async">
  ...
</div>

Using ngSwitch:

<div [ngSwitch]="loading.status$ | async">
  <ng-template ngSwitchCase="Ongoing">
    Data is loading...
  </ng-template>
  <ng-template ngSwitchCase="Succeed">
    ...
  </ng-template>
  <ng-template ngSwitchCase="Failed">
    Data loading failed!
  </ng-template>
</div>

TODO

  • tests
  • CI release
1.0.1

2 years ago

1.0.1-beta.1

2 years ago

1.0.0

2 years ago

1.0.0-beta.4

2 years ago

1.0.0-beta.3

2 years ago

1.0.0-beta.2

2 years ago

1.0.0-beta.1

2 years ago