# callbag-create

> Creates a new Callbag given an optional producer

Latest version **2.1.3** (published 2022-06-21) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.3 |
| Published | 2022-06-21 |
| First published | 2018-03-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Francisco Tavares de Lima Neto |
| Maintainers | francisco.tln |
| Keywords | callbag |

## Links

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

## Dependencies (1)

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

## Recent versions

- 2.1.3 (latest) — 2022-06-21
- 2.1.2 — 2020-05-19
- 2.1.1 — 2020-05-18
- 2.1.0 — 2019-07-23
- 2.0.1 — 2019-02-27
- 2.0.0 — 2018-11-24
- 1.1.1 — 2018-04-18
- 1.1.0 — 2018-04-17
- 1.0.4 — 2018-03-27
- 1.0.3 — 2018-03-26
- 1.0.2 — 2018-03-25
- 1.0.1 — 2018-03-25
- 1.0.0 — 2018-03-25

## README

# callbag-create

Creates a new Callbag given an optional producer that dictates how to emit values and complete the Callbag.

`npm install callbag-create`

## Examples

### With a Producer

```js
const create = require('callbag-create');
const forEach = require('callbag-for-each');
const pipe = require('callbag-pipe');

pipe(
  create((next, error, done) => {
    next('a');
    next('b');
    done();
    next('c');
  }),
  forEach((v) => {
    console.log(v);
  })
);
// logs 'a', 'b', then completes.
// Calling next('c') does nothing since done() was called and terminated the callbag
```

### With a Producer returning a clean-up logic

```js
const create = require('callbag-create');
const forEach = require('callbag-for-each');
const pipe = require('callbag-pipe');

const unsubscribe = pipe(
  create((next, error, done) => {
    const id = setTimeout(() => {
      next('a');
      done();
    }, 1000);

    return () => {
      clearTimeout(id);
    };
  }),
  subscribe({
    next(v) {
      console.log(v);
    },
    complete() {
      console.log('Done()');
    }
  })
);

unsubscribe();
// logs nothing since it was unsubscribed before emitting and the timeout is cleared
```

### With a Noop Producer
Equivalent to xstream and RxJs never().
Never emits the completion message.

```js
const create = require('callbag-create');
const forEach = require('callbag-for-each');
const pipe = require('callbag-pipe');

pipe(
  create(() => {}),
  forEach((v) => {
    console.log(v); // void
  })
);
```

### Without a Producer
Equivalent to xstream and RxJs empty().
Emits no value and immediatelly emits the completion message.

```js
const create = require('callbag-create');
const subscribe = require('callbag-subscribe');
const pipe = require('callbag-pipe');

pipe(
  create(),
  subscribe({
    next(v) {
      console.log(v);
    },
    complete() {
      console.log('Done()');
    }
  }) // => Done()
);
```

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