moonriver
Version:
Synchronous and asynchronous streams
75 lines (60 loc) • 2.85 kB
text/coffeescript
'use strict'
############################################################################################################
GUY = require 'guy'
{ alert
debug
help
info
plain
praise
urge
warn
whisper } = GUY.trm.get_loggers 'MOONRIVER/TRANSFORMER'
{ rpr
inspect
echo
log } = GUY.trm
#...........................................................................................................
{ get_base_types } = require './types'
#===========================================================================================================
class Transformer
#---------------------------------------------------------------------------------------------------------
: ( cfg ) ->
R = new ( require './main' ).Pipeline cfg; R.push new @(); return R
#---------------------------------------------------------------------------------------------------------
constructor: ->
GUY.props.hide @, '_types', get_base_types()
GUY.props.hide @, '_transforms', []
GUY.props.def @, 'length',
get: -> .length
set: ( n ) -> .length = n
return undefined
#---------------------------------------------------------------------------------------------------------
[Symbol.iterator]: -> yield from
#---------------------------------------------------------------------------------------------------------
_build: ->
chain = ( GUY.props.get_prototype_chain @ ).reverse()
for object in chain
for key from GUY.props.walk_keys object, { hidden: true, builtins: false, depth: 0, }
continue if key is 'constructor'
continue if key is 'length'
continue if key.startsWith '_'
.push d for d from object[ key ]
return null
#---------------------------------------------------------------------------------------------------------
_walk_values: ( value ) ->
return yield new value() if .isa.class value
#.......................................................................................................
if .isa.function value
return yield value unless ( value.name.startsWith '$' ) or ( value.name.startsWith 'bound $' )
return yield value.call @
#.......................................................................................................
if .isa.list value
for e in value
yield d for d from e
return null
#.......................................................................................................
return yield value
#===========================================================================================================
module.exports = { Transformer, }