         url: ->
             if @isNew() then super else @get 'url'
 
-        parse: (response) =>
-            if response
-                @nodes = {}
-                @node = DataContextNode.parseAttrs response.json, null, @cacheNode
-
-            return response
+        parse: (resp) =>
+            if resp
+                if not @node
+                    @nodes = {}
+                    @node = DataContextNode.parseAttrs resp.json, null, @_cacheNode
+                else
+                    DataContextNode.updateAttrs @node, resp.json
+            return resp
 
         toJSON: ->
             attrs = super
-            if @node
-                attrs.json = @node.toJSON()
+            if @node then attrs.json = @node.toJSON()
             return attrs
 
-        # Proxy methods
+        isRoot: ->
+            @node.isRoot()
+
         isEmpty: ->
             @node.isEmpty()
 

                if cache.indexOf(node) is -1
                    cache.push node

        promote: (node, nodes...) ->
            if node is null
                @node.promote nodes...
            else
                node.promote nodes...
            @set 'json', @node.toJSON()

        demote: (node) ->
            node.demote()
            @set 'json', @node.toJSON()

        add: (node, nodes...) ->
            if node is null
                node = @node

            if node.isEmpty()
                node.set nodes[0].attributes or nodes[0]
            else
                node.add(nodes...)
                @cacheNode node for node in node.get 'children'
            @set 'json', @node.toJSON()

        remove: (node) ->
            node.remove()
            # Dereference it
            if (cache = @nodes[node.id]) and (idx = cache.indexOf(node)) >= 0
                cache.splice(idx, 1)
            @set 'json', @node.toJSON()


    class DataContexts extends Backbone.Collection

                return false

            # Check the state of the siblings. If only one sibling is left,
            # demote the parent instead
            @parent.parent.get('children').push @remove()
            return @

        # 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'
            (children = @get('children')).push.apply children, _.map nodes, (attrs) =>
                DataContextNode.parseAttrs attrs, @
            return @

        # Removes itself from it's parent. When only one sibling remains in the
        # respective branch, the sibling gets demoted.
        remove: ->
            # If this is the root, simply clear the attributes
            if @isRoot()
                @clear()
            else
                children = @parent.get 'children'
                # Ensure the node exists, then splice it directly out of
                # the attributes. This bypasses validation since this operation
                # is recursive.
                if (idx = children.indexOf @) >= 0
                    children.splice(idx, 1)[0]
                    if children.length is 1
                        children[0].demote()
            return @


