Skip to content

Commit

Permalink
v1.3.1-rc.1, rename interfaces and fix worker params
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni55aN committed May 16, 2019
1 parent 2fe75b9 commit da58089
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 269 deletions.
480 changes: 243 additions & 237 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rete",
"version": "1.3.0",
"version": "1.3.1-rc.1",
"description": "JavaScript framework",
"main": "build/rete.common.js",
"module": "build/rete.esm.js",
Expand Down
34 changes: 19 additions & 15 deletions src/core/data.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
export interface Connection {
export interface ConnectionData {
node: number;
data: any;
}

export type InputConnection = Connection & {
export type InputConnectionData = ConnectionData & {
output: string;
}
export type OutputConnection = Connection & {
export type OutputConnectionData = ConnectionData & {
input: string;
}

export interface Input {
connections: InputConnection[];
export interface InputData {
connections: InputConnectionData[];
}
export interface Output {
connections: OutputConnection[];
export interface OutputData {
connections: OutputConnectionData[];
}

export interface Inputs { [key: string]: Input }
export interface Outputs { [key: string]: Output }
export interface InputsData { [key: string]: InputData }
export interface OutputsData { [key: string]: OutputData }

export interface Node {
export interface NodeData {
id: number;
name: string;
inputs: Inputs;
outputs: Outputs;
inputs: InputsData;
outputs: OutputsData;
data: any;
position: [number, number];
}

export interface Nodes { [id: string]: Node }
export interface NodesData { [id: string]: NodeData }

export interface Data {
id: string;
nodes: Nodes;
}
nodes: NodesData;
}

export interface WorkerInputs { [key: string]: any[] }

export interface WorkerOutputs { [key: string]: any }
6 changes: 2 additions & 4 deletions src/engine/component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Engine } from './index';
import { Node } from '../core/data';

export interface IOs { [key: string]: any }
import { NodeData, WorkerInputs, WorkerOutputs } from '../core/data';

export abstract class Component {

Expand All @@ -13,5 +11,5 @@ export abstract class Component {
this.name = name;
}

abstract worker(node: Node, inputs: IOs, outputs: IOs, ...args: any): any;
abstract worker(node: NodeData, inputs: WorkerInputs, outputs: WorkerOutputs, ...args: any): any;
}
10 changes: 5 additions & 5 deletions src/engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { Context } from '../core/context';
import { Recursion } from './recursion';
import { State } from './state';
import { Validator } from '../core/validator';
import { Data, Node } from '../core/data';
import { Data, NodeData } from '../core/data';
import { EngineEvents, EventsTypes } from './events';

export { Component, Recursion };

interface EngineNode extends Node {
interface EngineNode extends NodeData {
busy: boolean;
unlockPool: any[];
outputData: any;
Expand Down Expand Up @@ -102,7 +102,7 @@ export class Engine extends Context<EventsTypes> {
node.busy = false;
}

private async extractInputData(node: Node) {
private async extractInputData(node: NodeData) {
const obj: {[id: string]: any} = {};

for (let key of Object.keys(node.inputs)) {
Expand All @@ -125,7 +125,7 @@ export class Engine extends Context<EventsTypes> {
return obj;
}

private async processWorker(node: Node) {
private async processWorker(node: NodeData) {
const inputData = await this.extractInputData(node);
const component = this.components.get(node.name) as Component;
const outputData = {};
Expand Down Expand Up @@ -154,7 +154,7 @@ export class Engine extends Context<EventsTypes> {
return node.outputData;
}

private async forwardProcess(node: Node) {
private async forwardProcess(node: NodeData) {
if (this.state === State.ABORT)
return null;

Expand Down
12 changes: 6 additions & 6 deletions src/engine/recursion.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Node, Nodes } from '../core/data';
import { NodeData, NodesData } from '../core/data';

function intersect(array1: any[], array2: any[]) {
return array1.filter(value => -1 !== array2.indexOf(value));
}

export class Recursion {

nodes: Nodes;
nodes: NodesData;

constructor(nodes: Nodes) {
constructor(nodes: NodesData) {
this.nodes = nodes;
}

extractInputNodes(node: Node): Node[] {
extractInputNodes(node: NodeData): NodeData[] {
return Object.keys(node.inputs).reduce((a: any[], key: string) => {
const { connections } = node.inputs[key];

return [...a, ...(connections || []).reduce((b: any[], c: any) => [...b, this.nodes[c.node]], [])]
}, []);
}

findSelf(list: any[], inputNodes: Node[]): Node | null {
findSelf(list: any[], inputNodes: NodeData[]): NodeData | null {
const inters = intersect(list, inputNodes);

if (inters.length)
Expand All @@ -37,7 +37,7 @@ export class Recursion {
return null;
}

detect(): Node | null {
detect(): NodeData | null {
const nodesArr = Object.keys(this.nodes).map(id => this.nodes[id]);

for (let node of nodesArr) {
Expand Down
2 changes: 1 addition & 1 deletion src/node.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Connection } from './connection';
import { Control } from './control';
import { Input } from './input';
import { Node as NodeData } from './core/data';
import { NodeData } from './core/data';
import { Output } from './output';

export class Node {
Expand Down

0 comments on commit da58089

Please sign in to comment.