Skip to content

Commit d37bf51

Browse files
committed
remove withKeyOf stuff for now
1 parent f6aa84a commit d37bf51

File tree

3 files changed

+3
-163
lines changed

3 files changed

+3
-163
lines changed

lib/src/model/data_model.dart

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,6 @@ abstract class DataModel<T extends DataModel<T>> with DataModelMixin<T> {
88
/// Returns a model [Adapter]
99
static Adapter adapterFor(DataModelMixin model) => model._adapter;
1010

11-
// static T withKey<T extends DataModelMixin<T>>(String sourceKey,
12-
// {required T applyTo}) {
13-
// final core = applyTo._adapter.core;
14-
// final type = applyTo._internalType;
15-
16-
// // ONLY data we keep from source is its key
17-
// // ONLY data we remove from destination is its key
18-
// if (sourceKey != applyTo._key) {
19-
// final oldKey = applyTo._key;
20-
21-
// // assign correct key to destination
22-
// applyTo._key = sourceKey;
23-
24-
// // migrate relationships to new key
25-
// applyTo._adapter
26-
// ._initializeRelationships(applyTo, fromKey: sourceKey);
27-
28-
// if (applyTo.id != null) {
29-
// core._writeTxn(() {
30-
// // and associate ID with source key
31-
// // final typeId = applyTo.id!.typifyWith(type);
32-
// // core._keyOperations.add(AddKeyOperation(sourceKey, typeId));
33-
34-
// if (oldKey != null) {
35-
// core._storedModelBox.remove(oldKey.detypifyKey()!);
36-
// // core._keyOperations.add(RemoveKeyOperation(oldKey));
37-
// }
38-
// // core._keyCache[sourceKey.detypify() as int] = typeId;
39-
// });
40-
// }
41-
// }
42-
// return applyTo;
43-
// }
44-
4511
// data model helpers
4612

4713
/// Returns a model's `_key` private attribute.
@@ -95,22 +61,6 @@ mixin DataModelMixin<T extends DataModelMixin<T>> {
9561
/// linking them to common [Adapter] methods such as
9662
/// [save] and [delete].
9763
extension DataModelExtension<T extends DataModelMixin<T>> on DataModelMixin<T> {
98-
/// Copy identity (internal key) from an old model to a new one
99-
/// to signal they are the same.
100-
///
101-
/// **Only makes sense to use if model is immutable and has no ID!**
102-
///
103-
/// ```
104-
/// final walter = Person(name: 'Walter');
105-
/// person.copyWith(age: 56).withKeyOf(walter);
106-
/// ```
107-
// T withKeyOf(T model) {
108-
// if (model._key == null) {
109-
// throw Exception("Model must be initialized:\n\n$model");
110-
// }
111-
// return DataModel.withKey<T>(model._key!, applyTo: this as T);
112-
// }
113-
11464
/// Saves this model through a call equivalent to [save].
11565
///
11666
/// Usage: `await post.save()`, `author.save(remote: false, params: {'a': 'x'})`.

test/model/data_model_test.dart

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -34,113 +34,6 @@ void main() async {
3434
expect(result!.id, 3);
3535
});
3636

37-
// test('withKeyOf', () {
38-
// final familias = <Familia>[];
39-
// final pairs = <(Person, Person)>[];
40-
// container.familia.writeTxn(() {
41-
// familias.addAll([
42-
// Familia(id: '1', surname: 'Tester 1').saveLocal(),
43-
// Familia(id: '2', surname: 'Tester 2').saveLocal(),
44-
// Familia(id: '3', surname: 'Tester 3').saveLocal(),
45-
// Familia(id: '4', surname: 'Tester 4').saveLocal(),
46-
// Familia(id: '5', surname: 'Tester 5').saveLocal()
47-
// ]);
48-
// // source without ID + destination with ID
49-
// pairs.addAll([
50-
// (
51-
// Person(name: 'Peter', familia: familias[0].asBelongsTo).saveLocal(),
52-
// Person(
53-
// id: '1',
54-
// name: 'Peter Updated',
55-
// familia: familias[0].asBelongsTo)
56-
// .saveLocal()
57-
// ),
58-
// // source without ID + destination without ID
59-
// (
60-
// Person(name: 'Sonya', familia: familias[1].asBelongsTo).saveLocal(),
61-
// Person(name: 'Sonya Updated', familia: familias[1].asBelongsTo)
62-
// .saveLocal()
63-
// ),
64-
// // source with ID + destination with same ID
65-
// (
66-
// Person(id: '2', name: 'Mark', familia: familias[2].asBelongsTo)
67-
// .saveLocal(),
68-
// Person(
69-
// id: '2',
70-
// name: 'Mark Updated',
71-
// familia: familias[2].asBelongsTo)
72-
// .saveLocal()
73-
// ),
74-
// // source with ID + destination with different ID
75-
// (
76-
// Person(id: '3', name: 'Daniel', familia: familias[3].asBelongsTo)
77-
// .saveLocal(),
78-
// Person(
79-
// id: '4',
80-
// name: 'Daniel Updated',
81-
// familia: familias[3].asBelongsTo)
82-
// .saveLocal()
83-
// ),
84-
// // source with ID + destination without ID
85-
// (
86-
// Person(id: '5', name: 'Peter', familia: familias[4].asBelongsTo)
87-
// .saveLocal(),
88-
// Person(name: 'Peter Updated', familia: familias[4].asBelongsTo)
89-
// .saveLocal()
90-
// ),
91-
// ]);
92-
// });
93-
94-
// for (final pair in pairs) {
95-
// final index = pairs.indexOf(pair);
96-
// // we receive an update from the server,
97-
// // gets initialized with a new key destination
98-
// final source = pair.$1;
99-
// final destination = pair.$2;
100-
101-
// final destKeyBefore = keyFor(destination);
102-
103-
// destination.withKeyOf(source);
104-
105-
// // now both objects have the same key
106-
// expect(keyFor(source), keyFor(destination));
107-
108-
// if (destination.id != null) {
109-
// // now the source key is associated to id=destination.id
110-
// expect(core.getKeyForId('people', destination.id), keyFor(source));
111-
// }
112-
// expect(destination.familia.value, familias[index]);
113-
114-
// if (keyFor(source) != keyFor(destination)) {
115-
// expect(core.getIdForKey(destKeyBefore), isNull);
116-
// }
117-
// }
118-
119-
// // test freezed copyWith with different IDs
120-
// final house = House(address: '123 Main St').saveLocal();
121-
// final b1 =
122-
// Book(id: 1, house: house.asBelongsTo, ardentSupporters: HasMany())
123-
// .saveLocal();
124-
// final b2 = b1.copyWith(id: 2);
125-
// // TODO check - copyWith mutates b1 relationships, so we need to save b2 to persist rels
126-
// b2.saveLocal();
127-
// b2.withKeyOf(b1);
128-
129-
// expect(keyFor(b1), keyFor(b2));
130-
// expect(b2.house?.value, house);
131-
132-
// // test library using DataModelMixin (that can be uninitialized)
133-
// final sourceLibrary = Library(id: 1, name: 'one', books: HasMany());
134-
// final destinationLibrary = Library(id: 2, name: 'two', books: HasMany());
135-
136-
// expect(() => destinationLibrary.withKeyOf(sourceLibrary), throwsException);
137-
138-
// final initializedSourceLibrary = sourceLibrary.init();
139-
// destinationLibrary.withKeyOf(initializedSourceLibrary);
140-
// expect(DataModelMixin.keyFor(initializedSourceLibrary),
141-
// DataModelMixin.keyFor(destinationLibrary));
142-
// });
143-
14437
test('findOne (remote and local reload)', () async {
14538
var familia = await Familia(id: '1', surname: 'Perez').save();
14639
familia = Familia(id: '1', surname: 'Perez Gomez');

test/repository/remote_adapter_watch_test.dart

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,7 @@ void main() async {
693693
verifyNever(listener(argThat(matcher)));
694694
verifyNoMoreInteractions(listener);
695695

696-
final steve = Person(name: 'Steve-O', age: 30)
697-
.saveLocal(); // removed .withKeyOf(frank)
696+
final steve = Person(name: 'Steve-O', age: 30).saveLocal();
698697
await oneMs();
699698

700699
verify(listener(argThat(matcher))).called(1);
@@ -713,8 +712,7 @@ void main() async {
713712
verifyNoMoreInteractions(listener);
714713

715714
print('f1');
716-
Familia(surname: 'Thomson', cottage: cottage.asBelongsTo)
717-
.saveLocal(); // removed .withKeyOf(familia)
715+
Familia(surname: 'Thomson', cottage: cottage.asBelongsTo).saveLocal();
718716

719717
await oneMs();
720718

@@ -727,8 +725,7 @@ void main() async {
727725
verify(listener(argThat(matcher))).called(1);
728726
verifyNoMoreInteractions(listener);
729727

730-
Familia(surname: 'Thomson', cottage: BelongsTo.remove())
731-
.saveLocal(); // removed .withKeyOf(familia)
728+
Familia(surname: 'Thomson', cottage: BelongsTo.remove()).saveLocal();
732729
await oneMs();
733730

734731
verify(listener(argThat(matcher))).called(1);

0 commit comments

Comments
 (0)