tentjs-rails 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +46 -0
- data/vendor/assets/javascripts/tent.view.js +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -15,3 +15,49 @@ And then execute:
|
|
15
15
|
Or install it yourself as:
|
16
16
|
|
17
17
|
$ gem install tentjs-rails
|
18
|
+
|
19
|
+
## Using Tent
|
20
|
+
|
21
|
+
Rather than extending Backbone prototypes directly, Tent builds on top of them. That way, you can still create vanilla Backbone View, Models, and Collections without the additions that Tent provides. So, creating a view that uses Tent's extensions looks like this:
|
22
|
+
|
23
|
+
```
|
24
|
+
view = new Tent.View();
|
25
|
+
```
|
26
|
+
|
27
|
+
## Tent.View
|
28
|
+
|
29
|
+
### Binding to an object
|
30
|
+
|
31
|
+
By binding to an object using the `view.bindTo()` function, one can ensure that the binding is released when the view is closed using Tent's `view.close()` function.
|
32
|
+
|
33
|
+
```
|
34
|
+
view.bindTo(view.model, 'change', view.doSomething);
|
35
|
+
```
|
36
|
+
|
37
|
+
`bindTo` limits you to using the calling object as the context, which makes unbinding easier. If you must use another object as the context for a binding callback, use Backbone's `on` function.
|
38
|
+
|
39
|
+
|
40
|
+
### Unbinding from an object
|
41
|
+
|
42
|
+
Unbinding from an object is done with `unbindFrom`:
|
43
|
+
|
44
|
+
```
|
45
|
+
view.unbindFrom(view.model);
|
46
|
+
```
|
47
|
+
|
48
|
+
### Releasing all bindings
|
49
|
+
|
50
|
+
When closing a view, Tent's `close` function takes care of releasing bindings made with `bindTo`, but the bindings can also all be released with `unbindAll`.
|
51
|
+
|
52
|
+
```
|
53
|
+
view.unbindAll();
|
54
|
+
```
|
55
|
+
|
56
|
+
### Closing a view
|
57
|
+
|
58
|
+
Calling `view.close()` will do a fiew things:
|
59
|
+
|
60
|
+
1. Call `view.beforeClose()` if it's been defined.
|
61
|
+
2. Call `view.unbindAll()` to get rid of bindings.
|
62
|
+
3. Call `view.off()` to get rid of DOM bindings.
|
63
|
+
4. Call `view.remove()` to remove the view DOM element itself.
|