Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/hive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import 'dart:isolate'
if (dart.library.html) 'package:hive/src/impl/isolate_stub.dart';

import 'package:hive/src/impl/frame.dart';
import 'package:isar/isar.dart';
import 'package:isar_plus/isar_plus.dart';

part 'src/impl/box_impl.dart';
part 'src/impl/type_registry.dart';
part 'src/box.dart';
part 'src/hive.dart';
part 'src/impl/box_impl.dart';
part 'src/impl/type_registry.dart';
7 changes: 4 additions & 3 deletions lib/src/hive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ class Hive {
/// ```
static void registerAdapter<T>(
String typeName,
T? Function(dynamic json) fromJson,
) {
_typeRegistry.register<T>(Isar.fastHash(typeName), fromJson);
T? Function(dynamic json) fromJson, [
Type? type,
]) {
_typeRegistry.register<T>(Isar.fastHash(typeName), fromJson, type);
}

/// Get or open the box with [name] in the given [directory]. If no directory
Expand Down
2 changes: 1 addition & 1 deletion lib/src/impl/frame.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:isar/isar.dart';
import 'package:isar_plus/isar_plus.dart';

part 'frame.g.dart';

Expand Down
8 changes: 6 additions & 2 deletions lib/src/impl/type_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ class _TypeRegistry {
final Map<int, _TypeHandler<dynamic>> _registry = {};
final Map<Type, _TypeHandler<dynamic>> _reverseRegistry = {..._builtinTypes};

void register<T>(int typeId, T? Function(dynamic json) fromJson) {
void register<T>(
int typeId,
T? Function(dynamic json) fromJson,
Type? type,
) {
if (T == dynamic) {
throw ArgumentError('Cannot register dynamic type.');
}

final handler = _TypeHandler<T>(typeId, fromJson);
_registry[typeId] = handler;
_reverseRegistry[T] = handler;
_reverseRegistry[type ?? T] = handler;
}

T fromJson<T>(int? typeId, dynamic json) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ environment:
sdk: ">=3.1.0 <4.0.0"

dependencies:
isar: ^4.0.0-dev.13
isar_plus: ^1.0.4
meta: ^1.9.0

dev_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion test/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'dart:math';

import 'package:hive/hive.dart';
import 'package:hive/src/impl/frame.dart';
import 'package:isar/isar.dart';
import 'package:isar_plus/isar_plus.dart';
import 'package:test/test.dart';

const _releases = 'https://github.com/isar/isar/releases/download/';
Expand Down