|
1 |
| - |
| 1 | +/// [new] Blaze.View([kind], renderMethod) |
| 2 | +/// |
| 3 | +/// Blaze.View is the building block of reactive DOM. Views have |
| 4 | +/// the following features: |
| 5 | +/// |
| 6 | +/// * lifecycle callbacks - Views are created, rendered, and destroyed, |
| 7 | +/// and callbacks can be registered to fire when these things happen. |
| 8 | +/// |
| 9 | +/// * parent pointer - A View points to its parentView, which is the |
| 10 | +/// View that caused it to be rendered. These pointers form a |
| 11 | +/// hierarchy or tree of Views. |
| 12 | +/// |
| 13 | +/// * render() method - A View's render() method specifies the DOM |
| 14 | +/// (or HTML) content of the View. If the method establishes |
| 15 | +/// reactive dependencies, it may be re-run. |
| 16 | +/// |
| 17 | +/// * a DOMRange - If a View is rendered to DOM, its position and |
| 18 | +/// extent in the DOM are tracked using a DOMRange object. |
| 19 | +/// |
| 20 | +/// When a View is constructed by calling Blaze.View, the View is |
| 21 | +/// not yet considered "created." It doesn't have a parentView yet, |
| 22 | +/// and no logic has been run to initialize the View. All real |
| 23 | +/// work is deferred until at least creation time, when the onCreated |
| 24 | +/// callbacks are fired, which happens when the View is "used" in |
| 25 | +/// some way that requires it to be rendered. |
| 26 | +/// |
| 27 | +/// ... |
2 | 28 | Blaze.View = function (kind, render) {
|
3 | 29 | if (! (this instanceof Blaze.View))
|
4 | 30 | // called without `new`
|
@@ -49,6 +75,25 @@ Blaze.View.prototype.onDestroyed = function (cb) {
|
49 | 75 | this._callbacks.destroyed.push(cb);
|
50 | 76 | };
|
51 | 77 |
|
| 78 | +/// View#autorun(func) |
| 79 | +/// |
| 80 | +/// Sets up a Deps autorun that is "scoped" to this View in two |
| 81 | +/// important ways: 1) Blaze.currentView is automatically set |
| 82 | +/// on every re-run, and 2) the autorun is stopped when the |
| 83 | +/// View is destroyed. As with Deps.autorun, the first run of |
| 84 | +/// the function is immediate, and a Computation object that can |
| 85 | +/// be used to stop the autorun is returned. |
| 86 | +/// |
| 87 | +/// View#autorun is meant to be called from View callbacks like |
| 88 | +/// onCreated, or from outside the rendering process. It may not |
| 89 | +/// be called before the onCreated callbacks are fired (too early), |
| 90 | +/// or from a render() method (too confusing). |
| 91 | +/// |
| 92 | +/// Typically, autoruns that update the state |
| 93 | +/// of the View (as in Blaze.With) should be started from an onCreated |
| 94 | +/// callback. Autoruns that update the DOM should be started |
| 95 | +/// from either onCreated (guarded against the absence of |
| 96 | +/// view.domrange), onMaterialized, or onRendered. |
52 | 97 | Blaze.View.prototype.autorun = function (f, _inViewScope) {
|
53 | 98 | var self = this;
|
54 | 99 |
|
|
0 commit comments