Module scope

Module scope 

Source
Expand description

Scopes: the shared-view visibility mechanism.

A scope is a path in a tree. Every rendered element occupies one; every connection observes a small set of them. Visibility is a single line:

a connection sees an element when one of its observed scopes is comparable to the element’s, meaning one is a prefix of the other.

Both directions count, and that is what makes the relation useful: a player at /g7/t2 sees its ancestors (/, /g7) and its descendants, while a spectator at /g7 sees every team without anything being added to the model. Moving up the tree is how you see more.

§The closure theorem

Imposing one rule on rendering - a child channel’s scope extends its parent’s, a user’s scope extends its channel’s - makes the property everything else depends on automatic: if I see an element, I see what it refers to.

With c the channel’s scope and u the user’s, c a prefix of u, an observer seeing the user through some scope s comparable to u:

  • s is a prefix of u: then c is also a prefix of u, so s and c are two prefixes of the same path, hence comparable;
  • u is a prefix of s: then c prefixes u prefixes s.

Either way the observer sees the channel. There is no runtime check to write and no failure mode to chase, provided the builder can only ever narrow - which is why Scope::child is the only way to make a new one.

REF: docs/design/guide-implementation.md 2

Structs§

Scope
A position in the visibility tree.
ScopeSet
What one connection observes of the shared view.
TooManyScopes
A connection dropped more observed scopes than MAX_OBSERVED allows.

Constants§

MAX_DEPTH
How deep a scope path may go.
MAX_OBSERVED
How many scopes one connection may observe at once.