8000 Convert to ES Modules by bergie · Pull Request #354 · noflo/noflo-core · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 35 additions & 42 deletions components/Callback.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
const noflo = require('noflo');

exports.getComponent = () => {
const c = new noflo.Component();
c.description = `This component calls a given callback function for each
import noflo from "noflo";
export default function getComponent() {
const c = new noflo.Component();
c.description = `This component calls a given callback function for each
IP it receives. The Callback component is typically used to connect
NoFlo with external Node.js code.`;
c.icon = 'sign-out';

c.inPorts.add('in', {
description: 'Object passed as argument of the callback',
datatype: 'all',
});
c.inPorts.add('callback', {
description: 'Callback to invoke',
datatype: 'function',
control: true,
required: true,
});
c.outPorts.add(
'error',
{ datatype: 'object' },
);

return c.process((input, output) => {
if (!input.hasData('callback', 'in')) {
return;
}
const [callback, data] = input.getData('callback', 'in');
if (typeof callback !== 'function') {
output.done(new Error('The provided callback must be a function'));
return;
}

// Call the callback when receiving data
try {
callback(data);
} catch (e) {
output.done(e);
return;
}
output.done();
});
};
c.icon = "sign-out";
c.inPorts.add("in", {
description: "Object passed as argument of the callback",
datatype: "all",
});
c.inPorts.add("callback", {
description: "Callback to invoke",
datatype: "function",
control: true,
required: true,
});
c.outPorts.add("error", { datatype: "object" });
return c.process((input, output) => {
if (!input.hasData("callback", "in")) {
return;
}
const [callback, data] = input.getData("callback", "in");
if (typeof callback !== "function") {
output.done(new Error("The provided callback must be a function"));
return;
}
// Call the callback when receiving data
try {
callback(data);
} catch (e) {
output.done(e);
return;
}
output.done();
});
}
50 changes: 23 additions & 27 deletions components/Copy.js
8000
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
const noflo = require('noflo');
const owl = require('owl-deepcopy');

exports.getComponent = () => {
const c = new noflo.Component();
c.description = 'deep (i.e. recursively) copy an object';
c.icon = 'copy';

c.inPorts.add('in', {
datatype: 'all',
description: 'Packet to be copied',
});
c.outPorts.add('out', {
datatype: 'all',
description: 'Copy of the original packet',
});

return c.process((input, output) => {
if (!input.hasData('in')) {
return;
}
const data = input.getData('in');

const copy = owl.deepCopy(data);
output.sendDone({ out: copy });
});
};
import noflo from "noflo";
import * as owl from "owl-deepcopy";
export default function getComponent() {
const c = new noflo.Component();
c.description = "deep (i.e. recursively) copy an object";
c.icon = "copy";
c.inPorts.add("in", {
datatype: "all",
description: "Packet to be copied",
});
c.outPorts.add("out", {
datatype: "all",
description: "Copy of the original packet",
});
return c.process((input, output) => {
if (!input.hasData("in")) {
return;
}
const data = input.getData("in");
const copy = owl.deepCopy(data);
output.sendDone({ out: copy });
});
}
105 changes: 51 additions & 54 deletions components/DisconnectAfterPacket.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,51 @@
cons 8000 t noflo = require('noflo');

exports.getComponent = () => {
const c = new noflo.Component();
c.description = 'Makes each data packet a stream of its own';
c.icon = 'pause';
c.forwardBrackets = {};
c.autoOrdering = false;

c.inPorts.add('in', {
datatype: 'all',
description: 'Packet to be forward with disconnection',
});
c.outPorts.add('out', {
datatype: 'all',
});

let brackets = {};
c.tearDown = (callback) => {
brackets = {};
callback();
};
return c.process((input, output) => {
// Force auto-ordering to be off for this one
c.autoOrdering = false;

const data = input.get('in');
if (!brackets[input.scope]) { brackets[input.scope] = []; }
if (data.type === 'openBracket') {
brackets[input.scope].push(data.data);
output.done();
return;
}
if (data.type === 'closeBracket') {
brackets[input.scope].pop();
output.done();
return;
}

if (data.type !== 'data') { return; }

brackets[input.scope].forEach((bracket) => {
output.sendIP('out', new noflo.IP('openBracket', bracket));
});
output.sendIP('out', data);
const closes = brackets[input.scope].slice(0);
closes.reverse();
brackets[input.scope].forEach((bracket) => {
output.sendIP('out', new noflo.IP('closeBracket', bracket));
});

output.done();
});
};
import noflo from "noflo";
export default function getComponent() {
const c = new noflo.Component();
c.description = "Makes each data packet a stream of its own";
c.icon = "pause";
c.forwardBrackets = {};
c.autoOrdering = false;
c.inPorts.add("in", {
datatype: "all",
description: "Packet to be forward with disconnection",
});
c.outPorts.add("out", {
datatype: "all",
});
let brackets = {};
c.tearDown = (callback) => {
brackets = {};
callback();
};
return c.process((input, output) => {
// Force auto-ordering to be off for this one
c.autoOrdering = false;
const data = input.get("in");
if (!brackets[input.scope]) {
brackets[input.scope] = [];
}
if (data.type === "openBracket") {
brackets[input.scope].push(data.data);
output.done();
return;
}
if (data.type === "closeBracket") {
brackets[input.scope].pop();
output.done();
return;
}
if (data.type !== "data") {
return;
}
brackets[input.scope].forEach((bracket) => {
output.sendIP("out", new noflo.IP("openBracket", bracket));
});
output.sendIP("out", data);
const closes = brackets[input.scope].slice(0);
closes.reverse();
brackets[input.scope].forEach((bracket) => {
output.sendIP("out", new noflo.IP("closeBracket", bracket));
});
output.done();
});
}
34 changes: 16 additions & 18 deletions components/Drop.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
const noflo = require('noflo');

exports.getComponent = () => {
const c = new noflo.Component();
c.description = 'This component drops every packet it receives with no action';
c.icon = 'trash-o';

c.inPorts.add('in', {
datatypes: 'all',
description: 'Packet to be dropped',
});

return c.process((input, output) => {
const data = input.get('in');
data.drop();
output.done();
});
};
import noflo from "noflo";
export default function getComponent() {
const c = new noflo.Component();
c.description =
"This component drops every packet it receives with no action";
c.icon = "trash-o";
c.inPorts.add("in", {
datatypes: "all",
description: "Packet to be dropped",
});
return c.process((input, output) => {
const data = input.get("in");
data.drop();
output.done();
});
}
61 changes: 31 additions & 30 deletions components/Kick.js
D031
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
const noflo = require('noflo');

exports.getComponent = () => {
const c = new noflo.Component();
c.description = `This component generates a single packet and sends it to
import noflo from "noflo";
export default function getComponent() {
const c = new noflo.Component();
c.description = `This component generates a single packet and sends it to
the output port. Mostly usable for debugging, but can also be useful
for starting up networks.`;
c.icon = 'share';

c.inPorts.add('in', {
datatype: 'bang',
description: 'Signal to send the data packet',
});
c.inPorts.add('data', {
datatype: 'all',
description: 'Packet to be sent',
control: true,
default: null,
});
c.outPorts.add('out', {
datatype: 'all',
});

return c.process((input, output) => {
if (!input.hasStream('in')) { return; }
if (input.attached('data').length && !input.hasData('data')) { return; }
input.getData('in');
const data = input.getData('data');
output.send({ out: data });
output.done();
});
};
c.icon = "share";
c.inPorts.add("in", {
datatype: "bang",
description: "Signal to send the data packet",
});
c.inPorts.add("data", {
datatype: "all",
description: "Packet to be sent",
control: true,
default: null,
});
c.outPorts.add("out", {
datatype: "all",
});
return c.process((input, output) => {
if (!input.hasStream("in")) {
return;
}
if (input.attached("data").length && !input.hasData("data")) {
return;
}
input.getData("in");
const data = input.getData("data");
output.send({ out: data });
output.done();
});
}
Loading
Loading
0