callbag-types
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "callbag-types", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Types for 👜 Callbags", | ||
@@ -5,0 +5,0 @@ "main": "README.js", |
@@ -1,6 +0,27 @@ | ||
// @flow | ||
/** | ||
* ***************************************************************** | ||
* ***************************************************************** | ||
* ⚠️ DO NOT USE! ⚠️ | ||
* From what I can tell, Flow does not allow enough fine control | ||
* over polymorphism to realistically tame the possible typings | ||
* of callbags. If someone can figure it out, PRs very, very welcome. | ||
* ***************************************************************** | ||
* ***************************************************************** | ||
* | ||
* This library provides types for 👜 Callbags according to the spec. | ||
* | ||
* Spec: https://github.com/callbag/callbag | ||
* Original Typing work: http://blog.krawaller.se/posts/explaining-callbags-via-typescript-definitions/ | ||
* | ||
* Installation | ||
* | ||
* npm install --save-dev callbag-types | ||
* | ||
* Usage | ||
* | ||
* import type { START, SourceInitiator } from 'callbag-types' | ||
* | ||
* @flow | ||
*/ | ||
// Plagiarized from http://blog.krawaller.se/posts/explaining-callbags-via-typescript-definitions/ | ||
// and added generics. | ||
export type START = 0 | ||
@@ -10,17 +31,31 @@ export type DATA = 1 | ||
export type SourceTalkback = ((request: DATA) => void) & | ||
((terminate: END) => void) | ||
/** | ||
* Quoth the spec: | ||
* | ||
* "A callbag is terminated when the first argument is 2 and the second | ||
* argument is either undefined (signalling termination due to success) | ||
* or any truthy value (signalling termination due to failure)." | ||
*/ | ||
export type SourceTalkback<T> = ((DATA, T) => void) & | ||
((END, error?: any) => void) | ||
export type SinkTalkback<T> = (( | ||
start: START, | ||
sourceTalkback: SourceTalkback | ||
START, | ||
SourceTalkback<T> | SourceInitiator<T> | ||
) => void) & | ||
((deliver: DATA, data: T) => void) & | ||
((terminate: END, error?: any) => void) | ||
SourceTalkback<T> | ||
export type SourceInitiator<T> = (type: START, payload: SinkTalkback<T>) => void | ||
/** | ||
* Quoth the spec: | ||
* | ||
* "When a source is greeted and given a sink as payload, the sink MUST | ||
* be greeted back with a callbag payload that is either the source | ||
* itself or another callbag (known as the 'talkback'). In other | ||
* words, greets are mutual. Reciprocal greeting is called a handshake." | ||
*/ | ||
export type SourceInitiator<T> = (START, SinkTalkback<T>) => void | ||
export type SinkConnector<T> = ( | ||
source: SourceInitiator<T> | ||
) => SourceInitiator<T> | void | ||
) => ?SourceInitiator<T> | ||
@@ -32,3 +67,3 @@ export type SourceFactory<T> = (...args: any[]) => SourceInitiator<T> | ||
export type Callbag = | ||
| SourceTalkback | ||
| SourceTalkback<*> | ||
| SinkTalkback<*> | ||
@@ -35,0 +70,0 @@ | SourceFactory<*> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3928
62
71