Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

callable-class

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

callable-class

An extendable callable class

latest
Source
npmnpm
Version
2.0.1
Version published
Weekly downloads
16
700%
Maintainers
1
Weekly downloads
 
Created
Source

Callable

NPM

CircleCI

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

Type definition:

// @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

// @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

// @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

FAQs

Package last updated on 01 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts