pub struct Snapshot {
pub data: Map<String, Value>,
pub memo: Map<String, Value>,
pub checksum: String,
}Expand description
A component’s state between an initial page render and the browser’s next update.
Fields§
§data: Map<String, Value>The component’s wire-public properties, by name, in declaration order.
memo: Map<String, Value>Everything else an update needs: id, then name, then the feature memo entries.
checksum: StringThe checksum of signed_bytes, as lowercase hex.
Implementations§
Source§impl Snapshot
impl Snapshot
Sourcepub fn parse(json: &str) -> Result<Self, LivewireError>
pub fn parse(json: &str) -> Result<Self, LivewireError>
Parses the envelope, rejecting any structure the protocol does not define.
§Errors
LivewireError::InvalidSnapshot when the string is not a JSON object with an object
data, an object memo holding string id and name, and a string checksum.
Sourcepub fn encode(&self) -> String
pub fn encode(&self) -> String
Serializes minified, in envelope order.
memo.children is written as an object whenever the memo holds it, so an empty child list
is {} and never null or omitted.
Sourcepub fn id(&self) -> Result<&str, LivewireError>
pub fn id(&self) -> Result<&str, LivewireError>
The component’s ID, memo.id.
§Errors
LivewireError::InvalidSnapshot when the memo holds no string id.
Sourcepub fn name(&self) -> Result<&str, LivewireError>
pub fn name(&self) -> Result<&str, LivewireError>
The component’s registered name, memo.name.
§Errors
LivewireError::InvalidSnapshot when the memo holds no string name.
Sourcepub fn children(&self) -> Map<String, Value>
pub fn children(&self) -> Map<String, Value>
memo.children, always an object, empty when absent.
Sourcepub fn set_children(&mut self, children: Map<String, Value>)
pub fn set_children(&mut self, children: Map<String, Value>)
Replaces memo.children, writing it on encode even when empty.
Sourcepub fn memo_value(&self, key: &str) -> Option<&Value>
pub fn memo_value(&self, key: &str) -> Option<&Value>
A memo entry, such as path, method, parent, release.
Sourcepub fn signed_bytes(&self) -> String
pub fn signed_bytes(&self) -> String
The JSON that the checksum signs: {data, memo} with memo.children removed.
The client may rewrite the child list without invalidating the snapshot, so the child list is the one part of the envelope the checksum does not cover.