Documentation / @zerotal/flow / index / session
Function: session()
Call Signature
session(
value,context):void
Defined in: flow/src/decorators.ts:964
Binds a field to the server-side session, so its value survives across page loads.
Parameters
value
unknown
context
ClassFieldDecoratorContext
Returns
void
When configured, a field decorator; when used bare, nothing (applied directly).
Remarks
Requires SessionMiddleware. The field reads and writes the session's own key of the same
name, so @session userId is the same userId a controller sees — pass { key } to read a
differently-named one, or { scoped: true } to namespace it to this component instead.
The value stays server-side: @session alone puts nothing in the snapshot, so the
browser never sees it and cannot write it. Add @locked for a value the client should read.
Applies to a field only.
Example
class Preferences extends Component {
@session userId = ""; // the session's `userId`
@session({ key: "s" }) whatever = 0; // the session's `s`
@session({ scoped: true }) draft = ""; // flow:Preferences:draft
@locked @session theme = "light"; // readable by the client, server-owned
}
Call Signature
session(
opts?):SessionDecorator
Defined in: flow/src/decorators.ts:965
Binds a field to the server-side session, so its value survives across page loads.
Parameters
opts?
Optional SessionOptions when called with parentheses.
Returns
SessionDecorator
When configured, a field decorator; when used bare, nothing (applied directly).
Remarks
Requires SessionMiddleware. The field reads and writes the session's own key of the same
name, so @session userId is the same userId a controller sees — pass { key } to read a
differently-named one, or { scoped: true } to namespace it to this component instead.
The value stays server-side: @session alone puts nothing in the snapshot, so the
browser never sees it and cannot write it. Add @locked for a value the client should read.
Applies to a field only.
Example
class Preferences extends Component {
@session userId = ""; // the session's `userId`
@session({ key: "s" }) whatever = 0; // the session's `s`
@session({ scoped: true }) draft = ""; // flow:Preferences:draft
@locked @session theme = "light"; // readable by the client, server-owned
}