# obz

> simple and lightweight observer

Latest version **1.1.1** (published 2023-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install obz
pnpm add obz
yarn add obz
bun add obz
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2023-10-01 |
| First published | 2020-06-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | 'Dominic Tarr' |
| Maintainers | powersource, arj03, staltz, mixmix, cel, christianbundy |

## Links

- npm: https://www.npmjs.com/package/obz
- Repository: https://github.com/ssbc/obz
- Issues: https://github.com/ssbc/obz/issues
- npm.io page: https://npm.io/package/obz

## Recent versions

- 1.1.1 (latest) — 2023-10-01
- 1.1.0 — 2022-04-19
- 1.0.3 — 2021-01-14
- 1.0.2 — 2020-06-18
- 1.0.1 — 2020-06-18
- 1.0.0 — 2020-06-18

## README

# obz

A fork of https://github.com/dominictarr/obv

Represents a value changing in time.

Sometimes you have a sequence of values over time,
usually we use streams for this. However, in some cases,
the latest value, or the next value matters more
than the entire history of values.

For example, if you are drawing the mouse pointer,
you just need the current position, not the historical positions.

An observable is a simple way to represent these instantaniously changing values.

## Obv() => observable

returns an observable instance.

## observable(listener=function, immediate=boolean) => remove

register `listener` with the observable. `immediate` is true by default.
`listener` is called with the current value (if one has been set), set to false to disable.

A function `remove` is returned, calling this function deregisters the listener.

Another way of deregistering the listener is by returning `false` from inside the
listener function.

## observable.set(value=any)

set the current value of this observable. Any registered listeners will be called.

## observable.once(listener=function, immediate=boolean) => remove

Like the above call to `observable()` except the listener will only be triggered _once_.

This is useful for representing variables which must be set after an async operation
(say, initializing a database connection), but if the value is initalized
you can act on it immediately.

If you call `observable.once(listener, false)` that triggers at the _next_
time the value is set, which so far I have used to create live streams.

## observable.value

The current value of the observable is provided as a property.
I recommend not using null as a observable value in your program,
because it makes testing the current value awkward.

## License

MIT

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