In: |
lib/Borges/Utilities/StateRegistry.rb
|
Parent: | Object |
The StateRegistry is used to track, save, and restore the states of objects registered into it.
Session uses this to restore registered objects to the state they were at when the user first viewed the page they are attached to.
For example, in Borges/Component/Counter.rb, the Counter object is registered with the session when it is initialized. Every time a new page is rendered, a snapshot of the Counter’s state is created, so that if the user goes back in their history, any requested actions on the Counter will operate with the Counter’s state from the first rendering of that page.
Here’s a timeline to help explain things better:
load /borges/counter
load /borges/counter/session/a
load /borges/counter/session/b
load /borges/counter/session/b
The snapshots allow an object’s state to be backtracked easily. The snapshots created by the registry will drop unreferenced objects when the Session drops an old page from its cache of recent pages.
If the Session’s history cache contains 10 pages, and the user performs five operations in the Counter, then moves on to another task and spends 10 operations there, the Counter will no longer be accessible in their Session history, and no longer restorable.