PersistPayload constructor
Implementation
PersistPayload(List<Document> docs) {
final globalPersistorSettings = Loon.persistorSettings;
final defaultKey = switch (globalPersistorSettings) {
PersistorSettings(key: PersistorValueKey key) => key,
_ => Persistor.defaultKey,
};
resolver.write(ValueStore.root, defaultKey.value);
for (final doc in docs) {
final pathSettings = doc.persistorSettings;
if (pathSettings != null) {
switch (pathSettings) {
case PathPersistorSettings(
ref: final ref,
key: PersistorValueKey key
):
resolver.write(ref.path, key.value);
break;
case PathPersistorSettings(
ref: Document doc,
key: PersistorBuilderKey keyBuilder,
):
final path = doc.path;
final snap = doc.get();
if (snap != null) {
resolver.write(path, (keyBuilder as dynamic)(snap));
}
break;
}
} else if (globalPersistorSettings is PersistorSettings) {
switch (globalPersistorSettings) {
case PersistorSettings(key: PersistorBuilderKey keyBuilder):
final path = doc.path;
final snap = doc.get();
if (snap != null) {
resolver.write(path, (keyBuilder as dynamic)(snap));
}
break;
default:
break;
}
}
persistenceDocs.add(
PersistenceDocument(
path: doc.path,
data: doc.getSerialized(),
encrypted: doc.encrypted,
),
);
}
}