From 1004ab8542ec3e818a7efc7ad73c13d70e0dc1cd Mon Sep 17 00:00:00 2001 From: David Kunzler Date: Sun, 7 Mar 2021 00:25:47 +0100 Subject: [PATCH] fix notify with null value by providing complete frame and making it lazy in the keystore --- hive/lib/src/box/keystore.dart | 4 ++-- hive/lib/src/box/lazy_box_impl.dart | 2 +- hive/test/tests/box/lazy_box_impl_test.dart | 4 ++-- hive/test/tests/mocks.mocks.dart | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/hive/lib/src/box/keystore.dart b/hive/lib/src/box/keystore.dart index b02c12493..8aa5ebb31 100644 --- a/hive/lib/src/box/keystore.dart +++ b/hive/lib/src/box/keystore.dart @@ -146,7 +146,7 @@ class Keystore { } /// Not part of public API - Frame? insert(Frame frame, {bool notify = true}) { + Frame? insert(Frame frame, {bool notify = true, bool lazy = false}) { var value = frame.value; Frame? deletedFrame; @@ -160,7 +160,7 @@ class Keystore { value.init(key, _box); } - deletedFrame = _store.insert(key, frame); + deletedFrame = _store.insert(key, lazy ? frame.toLazy() : frame); } else { deletedFrame = _store.delete(frame.key); } diff --git a/hive/lib/src/box/lazy_box_impl.dart b/hive/lib/src/box/lazy_box_impl.dart index d522cb22d..78b3e79c7 100644 --- a/hive/lib/src/box/lazy_box_impl.dart +++ b/hive/lib/src/box/lazy_box_impl.dart @@ -66,7 +66,7 @@ class LazyBoxImpl extends BoxBaseImpl implements LazyBox { if (frame.value is HiveObject) { (frame.value as HiveObject).init(frame.key, this); } - keystore.insert(frame.toLazy()); + keystore.insert(frame, lazy: true); } await performCompactionIfNeeded(); diff --git a/hive/test/tests/box/lazy_box_impl_test.dart b/hive/test/tests/box/lazy_box_impl_test.dart index 4fc174c3d..8bce83768 100644 --- a/hive/test/tests/box/lazy_box_impl_test.dart +++ b/hive/test/tests/box/lazy_box_impl_test.dart @@ -88,8 +88,8 @@ void main() { Frame('key1', 'value1'), Frame('key2', 'value2'), ]), - keystore.insert(Frame.lazy('key1')), - keystore.insert(Frame.lazy('key2')), + keystore.insert(Frame('key1', 'value1'), lazy: true), + keystore.insert(Frame('key2', 'value2'), lazy: true), ]); }); diff --git a/hive/test/tests/mocks.mocks.dart b/hive/test/tests/mocks.mocks.dart index b81c339fa..9a545963d 100644 --- a/hive/test/tests/mocks.mocks.dart +++ b/hive/test/tests/mocks.mocks.dart @@ -162,8 +162,8 @@ class MockKeystore extends _i1.Mock implements _i11.Keystore { _i7.Stream<_i3.BoxEvent> watch({dynamic key}) => (super.noSuchMethod( Invocation.method(#watch, [], {#key: key}), Stream<_i3.BoxEvent>.empty()) as _i7.Stream<_i3.BoxEvent>); - _i9.Frame? insert(_i9.Frame? frame, {bool? notify = true}) => (super - .noSuchMethod(Invocation.method(#insert, [frame], {#notify: notify})) + _i9.Frame? insert(_i9.Frame? frame, {bool? notify = true, bool lazy = false}) => + (super.noSuchMethod(Invocation.method(#insert, [frame], {#notify: notify})) as _i9.Frame?); bool beginTransaction(List<_i9.Frame>? newFrames) => (super.noSuchMethod( Invocation.method(#beginTransaction, [newFrames]), false) as bool);