# callbag-share

> Callbag operator that broadcasts a single source to multiple sinks

Latest version **1.3.0** (published 2021-01-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install callbag-share
pnpm add callbag-share
yarn add callbag-share
bun add callbag-share
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2021-01-26 |
| First published | 2018-01-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | staltz.com |
| Maintainers | staltz |
| Keywords | callbag |

## Links

- npm: https://www.npmjs.com/package/callbag-share
- Repository: https://github.com/staltz/callbag-share
- Homepage: https://github.com/staltz/callbag-share#readme
- Issues: https://github.com/staltz/callbag-share/issues
- npm.io page: https://npm.io/package/callbag-share

## Dependencies (1)

- [callbag](https://npm.io/package/callbag.md) ^1.1.0

## Recent versions

- 1.3.0 (latest) — 2021-01-26
- 1.2.0 — 2019-02-09
- 1.1.1 — 2018-07-28
- 1.1.0 — 2018-06-12
- 1.0.2 — 2018-06-02
- 1.0.1 — 2018-05-31
- 1.0.0 — 2018-01-30

## README

# callbag-share

Callbag operator that broadcasts a single source to multiple sinks. Does reference counting on sinks and starts the source when the first sink gets connected, similar to RxJS [`.share()`](https://www.learnrxjs.io/operators/multicasting/share.html). Works on either pullable or listenable sources.

`npm install callbag-share`

## example

Share a listenable source to two listeners:

```js
const interval = require('callbag-interval');
const observe = require('callbag-observe');
const share = require('callbag-share');

const source = share(interval(1000));

observe(x => console.log(x))(source); // 0
                                      // 1
                                      // 2
                                      // 3
                                      // ...

setTimeout(() => {
  observe(x => console.log(x))(source); // 3
                                        // 4
                                        // 5
                                        // ...
}, 3500);
```

Share a pullable source to two pullers:

```js
const fromIter = require('callbag-from-iter');
const share = require('callbag-share');

const source = share(fromIter([10,20,30,40,50]));

let talkback;
source(0, (type, data) => {
  if (type === 0) talkback = data;
  else console.log('a' + data);
});

source(0, (type, data) => {
  if (type === 1) console.log('b' + data);
});

talkback(1); // a10
             // b10
talkback(1); // a20
             // b20
```

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