Multicast delegate for TypeScript and JavaScript
JavaScript TypeScript
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples Remove references to GPL and update example with return values Jun 27, 2017
lib/node Daily Jul 17, 2017
src Daily Jul 17, 2017
test Add nyc to package dependencies Jul 22, 2017
.codeclimate.yml Update code climate config Jul 12, 2018
.gitignore
.travis.yml
LICENSE Add directory structure Jun 20, 2017
README.md Update README.md Jul 21, 2017
package-lock.json Commit npm lockfile Jul 25, 2017
package.json Commit npm lockfile Jul 25, 2017
tsconfig.json Add MulticastDelegate interface Jun 26, 2017

README.md

delegate

Multicast delegate for TypeScript and JavaScript.

NPM Version NPM Downloads Build Status Code Climate Issue Count Test Coverage

If you like delegate, please star it...

Install

npm i @steelbreeze/delegate

Usage

TypeScript

import { create as delegate } from "@steelbreeze/delegate";

const a = delegate(param => console.log(param + " Hello"), param => console.log(param + " World "));
const b = delegate(param => console.log(param + " Hello world"));

const c = delegate(a, b);

a("a")
b("b")
c("c");

JavaScript

var delegate = require("@steelbreeze/delegate");

var a = delegate.create(function (param) { console.log(param + " Hello"); }, function (param) { console.log(param + " World "); });
var b = delegate.create(function (param) { console.log(param + " Hello world"); });

var c = delegate.create(a, b);

a("a");
b("b");
c("c");

Output

The output of the above code will be:

a Hello
a World
b Hello world
c Hello
c World
c Hello world

API

Interfaces

Delegate

A prototype for a delegate function that is callable and may return a value.

interface Delegate<TReturn = any> {
	(...args: any[]): TReturn
}

MulticastDelegate

A prototype for a multicast delegate function that calls multiple delegates and returns all their return values as an array.

interface MulticastDelegate<TReturn = any> {
	(...args: any[]): TReturn[]
}

Functions

create

Creates a new delegate from one or more functions or delegates, the result of which is callable and when called returns an array of all the return values from those functions or delegates.

create<TReturn = any>(...delegates: Delegate<TReturn>[]): MulticastDelegate<TReturn>

License

MIT License

Copyright (c) 2017 David Mesquita-Morris