mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-08-26 10:38:13 +08:00
Rename NoteView -> NoteMaterializedView
It is stored in the disk
This commit is contained in:
@ -4,18 +4,18 @@ import 'note.dart';
|
|||||||
|
|
||||||
typedef NotesViewComputer<T> = T Function(Note note);
|
typedef NotesViewComputer<T> = T Function(Note note);
|
||||||
|
|
||||||
class NotesView<T> {
|
class NotesMaterializedView<T> {
|
||||||
final Box storageBox;
|
final Box storageBox;
|
||||||
final NotesViewComputer computeFn;
|
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,
|
String name,
|
||||||
NotesViewComputer computeFn,
|
NotesViewComputer computeFn,
|
||||||
) async {
|
) async {
|
||||||
var box = await Hive.openBox<T>(name);
|
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
|
// 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!
|
// FIXME: the note.filePath doesn't need to contain the full path!
|
||||||
var ts = note.fileLastModified!.toUtc().millisecondsSinceEpoch / 1000;
|
var ts = note.fileLastModified!.toUtc().millisecondsSinceEpoch / 1000;
|
||||||
var path = note.filePath;
|
var path = note.filePath;
|
||||||
var key = '${ts}_$path';
|
var key = '${path}_$ts';
|
||||||
|
|
||||||
T? val = storageBox.get(key, defaultValue: null);
|
T? val = storageBox.get(key, defaultValue: null);
|
||||||
if (val == null) {
|
if (val == null) {
|
@ -2,7 +2,7 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:gitjournal/core/notes_folder_config.dart';
|
import 'package:gitjournal/core/notes_folder_config.dart';
|
||||||
import 'package:gitjournal/core/notes_folder_fs.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/note.dart';
|
||||||
import 'package:gitjournal/core/transformers/base.dart';
|
import 'package:gitjournal/core/transformers/base.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
@ -48,7 +48,8 @@ Hello
|
|||||||
return note.fileName;
|
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();
|
var note = await _createExampleNote();
|
||||||
|
|
||||||
expect(view.fetch(note), note.fileName);
|
expect(view.fetch(note), note.fileName);
|
Reference in New Issue
Block a user