# callable-class

> An extendable callable class

Latest version **2.0.1** (published 2017-12-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install callable-class
pnpm add callable-class
yarn add callable-class
bun add callable-class
```

## 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 | 2.0.1 |
| Published | 2017-12-01 |
| First published | 2017-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | sleexyz |
| Maintainers | sleexyz |

## Links

- npm: https://www.npmjs.com/package/callable-class
- Repository: https://github.com/sleexyz/callable
- Homepage: https://github.com/sleexyz/callable#readme
- Issues: https://github.com/sleexyz/callable/issues
- npm.io page: https://npm.io/package/callable-class

## Recent versions

- 2.0.1 (latest) — 2017-12-01
- 2.0.0 — 2017-07-10
- 1.0.0 — 2017-07-09

## README

# Callable

[![NPM](https://nodei.co/npm/callable-class.png)](https://npmjs.org/package/callable-class)

[![CircleCI](https://circleci.com/gh/sleexyz/callable.svg?style=svg)](https://circleci.com/gh/sleexyz/callable)


An extendable base class for callable classes, designed to work nicely with Flow.

## Type definition:

```js
// @flow
declare class Callable<A, B> extends Function {
  // See https://github.com/facebook/flow/issues/3084
  // (A): B
  $call: A => B;
  constructor(A => B): this;
}
```

## Examples:

#### Extend `Callable` with custom methods
```js
// @flow
import Callable from "callable-class";

class Composable<A, B> extends Callable<A, B> {
  andThen(next: B => C): Composable<A, B> {
    return new Composable(x => next(this(x)));
  }
}

const foo = new Composable(x => [...x, 1])
  .andThen(x => [...x, 2])
  .andThen(x => [...x, 3]);

console.log(foo([])); // [1, 2, 3]
```

#### Extend `Callable` with custom fields and constructor
```js
// @flow
import Callable from "callable-class";

class ActionCreator<Type, A, B> extends Callable<A, B> {
  type: string;
  constructor(type: Type, fn: A => B) {
    super(fn);
    this.type = type;
  }
}

const foo = new ActionCreator("foo", x => x + 1);

console.log(foo.type); // "foo"
console.log(foo(0)); // 1
```

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