Overview
The Persistence API provides filesystem tree serialization and storage management with support for multiple backends. It includes automatic debouncing for efficient saves and graceful error handling.PersistenceManager
Manages the lifecycle of filesystem persistence with automatic debouncing and error recovery.Constructor
The storage backend implementation (e.g.,
IndexedDBPersistenceBackend or MemoryPersistenceBackend)Methods
open
Initializes the persistence backend.load
Loads the filesystem tree from persistent storage.Returns the deserialized root node, or
null if no saved state exists or deserialization failssave
Immediately saves the filesystem tree to persistent storage.The root node of the filesystem tree to persist
Save errors are gracefully ignored to prevent disrupting the application. Use
scheduleSave for automatic debouncing.scheduleSave
Schedules a debounced save operation. Automatically cancels pending saves.The root node of the filesystem tree to persist
The debounce interval is 1000ms (1 second). See
PersistenceManager.ts:5PersistenceBackend Interface
Defines the contract for persistence storage implementations.Initialize the storage backend
Load the serialized filesystem tree. Returns
null if not found.Save the serialized filesystem tree
Optional cleanup method to close connections and release resources
IndexedDBPersistenceBackend
Browser-based persistent storage using IndexedDB.Constructor
Configuration
- Database name:
lifo(seebackends.ts:18) - Object store:
filesystem(seebackends.ts:19) - Storage key:
root(seebackends.ts:20)
Methods
open
Opens or creates the IndexedDB database.Automatically creates the object store on first use. Gracefully degrades if IndexedDB is unavailable.
loadTree
Retrieves the filesystem tree from IndexedDB.The serialized filesystem tree, or
null if not found or on errorsaveTree
Persists the filesystem tree to IndexedDB.The serialized filesystem tree to store
close
Closes the IndexedDB connection.Example
MemoryPersistenceBackend
In-memory storage for testing and temporary filesystems.Constructor
Methods
open
loadTree
The in-memory serialized tree, or
null if nothing has been savedsaveTree
The serialized filesystem tree to store in memory
close
Example
SerializedNode Format
Compact representation of filesystem nodes.Virtual directories (
proc, dev) are excluded during serialization. See serializer.ts:22