# callbag-from-verbose

> A more verbose way to create callbags

Latest version **1.0.0** (published 2018-06-09) · Unlicense license · 0 weekly downloads

## Install

```sh
npm install callbag-from-verbose
pnpm add callbag-from-verbose
yarn add callbag-from-verbose
bun add callbag-from-verbose
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-06-09 |
| First published | 2018-06-09 |
| Weekly downloads | 0 |
| License | Unlicense |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | acailly |
| Maintainers | acailly |
| Keywords | callbag |

## Links

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

## Recent versions

- 1.0.0 (latest) — 2018-06-09

## README

# callbag-from-verbose

A more verbose way to create callbags

## Concepts

### 3 actions

|      ACTION        |          VERBOSE          |       CALLBAG       |  
| ------------------ | --------------------------| --------------------|
| Introduce A to B   |    introduceAtoB(A, B)    |    B(START, A)      |  
| Send B a message   |    send(B, message)       |    B(DATA, message) |  
| Stop B             |    stop(B)                |    B(STOP)          |  

### 3 events

|      ACTION          |          VERBOSE              |              CALLBAG             |  
| -------------------- | ----------------------------- | -------------------------------- |
| B meet A             | B = {meet: A => ...}          | B = (t, p) => {if(t === 0){...}} |  
| B receives a message | B = {receive: message => ...} | B = (t, p) => {if(t === 1){...}} |  
| B is asked to stop   | B = {stop: () => ...}         | B = (t, p) => {if(t === 2){...}} |  

## Simple example

### Orginal code

*Taken from the 'Callback Heaven' talk from Andre Staltz (video)[https://www.youtube.com/watch?v=HssczgaY9BM]*

```javascript
const producer = (type, payload) => {
  if (type === 0) {
    const other = payload
    let i = 0;
    const handle = setInterval(() => {
      other(1, i++);
    }, 1000);
    other(0, (t, p) => {
      if (t === 1) i = p
      if (t === 2) clearInterval(handle);
    })
  }
};


const consumer = (type, payload) => {
  if (type === 0) {
    const other = payload
    setTimeout(() => other(1, 17), 3500)
    setTimeout(() => other(2), 7500)
  }
  if (type === 1) {
    console.log(payload)
  }
}

producer(0, consumer)
```

### Verbose code

```javascript
const {
    introduceAtoB,
    send,
    stop,
    fromVerboseCallbag
} = require('callbag-from-verbose')

const verboseProducer = fromVerboseCallbag({
  meet: other => {
    let i = 0;
    const handle = setInterval(() => {
      send(other, i++)
    }, 1000);
    introduceAtoB(
      fromVerboseCallbag({
        receive: message => (i = message),
        stop: () => clearInterval(handle)
      }),
      other
    )
  }
})

const verboseConsumer = fromVerboseCallbag({
  meet: other => {
    setTimeout(() => send(other, 17), 3500)
    setTimeout(() => stop(other), 7500)
  },
  receive: message => console.log(message)
})

introduceAtoB(verboseConsumer, verboseProducer)
```

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