1.1.0 • Published 7 months ago

rx-criteria v1.1.0

Weekly downloads
-
License
Apache License 2....
Repository
github
Last release
7 months ago

Rx Criteria

RxJs boolean conditions with ease.

npm i rx-criteria

The idea

When working with configurations, Observables composition can be messy.

This library aims to provide a simple and semantic interface to compose asynchronous boolean conditions using Observables.

The Criterion

A Criterion is the fundamental piece of this library, and it is a function with no arguments that returns a boolean, or a boolean Observable. Simple.

export type SyncCriterion = () => boolean
export type AsyncCriterion = () => Observable<boolean>
export type Criterion = AsyncCriterion | SyncCriterion

How to use it

You can find a complete example to build a Feature Flags system in the "examples" folder.

With this library we can compose functions with ease.

You can use the generic function combineCriteria to create a custom criteria combination, or use expressive functions like isEveryCriterionTrue.

const complexCriteria = isEveryCriterionTrue([
    isSomeCriterionTrue([
        () => of(false),
        () => false,
        () => of(true).pipe(delay(2000), startWith(false))
    ]),
    isEveryCriterionTrue([
        () => of(true),
        () => true,
        () => true
    ])
])

Peer Dependencies

  • RxJs 7

Author

Lean Vilas

Comments? Contact me on LinkedIn

Licence

Apache License 2.0

1.1.0

7 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago