🪄 Formats FSPersistence
This commit is contained in:
@@ -20,11 +20,9 @@
|
|||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class FSPersistence {
|
class FSPersistence {
|
||||||
public:
|
public:
|
||||||
FSPersistence(JsonStateReader<T> stateReader,
|
FSPersistence(JsonStateReader<T> stateReader, JsonStateUpdater<T> stateUpdater, StatefulService<T> *statefulService,
|
||||||
JsonStateUpdater<T> stateUpdater,
|
FS *fs, const char *filePath)
|
||||||
StatefulService<T> *statefulService, FS *fs,
|
|
||||||
const char *filePath)
|
|
||||||
: _stateReader(stateReader),
|
: _stateReader(stateReader),
|
||||||
_stateUpdater(stateUpdater),
|
_stateUpdater(stateUpdater),
|
||||||
_statefulService(statefulService),
|
_statefulService(statefulService),
|
||||||
@@ -39,13 +37,10 @@ class FSPersistence {
|
|||||||
|
|
||||||
if (settingsFile) {
|
if (settingsFile) {
|
||||||
JsonDocument jsonDocument;
|
JsonDocument jsonDocument;
|
||||||
DeserializationError error =
|
DeserializationError error = deserializeJson(jsonDocument, settingsFile);
|
||||||
deserializeJson(jsonDocument, settingsFile);
|
if (error == DeserializationError::Ok && jsonDocument.is<JsonObject>()) {
|
||||||
if (error == DeserializationError::Ok &&
|
|
||||||
jsonDocument.is<JsonObject>()) {
|
|
||||||
JsonObject jsonObject = jsonDocument.as<JsonObject>();
|
JsonObject jsonObject = jsonDocument.as<JsonObject>();
|
||||||
_statefulService->updateWithoutPropagation(jsonObject,
|
_statefulService->updateWithoutPropagation(jsonObject, _stateUpdater);
|
||||||
_stateUpdater);
|
|
||||||
settingsFile.close();
|
settingsFile.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -93,12 +88,11 @@ class FSPersistence {
|
|||||||
|
|
||||||
void enableUpdateHandler() {
|
void enableUpdateHandler() {
|
||||||
if (!_updateHandlerId) {
|
if (!_updateHandlerId) {
|
||||||
_updateHandlerId = _statefulService->addUpdateHandler(
|
_updateHandlerId = _statefulService->addUpdateHandler([&](const String &originId) { writeToFS(); });
|
||||||
[&](const String &originId) { writeToFS(); });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JsonStateReader<T> _stateReader;
|
JsonStateReader<T> _stateReader;
|
||||||
JsonStateUpdater<T> _stateUpdater;
|
JsonStateUpdater<T> _stateUpdater;
|
||||||
StatefulService<T> *_statefulService;
|
StatefulService<T> *_statefulService;
|
||||||
@@ -121,7 +115,7 @@ class FSPersistence {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// We assume the updater supplies sensible defaults if an empty object
|
// We assume the updater supplies sensible defaults if an empty object
|
||||||
// is supplied, this virtual function allows that to be changed.
|
// is supplied, this virtual function allows that to be changed.
|
||||||
virtual void applyDefaults() {
|
virtual void applyDefaults() {
|
||||||
@@ -131,4 +125,4 @@ class FSPersistence {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // end FSPersistence
|
#endif // end FSPersistence
|
||||||
|
|||||||
Reference in New Issue
Block a user