Permalink
Browse files

delay children scope until tag has a parent

  • Loading branch information...
1 parent 9cecfe1 commit b0cc0f7ca1cf3025cee53fe23ea677414f51fb7b @dodo committed Nov 9, 2013
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/xml.coffee
View
@@ -77,6 +77,7 @@ add_tag = (newtag, callback) ->
@emit 'new', tag
@isempty = no
tag.emit? 'close', tag if tag.closed
+ tag.emit? 'added', this
callback?.call(this, tag)
newtag.parent = this
@@ -153,7 +154,10 @@ class Tag extends EventEmitter
children: (children) =>
return this unless children?
- if typeof children is 'function'
+ unless @parent
+ @once 'added', ->
+ @children children
+ else if typeof children is 'function'
children.call this
else
@text children

0 comments on commit b0cc0f7

Please sign in to comment.