1 | noflo = require 'noflo'
|
2 |
|
3 | exports.getComponent = ->
|
4 | c = new noflo.Component
|
5 | c.description = 'Returns the value of a global variable.'
|
6 | c.icon = 'usd'
|
7 |
|
8 |
|
9 | c.inPorts.add 'name',
|
10 | description: 'The name of the global variable.'
|
11 |
|
12 |
|
13 | c.outPorts.add 'value',
|
14 | description: 'The value of the variable.'
|
15 |
|
16 | c.outPorts.add 'error',
|
17 | description: 'Any errors that occured reading the variables value.'
|
18 |
|
19 | c.forwardBrackets =
|
20 | name: ['value', 'error']
|
21 |
|
22 | c.process (input, output) ->
|
23 | return unless input.hasData 'name'
|
24 | data = input.getData 'name'
|
25 |
|
26 | value = unless noflo.isBrowser() then global[data] else window[data]
|
27 |
|
28 | if typeof value is 'undefined'
|
29 | err = new Error "\"#{data}\" is undefined on the global object."
|
30 | output.sendDone err
|
31 | return
|
32 | output.sendDone
|
33 | value: value
|