Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ngbites/reactive-enum

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ngbites/reactive-enum

A tool to automatically generate a typed reactive enum with Rx

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
91
increased by225%
Maintainers
1
Weekly downloads
 
Created
Source

Reactive Enum

A tool to automatically generate a typed reactive enum with Rx

Not yet production ready.

Install

npm i @ngbites/reactive-enum

Usage

This utility is particularly useful with framework such as Angular to automatically generate a set of reactive streams, so that you can use them in your template effortlessly.

This basically replaces using a BehaviorSubject property followed by auxiliary methods such as:

import { BehaviorSubject } from 'rxjs';

class MyComponent {
  private readonly status$ = new BehaviorSubject<Status>(Status.Initial);
  
  private readonly initial$ = this.status$.pipe(map(status => status === 
    Status.Initial));
  
  private readonly pending$ = this.status$.pipe(map(status => status ===
    Status.Pending));
}

Basic Usage

// declare an enum
enum Status {
  Initial,
  Pending,
  Success,
  Error
}

// pass your enum to "reactiveEnum"
const status = reactiveEnum(Status);

// "status" has now autmatically generated a method for each value of the enum
status.initial$.subscribe(); // false ... // true
status.pending$.subscribe(); // false
status.success$.subscribe(); // false
status.error$.subscribe(); // false

status.set(Status.Initial);

Passing an initial value

const status = reactiveEnum(Status, {
  initialValue: Status.Initial,
});

status.value$.subscribe(console.log); // Status.Initial

Updating the value

const status = reactiveEnum(Status);

status.value$.subscribe(console.log); // Status.Success

status.set(Status.Success);

Resetting to the original value

const status = reactiveEnum(Status, {
  initialValue: Status.Initial
});

status.value$.subscribe(console.log); 
// 1. Status.Initial
// 2. Status.Success
// 3. Status.Initial

status.set(Status.Success);
status.reset();

FAQs

Package last updated on 14 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc