maccman/spine — Issue #194: Stack usage documentation
Author: akheron
Created: 2012-02-02 11:57:34+00:00
State: open

Hi!

It took a while for me to figure out the "correct" usage pattern for stacks. In other parts of the docs, controllers are usually assigned a DOM element (wrapped in jQuery) like this:

```coffee
new Show(el: $('#target .show'))
```

When using stacks, there's no way to give controllers existing elements in the DOM. Instead, they should use the element automatically created by Spine, and these elements are then added to the stack's element one after another:

```coffee
class Show extends Spine.Controller
className: 'show'

construct: ->
@html(...)

class Edit extends Spine.Controller
className: 'edit'

construct: ->
@html(...)

class MyStack extends Spine.Stack
controllers:
show: Show
edit: Edit

default: 'show'

new MyStack(el: $('#target'))
```

In my opinion, this is a good approach, but it should be properly documented.