You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -540,26 +540,26 @@ TurboBoost manages various forms of state to provide a terrific reactive user ex
540
540
541
541
Here’s a breakdown of each type:
542
542
543
-
### ServerState
543
+
### Server-State
544
544
545
-
Server state is the persistent state that the server used for the most recent render.
545
+
Server-State is the persistent state that the server used for the most recent render.
546
546
This state is signed, ensuring data integrity and security.
547
547
548
548
The client includes this signed state along with its own optimistic changes whenever a Command is invoked.
549
-
The server can then compute the difference between the client state and the server state,
549
+
The server can then compute the difference between the Client-State and the Server-State,
550
550
allowing you to accept or reject the client's optimistic changes.
551
551
552
552
This ensures the server remains the single source of truth.
553
553
554
-
Server state can be accessed within Commands like so.
554
+
Server-State can be accessed within Commands like so.
555
555
556
556
```ruby
557
557
state[:key] ="value"
558
558
state[:key]
559
559
#=> "value"
560
560
```
561
561
562
-
Server state is also accessible in controllers and views.
562
+
Server-State is also accessible in controllers and views.
563
563
564
564
```ruby
565
565
# controller
@@ -576,22 +576,22 @@ turbo_boost.state[:key]
576
576
%>
577
577
```
578
578
579
-
### NowState
579
+
### Now-State
580
580
581
-
Now state is ephemeral server-side state that only exists for the current render cycle.
581
+
Now-State is ephemeral serverside state that only exists for the current render cycle.
582
582
Similar to `flash.now` in Rails, this state is discarded after rendering.
583
583
584
584
It’s useful for managing temporary data that doesn’t need to persist beyond the current request.
585
585
586
-
Now state can be accessed within Commands like so.
586
+
Now-State can be accessed within Commands like so.
587
587
588
588
```ruby
589
589
state.now[:key] ="value"
590
590
state.now[:key]
591
591
#=> "value"
592
592
```
593
593
594
-
Server state is also accessible in controllers and views.
594
+
Now-State is also accessible in controllers and views.
595
595
596
596
```ruby
597
597
# controller
@@ -608,35 +608,62 @@ turbo_boost.state.now[:key]
608
608
%>
609
609
```
610
610
611
-
### ClientState
611
+
### Client-State
612
612
613
-
Client state is a mutable version of the signed server state, wrapped in an observable JavaScript proxy.
614
-
This allows for sophisticated techniques like data binding with custom JavaScript, Stimulus controllers, and web components.
613
+
Client-State is a mutable version of the signed Server-State, wrapped in an observable JavaScript proxy.
614
+
This allows for sophisticated techniques like data binding via custom JavaScript, Stimulus controllers, or web components.
615
615
616
-
Client-side state enables immediate UI updates, providing a fast and smooth user experience while the server resolves state differences whenever commands are invoked.
616
+
Client-side state enables immediate UI updates, providing a fast and smooth user experience while the server
617
+
[resolves state](#state-resolution) differences whenever Commands are invoked.
617
618
618
-
Client state can be accessed on the client like so.
619
+
Client-State can be accessed on the client like so.
619
620
620
621
```js
621
622
TurboBoost.State.current['key'] ='value'
622
623
TurboBoost.State.current['key']
623
624
//=> 'value'
624
625
```
625
626
627
+
### Page-State
628
+
629
+
Page-State is managed by the client and used to remember element attribute values between server renders.
630
+
It’s best for tracking transient user interactions, like which elements are visible, open/closed, their position, etc.
631
+
632
+
This enhances the user experience by maintaining the state of UI elements between renders.
633
+
When invoking commands, the client sends the Page-State to the server, allowing it to preserve element attributes when rendering.
634
+
_The client also checks and restores Page-State whenever the DOM changes if needed._
635
+
636
+
You can opt-in to remember Page-State with Rails tag helpers via the `turbo_boost[:remember]` option.
0 commit comments