tbranyen/backbone.layoutmanager — pull request #379 by ssafejava (2013-09-05 03:37:39+00:00)
Title: Added insertView `insertAt` option for inserting a view at a given index.

(Moved from #348, #350)

It is often useful to update a collection of views in place without rerendering the bunch.

A simple way of doing that is the following code:

```javascript
parentView.insertView('.container', new ChildView()).render() // renders child at bottom
```

The above code will not rerender the entire parent view, but successfully inserts a new view and appends it to the bottom of `.container`.

This patch adds an optional `insertAt` parameter as an options key (for readability, I dislike magic-looking numbers) that indicates where the inserted view should be placed. If 0, it is at the beginning of the list; if > list.length, it is at the end; if negative, it is counted backwards from the end of the list. Behavior mirrors Array#splice.

```javascript
parentView.insertView('.container', new ChildView(), {insertAt: 1}).render(); // renders after first item
```

Tests are included.