Move flush to deps. Not the best place for it, but better than core.

This commit is contained in:
Nick Martin
2012-08-29 17:13:57 -07:00
parent 5b03c1f5fb
commit ee3bd696fe
3 changed files with 52 additions and 48 deletions

View File

@@ -28,36 +28,6 @@ put on the screen.
});
}
{{> api_box flush }}
Normally, when you make changes (like writing to the database),
their impact (like updating the DOM) is delayed until the system is
idle. This keeps things predictable — you can know that the DOM
won't go changing out from under your code as it runs. It's also one
of the things that makes Meteor fast.
`Meteor.flush` forces all of the pending reactive updates to complete
(for example, it ensures the DOM has been updated with your recent
database changes.) Call `flush` to apply those pending changes
immediately. The main use for this is to make sure the DOM has been
brought up to date with your latest changes, so you can manually
manipulate it with jQuery or the like.
When you call `flush`, any auto-updating DOM elements that are not on
the screen may be cleaned up (meaning that Meteor will stop tracking
and updating the elements, so that the browser's garbage collector can
delete them.) So, if you manually call `flush`, you need to make sure
that any auto-updating elements that you have created by calling
[`Meteor.ui.render`](#meteor_ui_render) have already been inserted in the main
DOM tree.
Technically speaking, `flush` calls the [invalidation
callbacks](#on_invalidate) on every [reactive context](#context) that
has been [invalidated](#invalidate), but hasn't yet has its callbacks
called. If the invalidation callbacks invalidate still more contexts,
flush keeps flushing until everything is totally settled. The DOM
elements are cleaned up because of logic in
[`Meteor.ui.render`](#meteor_ui_render) that works through invalidations.
<h2 id="publishandsubscribe"><span>Publish and subscribe</span></h2>
@@ -1683,6 +1653,40 @@ just means that [`run`](#run) sets it, runs some user-supplied code, and
then restores its previous value.)
{{> api_box flush }}
Normally, when you make changes (like writing to the database),
their impact (like updating the DOM) is delayed until the system is
idle. This keeps things predictable &mdash; you can know that the DOM
won't go changing out from under your code as it runs. It's also one
of the things that makes Meteor fast.
`Meteor.flush` forces all of the pending reactive updates to complete
(for example, it ensures the DOM has been updated with your recent
database changes.) Call `flush` to apply those pending changes
immediately. The main use for this is to make sure the DOM has been
brought up to date with your latest changes, so you can manually
manipulate it with jQuery or the like.
When you call `flush`, any auto-updating DOM elements that are not on
the screen may be cleaned up (meaning that Meteor will stop tracking
and updating the elements, so that the browser's garbage collector can
delete them.) So, if you manually call `flush`, you need to make sure
that any auto-updating elements that you have created by calling
[`Meteor.render`](#meteor_render) have already been inserted in the main
DOM tree.
Technically speaking, `flush` calls the [invalidation
callbacks](#on_invalidate) on every [reactive context](#context) that
has been [invalidated](#invalidate), but hasn't yet has its callbacks
called. If the invalidation callbacks invalidate still more contexts,
flush keeps flushing until everything is totally settled. The DOM
elements are cleaned up by logic that is triggered by context invalidations.
<h2 id="meteor_http"><span>Meteor.http</span></h2>
`Meteor.http` provides an HTTP API on the client and server. To use

View File

@@ -24,14 +24,6 @@ Template.api.startup = {
]
};
Template.api.flush = {
id: "meteor_flush",
name: "Meteor.flush()",
locus: "Client",
descr: ["Ensure that any reactive updates have finished. Allow auto-updating DOM element to be cleaned up if they are offscreen."]
};
Template.api.publish = {
id: "meteor_publish",
name: "Meteor.publish(name, func)",
@@ -483,13 +475,6 @@ Template.api.Context = {
descr: ["Create an invalidation context. Invalidation contexts are used to run a piece of code, and record its dependencies so it can be rerun later if one of its inputs changes.", "An invalidation context is basically just a list of callbacks for an event that can fire only once. The [`on_invalidate`](#on_invalidate) method adds a callback to the list, and the [`invalidate`](#invalidate) method fires the event."]
};
Template.api.current = {
id: "current",
name: "Meteor.deps.Context.current",
locus: "Client",
descr: ["The current [`invalidation context`](#context), or `null` if not being called from inside [`run`](#run)."]
};
Template.api.run = {
id: "run",
name: "<em>context</em>.run(func)",
@@ -521,6 +506,21 @@ Template.api.invalidate = {
descr: ["Add this context to the list of contexts that will have their `on_invalidate|on_invalidate` callbacks called by the next call to [`Meteor.flush`](#meteor_flush)."]
};
Template.api.current = {
id: "current",
name: "Meteor.deps.Context.current",
locus: "Client",
descr: ["The current [`invalidation context`](#context), or `null` if not being called from inside [`run`](#run)."]
};
Template.api.flush = {
id: "meteor_flush",
name: "Meteor.flush()",
locus: "Client",
descr: ["Ensure that any reactive updates have finished. Allow auto-updating DOM element to be cleaned up if they are offscreen."]
};
// writeFence
// invalidationCrossbar

View File

@@ -82,8 +82,7 @@ var toc = [
"Core", [
"Meteor.is_client",
"Meteor.is_server",
"Meteor.startup",
"Meteor.flush"
"Meteor.startup"
],
"Publish and subscribe", [
@@ -181,7 +180,8 @@ var toc = [
{instance: "context", name: "on_invalidate"},
{instance: "context", name: "invalidate"}
],
{name: "Meteor.deps.Context.current", id: "current"}
{name: "Meteor.deps.Context.current", id: "current"},
"Meteor.flush"
// ],
// "Environment Variables", [