Rename NoteView -> NoteMaterializedView

It is stored in the disk
This commit is contained in:
Vishesh Handa
2021-08-31 16:24:15 +02:00
parent 4163f75189
commit 096d3a8278
2 changed files with 8 additions and 7 deletions

View File

@ -4,18 +4,18 @@ import 'note.dart';
typedef NotesViewComputer<T> = T Function(Note note);
class NotesView<T> {
class NotesMaterializedView<T> {
final Box storageBox;
final NotesViewComputer computeFn;
NotesView._internal(this.storageBox, this.computeFn);
NotesMaterializedView._internal(this.storageBox, this.computeFn);
static Future<NotesView<T>> loadView<T>(
static Future<NotesMaterializedView<T>> loadView<T>(
String name,
NotesViewComputer computeFn,
) async {
var box = await Hive.openBox<T>(name);
return NotesView<T>._internal(box, computeFn);
return NotesMaterializedView<T>._internal(box, computeFn);
}
// FIXME: The return value doesn't need to be optional
@ -29,7 +29,7 @@ class NotesView<T> {
// FIXME: the note.filePath doesn't need to contain the full path!
var ts = note.fileLastModified!.toUtc().millisecondsSinceEpoch / 1000;
var path = note.filePath;
var key = '${ts}_$path';
var key = '${path}_$ts';
T? val = storageBox.get(key, defaultValue: null);
if (val == null) {

View File

@ -2,7 +2,7 @@ import 'dart:io';
import 'package:gitjournal/core/notes_folder_config.dart';
import 'package:gitjournal/core/notes_folder_fs.dart';
import 'package:gitjournal/core/notes_view.dart';
import 'package:gitjournal/core/notes_materialized_view.dart';
import 'package:gitjournal/core/note.dart';
import 'package:gitjournal/core/transformers/base.dart';
import 'package:shared_preferences/shared_preferences.dart';
@ -48,7 +48,8 @@ Hello
return note.fileName;
};
var view = await NotesView.loadView<String>('_test_box', compute);
var view =
await NotesMaterializedView.loadView<String>('_test_box', compute);
var note = await _createExampleNote();
expect(view.fetch(note), note.fileName);