-
Notifications
You must be signed in to change notification settings - Fork 87
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
RDART-1010: Allow configuration of generator per realm model class #1641
Changes from 7 commits
fccede0
16af902
e112bbf
d33b858
cbc4be0
498a46a
9ca1297
36a43af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,18 +85,12 @@ enum RealmCollectionType { | |
_3, // ignore: unused_field, constant_identifier_names | ||
map; | ||
|
||
String get plural { | ||
switch (this) { | ||
case RealmCollectionType.list: | ||
return "lists"; | ||
case RealmCollectionType.set: | ||
return "sets"; | ||
case RealmCollectionType.map: | ||
return "maps"; | ||
default: | ||
return "none"; | ||
} | ||
} | ||
String get plural => switch (this) { | ||
RealmCollectionType.list => 'lists', | ||
RealmCollectionType.set => 'sets', | ||
RealmCollectionType.map => 'maps', | ||
_ => 'none' | ||
}; | ||
Comment on lines
+88
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A small drive by edit. Not related to this PR |
||
} | ||
|
||
/// A base class of all Realm errors. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import 'package:realm_common/realm_common.dart'; | ||
|
||
part 'all_named_ctor.realm.dart'; | ||
|
||
const config = GeneratorConfig(ctorStyle: CtorStyle.allNamed); | ||
const realmModel = RealmModel.using(baseType: ObjectType.realmObject, generatorConfig: config); | ||
|
||
@realmModel | ||
class _Person { | ||
late String name; | ||
int age = 42; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// GENERATED CODE - DO NOT MODIFY BY HAND | ||
|
||
part of 'all_named_ctor.dart'; | ||
|
||
// ************************************************************************** | ||
// RealmObjectGenerator | ||
// ************************************************************************** | ||
|
||
// ignore_for_file: type=lint | ||
class Person extends _Person with RealmEntity, RealmObjectBase, RealmObject { | ||
static var _defaultsSet = false; | ||
|
||
Person({ | ||
required String name, | ||
int age = 42, | ||
}) { | ||
Comment on lines
+13
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The interesting bit |
||
if (!_defaultsSet) { | ||
_defaultsSet = RealmObjectBase.setDefaults<Person>({ | ||
'age': 42, | ||
}); | ||
} | ||
RealmObjectBase.set(this, 'name', name); | ||
RealmObjectBase.set(this, 'age', age); | ||
} | ||
|
||
Person._(); | ||
|
||
@override | ||
String get name => RealmObjectBase.get<String>(this, 'name') as String; | ||
@override | ||
set name(String value) => RealmObjectBase.set(this, 'name', value); | ||
|
||
@override | ||
int get age => RealmObjectBase.get<int>(this, 'age') as int; | ||
@override | ||
set age(int value) => RealmObjectBase.set(this, 'age', value); | ||
|
||
@override | ||
Stream<RealmObjectChanges<Person>> get changes => | ||
RealmObjectBase.getChanges<Person>(this); | ||
|
||
@override | ||
Stream<RealmObjectChanges<Person>> changesFor([List<String>? keyPaths]) => | ||
RealmObjectBase.getChangesFor<Person>(this, keyPaths); | ||
|
||
@override | ||
Person freeze() => RealmObjectBase.freezeObject<Person>(this); | ||
|
||
EJsonValue toEJson() { | ||
return <String, dynamic>{ | ||
'name': name.toEJson(), | ||
'age': age.toEJson(), | ||
}; | ||
} | ||
|
||
static EJsonValue _toEJson(Person value) => value.toEJson(); | ||
static Person _fromEJson(EJsonValue ejson) { | ||
return switch (ejson) { | ||
{ | ||
'name': EJsonValue name, | ||
'age': EJsonValue age, | ||
} => | ||
Person( | ||
name: fromEJson(name), | ||
age: fromEJson(age), | ||
), | ||
_ => raiseInvalidEJson(ejson), | ||
}; | ||
} | ||
|
||
static final schema = () { | ||
RealmObjectBase.registerFactory(Person._); | ||
register(_toEJson, _fromEJson); | ||
return SchemaObject(ObjectType.realmObject, Person, 'Person', [ | ||
SchemaProperty('name', RealmPropertyType.string), | ||
SchemaProperty('age', RealmPropertyType.int), | ||
]); | ||
}(); | ||
|
||
@override | ||
SchemaObject get objectSchema => RealmObjectBase.getSchema(this) ?? schema; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
part of 'all_named_ctor.dart'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,15 +13,15 @@ class WithPrivateFields extends _WithPrivateFields | |
|
||
WithPrivateFields( | ||
String _plain, { | ||
int _withDefault = 0, | ||
int withDefault = 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually fixing a bug in version 2.1.0. Named arguments cannot start with underscore. |
||
}) { | ||
if (!_defaultsSet) { | ||
_defaultsSet = RealmObjectBase.setDefaults<WithPrivateFields>({ | ||
'_withDefault': 0, | ||
}); | ||
} | ||
RealmObjectBase.set(this, '_plain', _plain); | ||
RealmObjectBase.set(this, '_withDefault', _withDefault); | ||
RealmObjectBase.set(this, '_withDefault', withDefault); | ||
} | ||
|
||
WithPrivateFields._(); | ||
|
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.
Are you okay with this?
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.
I don't think it's a big deal. I don't imagine anyone has any code that reads this value.