noflo
Version:
Flow-Based Programming environment for JavaScript
46 lines (40 loc) • 1.21 kB
text/coffeescript
# NoFlo - Flow-Based Programming for JavaScript
# (c) 2016-2017 Flowhub UG
# NoFlo may be freely distributed under the MIT license
module.exports = class IP
# Valid IP types
: [
'data'
'openBracket'
'closeBracket'
]
# Detects if an arbitrary value is an IP
: (obj) ->
obj and typeof obj is 'object' and obj._isIP is true
# Creates as new IP object
# Valid types: 'data', 'openBracket', 'closeBracket'
constructor: ( = 'data', = null, options = {}) ->
= true
= null # sync scope id
= null # packet owner process
= false # cloning safety flag
= null # addressable port index
for key, val of options
this[key] = val
# Creates a new IP copying its contents by value not reference
clone: ->
ip = new IP
for key, val of @
continue if ['owner'].indexOf(key) isnt -1
continue if val is null
if typeof(val) is 'object'
ip[key] = JSON.parse JSON.stringify val
else
ip[key] = val
ip
# Moves an IP to a different owner
move: () ->
# no-op
# Frees IP contents
drop: ->
delete this[key] for key, val of @