Skip to content

Commit 78fbda0

Browse files
committed
update
1 parent 5a837d4 commit 78fbda0

File tree

8 files changed

+164
-606
lines changed

8 files changed

+164
-606
lines changed

lib/src/models/base_model.dart

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ abstract mixin class BaseModel {
6464
//
6565
//
6666

67-
/// Returns a new copy of the BaseModel with the fields updated from the
68-
/// [other] BaseModel. Set [deepMerge] to `true` to merge nested objects.
69-
T mergeWith<T extends BaseModel>(BaseModel? other, {bool deepMerge = false});
70-
71-
//
72-
//
73-
//
74-
7567
/// Converts the current [BaseModel] to a [Uri] that can be used as a
7668
/// distinct identifier. The model must not be too large to avoid exceeding
7769
/// the maximum length of a URL.

lib/src/models/data_ref/_data_ref_model.g.dart

Lines changed: 41 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ part of 'data_ref_model.dart';
2020
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2121

2222
/// Generated class for [_DataRefModel].
23-
class DataRefModel extends _DataRefModel {
23+
class DataRefModel extends Model {
2424
//
2525
//
2626
//
@@ -31,36 +31,29 @@ class DataRefModel extends _DataRefModel {
3131
@override
3232
String get $className => CLASS_NAME;
3333

34-
/// The document ID within the database. If null, the reference points to a collection instead of a specific document.
35-
final String? id;
36-
37-
/// A list representing the hierarchical path where the document or collection resides.
38-
final List<String>? collection;
34+
3935

4036
/// Constructs a new instance of [DataRefModel]
4137
/// from optional and required parameters.
4238
const DataRefModel({
43-
this.id,
44-
required this.collection,
45-
});
39+
40+
}) ;
4641

4742
/// Construcs a new instance of [DataRefModel],
4843
/// forcing all parameters to be optional.
4944
const DataRefModel.optional({
50-
this.id,
51-
this.collection,
52-
});
45+
46+
}) ;
47+
5348

5449
/// Constructs a new instance of [DataRefModel],
5550
/// and asserts that all required parameters are not null.
5651
factory DataRefModel.assertRequired({
57-
String? id,
58-
List<String>? collection,
52+
5953
}) {
60-
assert(collection != null);
61-
return DataRefModel(
62-
id: id,
63-
collection: collection,
54+
55+
return const DataRefModel(
56+
6457
);
6558
}
6659

@@ -87,6 +80,7 @@ class DataRefModel extends _DataRefModel {
8780
return fromJsonOrNull(another?.toJson())!;
8881
}
8982

83+
9084
/// Constructs a new instance of [DataRefModel],
9185
/// from the fields of [another] instance. Throws if the conversion fails.
9286
factory DataRefModel.of(
@@ -119,7 +113,7 @@ class DataRefModel extends _DataRefModel {
119113
try {
120114
return fromJsonStringOrNull(jsonString)!;
121115
} catch (e) {
122-
assert(false, '$DataRefModel.fromJsonString: $e');
116+
assert(false, '$DataRefModel.fromJsonString: $e');
123117
rethrow;
124118
}
125119
}
@@ -163,18 +157,9 @@ class DataRefModel extends _DataRefModel {
163157
Map<String, dynamic>? json,
164158
) {
165159
try {
166-
final id = json?['id']?.toString().trim().nullIfEmpty;
167-
final collection = letListOrNull<dynamic>(json?['collection'])
168-
?.map(
169-
(p0) => p0?.toString().trim().nullIfEmpty,
170-
)
171-
.nonNulls
172-
.nullIfEmpty
173-
?.toList()
174-
.unmodifiable;
175-
return DataRefModel(
176-
id: id,
177-
collection: collection,
160+
161+
return const DataRefModel(
162+
178163
);
179164
} catch (e) {
180165
return null;
@@ -217,17 +202,9 @@ class DataRefModel extends _DataRefModel {
217202
bool includeNulls = false,
218203
}) {
219204
try {
220-
final id0 = id?.trim().nullIfEmpty;
221-
final collection0 = collection
222-
?.map(
223-
(p0) => p0?.trim().nullIfEmpty,
224-
)
225-
.nonNulls
226-
.nullIfEmpty
227-
?.toList();
205+
228206
final withNulls = {
229-
'id': id0,
230-
'collection': collection0,
207+
231208
};
232209
return includeNulls ? withNulls : withNulls.nonNulls;
233210
} catch (e) {
@@ -236,60 +213,45 @@ class DataRefModel extends _DataRefModel {
236213
}
237214
}
238215

239-
@override
240-
T mergeWith<T extends BaseModel>(
216+
217+
}
218+
219+
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
220+
221+
abstract final class DataRefModelFieldNames {
222+
223+
}
224+
225+
extension DataRefModelX on DataRefModel {
226+
/// Creates a copy of this instance, merging another model's fields into
227+
/// this model's fields.
228+
DataRefModel mergeWith(
241229
BaseModel? other, {
242230
bool deepMerge = false,
243231
}) {
244232
final a = toJson();
245233
final b = other?.toJson() ?? {};
246234
final data = (deepMerge ? mergeDataDeep(a, b) : {...a, ...b}) as Map;
247-
return DataRefModel.fromJson(data.cast()) as T;
235+
return DataRefModel.fromJson(data.cast());
248236
}
249237

250238
/// Creates a copy of this instance, replacing the specified fields.
251-
static DataRefModel copyWith(
252-
DataRefModel src, {
253-
String? id,
254-
List<String>? collection,
239+
DataRefModel copyWith(DataRefModel src, {
240+
255241
}) {
242+
final src = this;
256243
return DataRefModel.assertRequired(
257-
id: id ?? this.id,
258-
collection: collection ?? this.collection,
244+
259245
);
260246
}
261247

262248
/// Creates a copy of this instance, removing the specified fields.
263-
static DataRefModel copyWithout(
264-
DataRefModel src, {
265-
bool id = true,
266-
bool collection = true,
249+
DataRefModel copyWithout(DataRefModel src, {
250+
267251
}) {
252+
final src = this;
268253
return DataRefModel.assertRequired(
269-
id: id ? this.id : null,
270-
collection: collection ? this.collection : null,
254+
271255
);
272256
}
273-
274-
/// Returns the value of the [id] field.
275-
/// If the field is nullable, the return value may be null; otherwise, it
276-
/// will always return a non-null value.
277-
@pragma('vm:prefer-inline')
278-
String? get id$ => id;
279-
280-
/// Returns the value of the [collection] field.
281-
/// If the field is nullable, the return value may be null; otherwise, it
282-
/// will always return a non-null value.
283-
@pragma('vm:prefer-inline')
284-
List<String> get collection$ => collection!;
285-
}
286-
287-
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
288-
289-
abstract final class DataRefModelFieldNames {
290-
/// The field name of [DataRefModel.id].
291-
static const id = 'id';
292-
293-
/// The field name of [DataRefModel.collection].
294-
static const collection = 'collection';
295-
}
257+
}

0 commit comments

Comments
 (0)