Created
April 5, 2016 20:08
-
-
Save trustmaster/c7117776d2aab3a18fecffa7f44ae5ac to your computer and use it in GitHub Desktop.
Bracket forwarding the quick way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
noflo = require 'noflo' | |
parser = require 'js-yaml' | |
exports.getComponent = -> | |
c = new noflo.Component | |
c.description = 'Parse YAML to an object' | |
c.inPorts.add 'in', | |
datatype: 'string' | |
description: 'YAML source' | |
c.outPorts.add 'out', | |
datatype: 'object' | |
c.outPorts.add 'error', | |
datatype: 'object' | |
required: false | |
c.ordered = true # Maintain order | |
c.process (input, output) -> | |
data = input.get 'in' | |
unless data.type is 'data' | |
return output.sendDone out: data # Forward brackets | |
unless data.data | |
output.sendDone | |
out: {} | |
return | |
try | |
result = parser.load data.data | |
catch e | |
output.sendDone | |
error: e | |
return | |
result = {} if result is null | |
output.sendDone | |
out: result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment