 
   # When HTML is already present (rendered by server),
   # this is what gets called to bind to the element.
-  attach: (element) ->
+  attach: (element, parentView = null) ->
     $el = $(element)
     $el.data('view-attached', true)
-    # Save the instance on the DOM el so we can grab later
-    # TODO does this cause a memory leak?
-    $el.data('view-instance', @)
     @setElement($el)
+
+    # Store a reference to the parent view.
+    @parentView = parentView
 
     # Hydrate looks if there is a model or collection associated
     # with this view, and tries to load it from memory.

  # Call @getView()
  # Attach childView
  attachChildViews: ->
    BaseView.attach(@app, @$el)

  remove: ->
    # TODO is this necessary or does it happen automatically when
    # DOM el is removed?
    @$el.data('view-instance', null)
    super

  # Class methods

  @getView: (viewName) ->
    require(rendr.entryPath + "/views/#{viewName}")

  @attach: (app, parentView = null) ->
    scope = parentView?.$el
    views = $('[data-view]', scope).map (i, el) =>
      $el = $(el)
      if !$el.data('view-attached')
        viewName = $el.data('view')
