     '../core'
 ], (c) ->
 
+    class ContextNodeError extends Error
 
     isBranch = (attrs) ->
         (attrs.type is 'and' or attrs.type is 'or') and attrs.children?.length >= 2

        # Add one or more nodes to this branch.
        add: (nodes...) ->
            if not @isBranch()
                throw new Error 'Node is not a branch. Use "promote" to convert it into one'
            @get('children').push nodes...
            return @


        initialize: ->
            super
            c.subscribe c.SESSION_OPENED, =>
                @fetch().done =>
                    @ensureSession()
                    @resolve()
            c.subscribe c.SESSION_CLOSED, => @reset()

        getSession: ->
            (@filter (model) -> model.get 'session')[0]
