Skip to content

Commit

Permalink
refactor(rstream-graph): update types/generics
Browse files Browse the repository at this point in the history
- update types due to changes in rstream interfaces
  • Loading branch information
postspectacular committed Mar 12, 2021
1 parent c982288 commit 2597482
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
17 changes: 10 additions & 7 deletions packages/rstream-graph/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@ import type { Transducer } from "@thi.ng/transducers";
* {@link @thi.ng/rstream#ISubscribable} using given object of inputs
* and node ID. See `node()` and `node1()`.
*/
export type NodeFactory<T> = (src: NodeInputs, id: string) => ISubscription<T>;
export type NodeFactory<T> = (
src: NodeInputs,
id: string
) => ISubscription<T, any>;

export type NodeResolver = Fn<ResolveFn, Node>;
export type NodeInputs = IObjectOf<ISubscription>;
export type NodeOutputs = IObjectOf<ISubscription>;
export type NodeInputs = IObjectOf<ISubscription<any, any>>;
export type NodeOutputs = IObjectOf<ISubscription<any, any>>;
export type Graph = IObjectOf<Node>;

export interface Node {
ins: NodeInputs;
outs: NodeOutputs;
node: ISubscription;
node: ISubscription<any, any>;
}

/**
Expand Down Expand Up @@ -103,14 +106,14 @@ export interface NodeSpec {
export interface NodeInputSpec {
id?: string;
path?: Path;
stream?: string | Fn<ResolveFn, ISubscription>;
stream?: string | Fn<ResolveFn, ISubscription<any, any>>;
const?: any | Fn<ResolveFn, any>;
xform?: Transducer<any, any>;
}

export type NodeOutputSpec = Path | NodeOutputFn;

export type NodeOutputFn = (
node: ISubscription,
node: ISubscription<any, any>,
id: NumOrString
) => ISubscription;
) => ISubscription<any, any>;
16 changes: 8 additions & 8 deletions packages/rstream-graph/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const prepareNodeInputs = (
if (!ins) return res;
for (let id in ins) {
const i = ins[id];
const src: ISubscription = i.path
const src: ISubscription<any, any> = i.path
? fromViewUnsafe(state, { path: i.path })
: i.stream
? isString(i.stream)
Expand All @@ -134,7 +134,7 @@ const prepareNodeInputs = (

const prepareNodeOutputs = (
outs: IObjectOf<NodeOutputSpec> | undefined,
node: ISubscription,
node: ISubscription<any, any>,
state: IAtom<any>,
nodeID: string
) => {
Expand All @@ -152,7 +152,7 @@ const prepareNodeOutputs = (
};

const nodeOutAll = (
node: ISubscription,
node: ISubscription<any, any>,
state: IAtom<any>,
nodeID: string,
path: Path
Expand All @@ -165,7 +165,7 @@ const nodeOutAll = (
);

const nodeOutID = (
node: ISubscription,
node: ISubscription<any, any>,
state: IAtom<any>,
nodeID: string,
path: Path,
Expand Down Expand Up @@ -260,7 +260,7 @@ export const node = (
inputIDs?: string[],
reset = false
): NodeFactory<any> => (
src: IObjectOf<ISubscription>,
src: IObjectOf<ISubscription<any, any>>,
id: string
): StreamSync<any, any> => (
ensureInputs(src, inputIDs, id), sync({ src, xform, id, reset })
Expand All @@ -279,9 +279,9 @@ export const node1 = (
xform?: Transducer<any, any>,
inputID = "src"
): NodeFactory<any> => (
src: IObjectOf<ISubscription>,
src: IObjectOf<ISubscription<any, any>>,
id: string
): ISubscription => {
): ISubscription<any, any> => {
ensureInputs(src, [inputID], id);
return src[inputID].subscribe({}, { xform, id });
};
Expand Down Expand Up @@ -309,7 +309,7 @@ export const node2 = (
* @param nodeID -
*/
export const ensureInputs = (
src: IObjectOf<ISubscription>,
src: IObjectOf<ISubscription<any, any>>,
inputIDs: string[] | undefined,
nodeID: string
) => {
Expand Down

0 comments on commit 2597482

Please sign in to comment.