switch
| child is undefined => @_String '', done
| typeof! child is \String => @_String child, done
| typeof! child is \Array => @_Array child, done
| child.then? => @_Promise child, done
| child._promise? => @_ResourcePromise child, done
| child.Then? => @_ResourceInst child, done
| child._type is \Node => @_Node child, done
| child.Render? => @_View child, done
| typeof! child is \Function => @_Function child, done
| _ => @_String '' + child, done
_String: (text, done) -> done null new Node \text text
_Node: (node, done) -> done null node
_Array: (array, done) -> async.mapSeries array, @~_ResolveType, done
_Function: (f, done) ->
done null new WatchableNode f, @
_View: (view, done) ->
view.Render (err, res) ~>
return done err if err?
@_ResolveType res, done
_Promise: (promise, done) ->
promise
.then -> done null, it
.catch -> done it
_ResourceInst: (resourceInst, done) ->
throw "No Render() on #{resourceInst._type}. Attach view first" if not resourceInst.Render?
resourceInst.Render done
_ResourcePromise: (resourcePromise, done) ->
resourcePromise
.Then ~>
@_ResolveType it, done
.Catch -> done it
class WatchableNode extends Node
(@func, @parent) ->
@name = \func
@attrs = anchor: Node.anchorNb++
@children = []
first = true
N.Watch ~>