Interface IPageState
- Namespace
- Htmx.Components.State
- Assembly
- Htmx.Components.dll
Provides a contract for managing page state with encrypted storage capabilities. The page state is organized into partitions and key-value pairs, allowing for structured data management.
public interface IPageState
- Extension Methods
Properties
Encrypted
Gets the current state as an encrypted string representation. This encrypted string can be stored and later loaded using the Load method.
string Encrypted { get; }
Property Value
IsDirty
Gets a value indicating whether the state has been modified since it was last loaded. This is determined by comparing the current version with the version when the state was loaded.
bool IsDirty { get; }
Property Value
Version
Gets the current version number of the page state. This version is incremented whenever the state is modified.
int Version { get; }
Property Value
Methods
ClearKey(string, string)
Removes a specific key from the specified partition. This operation marks the state as dirty and increments the version if the key existed.
void ClearKey(string partition, string key)
Parameters
partition
stringThe partition name to remove the key from.
key
stringThe key to remove from the partition.
ClearPartition(string)
Removes an entire partition and all its keys. This operation marks the state as dirty and increments the version if the partition existed.
void ClearPartition(string partition)
Parameters
partition
stringThe partition name to remove.
GetOrCreate<T>(string, string, Func<T>)
Retrieves a value from the specified partition and key, or creates it using the factory function if not found.
T GetOrCreate<T>(string partition, string key, Func<T> factory)
Parameters
partition
stringThe partition name to retrieve or store the value in.
key
stringThe key within the partition.
factory
Func<T>A function to create the value if it doesn't exist.
Returns
- T
The existing value if found, otherwise the newly created value from the factory.
Type Parameters
T
The type to deserialize/create.
Get<T>(string, string)
Retrieves a value from the specified partition and key.
T? Get<T>(string partition, string key)
Parameters
partition
stringThe partition name to retrieve the value from.
key
stringThe key within the partition.
Returns
- T
The deserialized value if found, otherwise the default value for type T.
Type Parameters
T
The type to deserialize the value to.
Load(string?)
Loads the page state from an encrypted string representation. If the encrypted string is null or empty, initializes with default state.
void Load(string? encrypted)
Parameters
encrypted
stringThe encrypted string containing the serialized state data, or null for initial state.
Set<T>(string, string, T)
Sets a value in the specified partition and key. This operation marks the state as dirty and increments the version.
void Set<T>(string partition, string key, T value)
Parameters
partition
stringThe partition name to store the value in.
key
stringThe key within the partition.
value
TThe value to store.
Type Parameters
T
The type of the value to store.