markevans/onionjs — pull request #5 by pablobm (2013-06-03 15:02:49+00:00)
Title: Progressive views

Scenario: there's HTML already rendered on the page (as sent by the server). You want your JS to use this DOM without necessarily add any new elements to it:

```ERB

Press me

Nothing yet...

<%= onionjs_app('prog_app', {@serverData}, {anchor: true, base: 'body'}) %>
```

This will anchor the controller `prog_app/prog_app_controller.coffee` to the `

` element. This controller will probably have two children, "button" and "results", that will in turn be anchored to the appropriate [data-child] nodes.

### What does the helper print out?

```HTML

```

The difference from the normal approach is that, after being instantiated, it does `anchorAt` as opposed to `appendTo`.

### Inside the controller, how are grandchildren set?

If they are bog-standard, non-"progressive" (they have a template associated and generate new content), there's no change.

If they are "progressive" (they will just work with the existing content), add the option `anchor: true` to `setChild`.

Examples of each:

```CoffeeScript
@setChild 'button', ButtonController, {}, {anchor: true}
@setChild 'button', ResultController
```

And a lot more to comment, but better doing that in person than here...