MCPcopy Create free account
hub / github.com/Effect-TS/effect / hydrate

Function hydrate

packages/effect/src/unstable/reactivity/Hydration.ts:128–155  ·  view source on GitHub ↗
(
  registry: AtomRegistry.AtomRegistry,
  dehydratedState: Iterable<DehydratedAtom>
)

Source from the content-addressed store, hash-verified

126 * @since 4.0.0
127 */
128export const hydrate = (
129 registry: AtomRegistry.AtomRegistry,
130 dehydratedState: Iterable<DehydratedAtom>
131): void => {
132 for (const datom of (dehydratedState as Iterable<DehydratedAtomValue>)) {
133 registry.setSerializable(datom.key, datom.value)
134
135 // If there's a resultPromise, it means this was in Initial state when dehydrated
136 // and we should wait for it to resolve to a non-Initial state, then update the registry
137 if (!datom.resultPromise) continue
138 datom.resultPromise.then((resolvedValue) => {
139 // Try to update the existing node directly instead of using setSerializable
140 const nodes = registry.getNodes()
141 const node = nodes.get(datom.key)
142 if (node) {
143 // Decode the resolved value using the node's atom serializable decoder
144 const atom = node.atom as any
145 if (atom[Atom.SerializableTypeId]) {
146 const decoded = atom[Atom.SerializableTypeId].decode(resolvedValue)
147 ;(node as any).setValue(decoded)
148 }
149 } else {
150 // Fallback to setSerializable if node doesn't exist yet
151 registry.setSerializable(datom.key, resolvedValue)
152 }
153 })
154 }
155}

Callers

nothing calls this directly

Calls 4

setSerializableMethod · 0.80
getNodesMethod · 0.80
getMethod · 0.65
setValueMethod · 0.45

Tested by

no test coverage detected