# rx-computed

> Computed observables (ala Knockout) for RxJS

Latest version **0.0.2-alpha.6** (published 2017-01-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install rx-computed
pnpm add rx-computed
yarn add rx-computed
bun add rx-computed
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2-alpha.6 |
| Published | 2017-01-11 |
| First published | 2016-12-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Adriano dos Santos Fernandes |
| Maintainers | asfernandes |
| Keywords | typescript, rxjs |

## Links

- npm: https://www.npmjs.com/package/rx-computed
- Repository: https://github.com/asfernandes/rx-computed
- Homepage: https://github.com/asfernandes/rx-computed#readme
- Issues: https://github.com/asfernandes/rx-computed/issues
- npm.io page: https://npm.io/package/rx-computed

## Dependencies (1)

- [rxjs](https://npm.io/package/rxjs.md) ^5.0.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.0.2-alpha.6 (latest) — 2017-01-11
- 0.0.2-alpha.5 — 2017-01-11
- 0.0.2-alpha.4 — 2016-12-23
- 0.0.2-alpha.3 — 2016-12-23
- 0.0.2-alpha.2 — 2016-12-22
- 0.0.2-alpha.1 — 2016-12-22

## README

# RxComputed

Make it possible to use RxJS in a manner similar to [Knockout computed observables](http://knockoutjs.com/documentation/computedObservables.html).

## Installation

`npm install --save rx-computed`

## Usage in TypeScript (sync)

```ts
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { RxComputed } from 'rx-computed';
import * as assert from "power-assert";

// debug how many times the computed function is called
let counter = 0;

// variables that our computed will depend on
let n1 = new BehaviorSubject(10);
let n2 = new BehaviorSubject(100);

let computed = RxComputed.sync<number>(context => {
	++counter;
	return context.get(n1) + context.get(n2);
});

// the computed function is called when creating the object
assert.equal(counter, 1);
assert.equal(computed.value, 110);

// changing n1 will re-evaluate the computed
n1.next(11);
assert.equal(counter, 2);
assert.equal(computed.value, 111);

// changing n2 will re-evaluate the computed
n2.next(200);
assert.equal(counter, 3);
assert.equal(computed.value, 211);

// dispose the computed
computed.dispose();

// changing n2 will not re-evaluate the disposed computed
n2.next(300);
assert.equal(counter, 3);
```

## Usage in TypeScript (async)

```ts
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { RxComputed }  from 'rx-computed';

// variable that our computed will depend on
let n1 = new BehaviorSubject(10);

let computed = RxComputed.async<number>(context => {
	let val1 = context.get(n1);

	return new Promise<number>(resolve => {
		setTimeout(() => {
			resolve(val1 + 1);
		}, 10);
	});
});

// ...

// dispose the computed
computed.dispose();
```

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