-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type registration improvements idea #163
Comments
I think this is a great idea. Thank you for the pull requests. Please give me a few days to merge them :) |
Added typeId property to HiveType (#163)
Published with v1.3.0. |
With this implement, I have something to say...
That makes the The new change might made the Too aggressive with this change, and it didn't land on a new major version. 😢 |
I would not recommend the way you registered I'm thinking about a way to automate the
I'm sorry for that. I should have created a new major version. Ultimately I think the new API is easier to use and more consistent. I also don't think it is a good idea to determine |
Actually when it comes to the app which was published, there's almost no chances to remove a type adapter or even a box.
Maybe it just needs a box to store the ids :P (just kidding) Now I'm using a class and constants to define
Generate constants was usually used to generate routes, I think at here it works. |
Great idea!!! Does the generator accept the constants? I might recommend that in the docs... |
Yes it works fine now. I've just finished reconfigure my projects with this migration. 😄 |
Sorry for not realizing this sooner, but this kind of broke my workflow. Because Hive doesn't support generics yet (writing an class IdAdapter<T> extends TypeAdapter<Id<T>> {
@override
Id<T> read(BinaryReader reader) => Id<T>(reader.readString());
@override
void write(BinaryWriter writer, Id obj) => writer.writeString(obj.id);
}
class ColorAdapter extends TypeAdapter<Color> {
@override
Color read(BinaryReader reader) => Color(reader.readInt());
@override
void write(BinaryWriter writer, Color color) => writer.writeInt(color.value);
} Hive
// this is an excerpt of the registry process
..registerAdapter(IdAdapter<ContentType>(), 41)
..registerAdapter(IdAdapter<Content>(), 42)
..registerAdapter(IdAdapter<Course>(), 43)
..registerAdapter(IdAdapter<Lesson>(), 44) This doesn't work anymore with this feature implemented. |
You could do the following: class IdAdapter<T> extends TypeAdapter<Id<T>> {
@override
final int typeId;
IdAdapter(this.typeId);
...
}
Hive.registerAdapter(IdAdapter<ContentType>(41));
... |
Works for us this way, thanks 😊 For the future though, I would strongly advise against pushing breaking changes in minor versions. This goes against the principles of semantic versioning: Versions of the form MAJOR.MINOR.PATCH should only contain breaking changes in major releases, although |
Added typeId property to HiveType (#163)
Simplify custom type registration
partially hide typeid for registration
The bottom line is that the id is initialized only once and cannot be changed in the future. it would be more logical to combine it with the model itself
now:
After:
The text was updated successfully, but these errors were encountered: