# @ngspot/rxjs

> A library providing a few useful RxJS operators.

Latest version **1.0.3** (published 2024-05-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ngspot/rxjs
pnpm add @ngspot/rxjs
yarn add @ngspot/rxjs
bun add @ngspot/rxjs
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2024-05-03 |
| First published | 2020-01-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 44 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 32 |
| Author | Dmitry Efimenko |
| Maintainers | dmitryefimenko |
| Keywords | rxjs, reactive streams, utility |

## Links

- npm: https://www.npmjs.com/package/@ngspot/rxjs
- Repository: https://github.com/DmitryEfimenko/ngspot
- Homepage: https://github.com/DmitryEfimenko/ngspot/tree/main/packages/rxjs
- Issues: https://github.com/DmitryEfimenko/ngspot/issues
- npm.io page: https://npm.io/package/@ngspot/rxjs

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.0

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2024-05-03
- 1.0.2 — 2023-03-29
- 1.0.1 — 2023-03-26
- 1.0.0 — 2023-03-26
- 0.0.4 — 2020-12-21
- 0.0.3 — 2020-02-05
- 0.0.2 — 2020-01-30
- 0.0.1 — 2020-01-27

## README

# @ngspot/rxjs

A library providing a few useful RxJS operators.

## Installation

### NPM

```sh
npm install @ngspot/rxjs
```

### Yarn

```sh
yarn add @ngspot/rxjs
```

## Operators:

- `filterOutNullish` - type safe operator for filtering out nullish values
- `deferredStartWith` - the same as `startWith`, but takes the first value in a callback, which allows to evaluate it lazily
- `conditionalStartWith` - the same as `deferredStartWith`, but the first argument is a callback returning a boolean. If boolean is evaluated to true, `startWith` is applied with a result of a callback of the second argument
- `log$` - logs values passing through this operator
- `mutationObserver` - observable creator. Wraps native `MutationObserver`
- `resizeObserver` - observable creator. Wraps native `ResizeObserver`
- `zoneFull` - enters the stream into Angular Zone
- `zoneFree` - exits the stream from Angular Zone

### Usage

```ts
import { filterOutNullish } from '@ngspot/rxjs/operators';

myObservable$.pipe(filterOutNullish());
```

## Decorators


### @Share()

This decorator comes handy when you expect a function that returns a completable observable to share that observable for a unique set of parameters of the function.

In the example below only 2 http network requests will be made.

```ts
import { Share } from '@ngspot/rxjs/decorators';

class MyApi {
  constructor(private http: HttpClient) {}

  @Share()
  makeCall(param1: number, param2: number) {
    return this.http.get(`/api/${param1}/${param2}`);
  }
}

class BusinessLogic {
  constructor(private api: MyApi) {
    api.makeCall(1, 2).subscribe();
    api.makeCall(1, 2).subscribe();
    api.makeCall(1, 3).subscribe();
  }
}
```

There might be a use-case when you'd want to disable the functionality of `@Share` decorator based on the function arguments.
To achieve this you can provide the `when` option to specify the condition when the observable should be shared:

In the example below the observable will only be shared when the `param1` is not equal to `param2`.

```ts
@Share({ when: (param1, param2) => param1 !== param2 })
makeCall(param1: number, param2: number) {
  return this.http.get(`/api/${param1}/${param2}`);
}
```
The context of the `when` callback function is the context of the class instance. The signature of the of `when` callback has the same signature as the method that the decorator is applied to.

With the implementation above, two HTTP requests will be made in the example below:
```ts
class BusinessLogic {
  constructor(private api: MyApi) {
    api.makeCall(1, 1).subscribe();
    api.makeCall(1, 1).subscribe();
  }
}
```

## License

MIT © [Dmitry Efimenko](mailto:dmitrief@gmail.com)

---
_Source: https://npm.io/package/@ngspot/rxjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
