Interfaces & Types

CONNECTIVE comes with a host of interfaces and types to allow strong type annotation in Typescript codes which use it. The most common ones are listed here.

Shared Types

These types are re-used across CONNECTIVE and shared between pins and agents.

Clearable

A Clearable is an object that bears the .clear() method, which can be called when the object is to be disposed. The core functionality of a Clearable should be assumed unusable after invokation of the .clear() method. All agents and pins are Clearable.
import { Clearable, isClearable } from '@connectv/core';

isClearable(obj); //--> returns true if the object is `Clearable`, useful for type inference.


Bindable

A Bindable object can be bound via its .bind() method. sink()s, state()s and Compositions are examples of Bindable.
import { Bindable, isBindable } from '@connectv/core';

if (isBindable(obj))
  obj.bind();        //--> because of type inference, this will compile without errors.


Error callback

ErrorCallback denotes callbacks responsible for error handling in async functions:
/*!*/import { map, ResolveCallback, ErrorCallback } from '@connectv/core';

...

map((x: any, 
  done: ResolveCallback, 
/*!*/  err: ErrorCallback) => {
  ...
/*!*/  err('something went wrong ...');
// or ...
/*!*/  err(new Error('Bad Stuff'));
});


Resolve callback

ResolveCallback denotes callbacks used to return async results:
/*!*/import { filter, ResolveCallback } from '@connectv/core';

...

filter((x: value, 
/*!*/  done: ResolveCallback) => {
  ...
/*!*/  done(typeof x === 'something');
});


Notify callback

NotifyCallback denotes callbacks responding to a notification, for example when a source() has completed.
import { source, ResolveCallback, ErrorCallback, 
/*!*/          NotifyCallback } from '@connectv/core';

let a = source();
a.to(...)
.to(...)
.to(...)
.subscribe({
  <ResolveCallback>(v => { ... }), //--> the default callback,
  <ErrorCallback>(err => { ... }), //--> the error callback,
/*!*/  <NotifyCallback>(() => { ... })  //--> the complete callback
});


Pins

These are types and interfaces related to pins:

Pin-like

The PinLike interface denotes any object that can act like a Pin. It is the recommended type annotation for any function parameter, return type, and class property that is to denote a pin without requiring to be more strict.
/*!*/import { PinLike, isPinLike } from '@connectv/core';

...

/*!*/if (isPinLike(p))
  p.to(...).subscribe(...);


Agents

These are types and interfaces related to agents:

Agent-like

The AgentLike interface denotes any object that acts like an agent. It is the recommended type annotation for any function parameter, return type, and class property that is to denote an agent without requiring to be more strict.
/*!*/import { AgentLike, isAgentLike } from '@connectv/core';

...

/*!*/isAgentLike(obj);


Node-like

NodeLike denotes agents that behave like nodes. Though from a strict typing perspective this just means that they have a .control property (which is a control()), it is highly recommended that any class implementing this interface also abides by the following rules:
/*!*/import { NodeLike, isNodeLike } from '@connectv/core';

...

/*!*/isNodeLike(obj);


Node function parameters

Functions that are used to build a node() are provided with parameters with following types:
/*!*/import { node, NodeInputs, NodeOutput } from '@connectv/core';

node({
  inputs: ['a', 'b'],
  outputs: ['c']
}, 
/*!*/(inputs: NodeInputs, output: NodeOutput) => {
/*!*/  output('c', inputs.a + inputs.b);
});


Signature

A Signature denotes the signature of an agent.
/*!*/import { Signature, isSignature } from '@connectv/core';

...

/*!*/isSignature(obj);


Further reading

In addition to types and interfaces outlined here, CONNECTIVE offers a lot of other type aliases and classes designed to allow for strict typing. For example, each pin() is an instance of Pin, each expr() is an instance of Expr, etc.

Additionally, there are type aliases for the type of function you should provide to a filter() (which is a FilterFunc), etc. You can find comprehensive lists of exported types, interfaces and classes in the following files:




Copied to Clipboard!