-
Notifications
You must be signed in to change notification settings - Fork 192
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
Introduce static 'to map' functions #178
Introduce static 'to map' functions #178
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #178 +/- ##
===========================================
+ Coverage 77.76% 77.78% +0.01%
===========================================
Files 49 49
Lines 1381 1382 +1
===========================================
+ Hits 1074 1075 +1
Misses 307 307
Continue to review full report at Codecov.
|
Thanks for your contribution! What's your specific use case for private static mapper functions? |
It wouldn't be private if this is part of a library, which then I can reuse to expose
By the way, I'm making use of this wonderful code a lot and if you need some assistance, I could help out. I've been working with Flutter for almost 2 years and engaged in many other open source Flutter plugins and libraries, feel free to contact me privately if you want a helping hand. |
What do you say about the pr, @vitusortner? This shouldn't affect the code really but it's very useful for my usecase, and basically when you architecture Floor as a library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merged and all good.
@vitusortner hope you'd be willing to merge this also, it's helping me when including Floor as a library. |
Would you be so kind and show me a complete code example on how you would use this? |
It's internal code so hang on while I prepare something up... |
database.dart: library my_dao;
part 'database.g.dart';
part 'entity/user.dart';
@Database(version: 1, entities: [UserEntity])
abstract class AppDatabase extends FloorDatabase {
// Implementation hidden.
}
/// Entities extend this class.
abstract class BaseEntity {
const BaseEntity);
// Additional abstract requirements on entities go here.
Map<String, dynamic> get toMap;
} entity/user.dart: part of my_dao;
/// Entity extends the BaseEntity
@Entity(tableName: 'users')
class UserEntity extends BaseEntity {
/// First use.
UserEntity.fromMap(<String, dynamic> map) => _$UserDao._userMapper(map);
// Properties hidden.
// Other implementations hidden.
/// Second use.
@override
Map<String, dynamic> get toMap {
final map = <String, dynamic>{};
_$UserDao._userMapper(map);
return map;
}
} |
@vitusortner example above. 2 places where the function can be reused. |
Both used when communicating with a JSON-based RESTful API. Learning from our previous merge experience, I would say that you'll probably introduce another mechanism to achieve this so I'm ready to adjust :) |
I see the value in reusing the mapping functionality of the library, but I'm unsure if the suggested implementation is the best what we can get. Nevertheless, as it's such a small change, let's still merge it. |
No description provided.