From e3526b491123e1e15a000b517a2238c5996a4438 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Mon, 26 Jul 2021 16:51:58 +0200 Subject: [PATCH] Minor refactoring --- lib/core/note.dart | 6 ++++-- lib/core/note_serializer.dart | 16 +++++++++------- lib/settings/settings_note_metadata.dart | 5 +++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/core/note.dart b/lib/core/note.dart index a84c5e6f..6a343b3c 100644 --- a/lib/core/note.dart +++ b/lib/core/note.dart @@ -116,7 +116,8 @@ class Note with NotesNotifier { static final _linksLoader = LinksLoader(); Note(this.parent, this._filePath) { - noteSerializer = NoteSerializer.fromConfig(parent.config); + var settings = NoteSerializationSettings.fromConfig(parent.config); + noteSerializer = NoteSerializer.fromConfig(settings); } Note.newNote( @@ -127,7 +128,8 @@ class Note with NotesNotifier { created = DateTime.now(); _loadState = NoteLoadState.Loaded; _fileFormat = NoteFileFormat.Markdown; - noteSerializer = NoteSerializer.fromConfig(parent.config); + var settings = NoteSerializationSettings.fromConfig(parent.config); + noteSerializer = NoteSerializer.fromConfig(settings); if (extraProps.isNotEmpty) { extraProps.forEach((key, value) { diff --git a/lib/core/note_serializer.dart b/lib/core/note_serializer.dart index 47e31f4a..e19f26f7 100644 --- a/lib/core/note_serializer.dart +++ b/lib/core/note_serializer.dart @@ -44,18 +44,20 @@ class NoteSerializationSettings { bool tagsHaveHash = false; SettingsTitle titleSettings = SettingsTitle.Default; + + NoteSerializationSettings.fromConfig(NotesFolderConfig config) { + modifiedKey = config.yamlModifiedKey; + createdKey = config.yamlCreatedKey; + tagsKey = config.yamlTagsKey; + titleSettings = config.titleSettings; + } + NoteSerializationSettings(); } class NoteSerializer implements NoteSerializerInterface { var settings = NoteSerializationSettings(); - NoteSerializer.fromConfig(NotesFolderConfig config) { - settings.modifiedKey = config.yamlModifiedKey; - settings.createdKey = config.yamlCreatedKey; - settings.tagsKey = config.yamlTagsKey; - settings.titleSettings = config.titleSettings; - } - + NoteSerializer.fromConfig(this.settings); NoteSerializer.raw(); @override diff --git a/lib/settings/settings_note_metadata.dart b/lib/settings/settings_note_metadata.dart index 80c80e05..38a254d7 100644 --- a/lib/settings/settings_note_metadata.dart +++ b/lib/settings/settings_note_metadata.dart @@ -211,8 +211,9 @@ class NoteOutputExample extends StatelessWidget { var settings = Provider.of(context); var doc = MdYamlDoc(); - NoteSerializer.fromConfig(NotesFolderConfig.fromSettings(null, settings)) - .encode(note, doc); + var folderConfig = NotesFolderConfig.fromSettings(null, settings); + var serialSettings = NoteSerializationSettings.fromConfig(folderConfig); + NoteSerializer.fromConfig(serialSettings).encode(note, doc); var codec = MarkdownYAMLCodec(); var noteStr = codec.encode(doc);