Skip to content

Commit 1dbe352

Browse files
committed
Start commenting Blaze.View
1 parent 379dcab commit 1dbe352

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

packages/blaze/view.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,30 @@
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+
/// ...
228
Blaze.View = function (kind, render) {
329
if (! (this instanceof Blaze.View))
430
// called without `new`
@@ -49,6 +75,25 @@ Blaze.View.prototype.onDestroyed = function (cb) {
4975
this._callbacks.destroyed.push(cb);
5076
};
5177

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.
5297
Blaze.View.prototype.autorun = function (f, _inViewScope) {
5398
var self = this;
5499

0 commit comments

Comments
 (0)