Skip to content

Commit 459690d

Browse files
committed
Remove Identifier.identifies()
1 parent 8cbc0a6 commit 459690d

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

lib/src/document/identifier.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ class Identifier {
1010
final String type;
1111
final String id;
1212

13-
String get key => '$type:$id';
14-
15-
/// True if this identifier identifies the [resource].
16-
bool identifies(Resource resource) =>
17-
type == resource.type && id == resource.id;
18-
1913
/// Identifier meta-data.
2014
final meta = <String, Object?>{};
2115

test/contract/crud_test.dart

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void main() {
6161
expect(fetchedAuthor.attributes['name'], 'Alice');
6262

6363
final fetchedComment =
64-
find(fetchedPost.many('comments')!, response.included).single;
64+
fetchedPost.many('comments')!.findIn(response.included).single;
6565
expect(fetchedComment.attributes['text'], 'Hi Alice');
6666
});
6767

@@ -145,12 +145,16 @@ void main() {
145145
Include(['comments'])
146146
]).then((r) {
147147
expect(
148-
find(r.resource.many('comments')!, r.included)
148+
r.resource
149+
.many('comments')!
150+
.findIn(r.included)
149151
.single
150152
.attributes['text'],
151153
'Secret comment');
152154
expect(
153-
find(r.resource.many('comments')!, r.included)
155+
r.resource
156+
.many('comments')!
157+
.findIn(r.included)
154158
.single
155159
.attributes['text'],
156160
'Secret comment');
@@ -179,9 +183,16 @@ void main() {
179183
});
180184
}
181185

182-
/// Finds the referenced elements which are found in the [collection].
183-
/// The resulting [Iterable] may contain fewer elements than referred by the
184-
/// relationship if the [collection] does not have all of them.
185-
Iterable<Resource> find(ToMany many, Iterable<Resource> collection) =>
186-
collection.where((resource) =>
187-
many.any((identifier) => identifier.identifies(resource)));
186+
extension _ToManyExt on ToMany {
187+
/// Finds the referenced elements which are found in the [collection].
188+
/// The resulting [Iterable] may contain fewer elements than referred by the
189+
/// relationship if the [collection] does not have all of them.
190+
Iterable<Resource> findIn(Iterable<Resource> collection) => collection.where(
191+
(resource) => any((identifier) => identifier.identifies(resource)));
192+
}
193+
194+
extension _IdentifierExt on Identifier {
195+
/// True if this identifier identifies the [resource].
196+
bool identifies(Resource resource) =>
197+
type == resource.type && id == resource.id;
198+
}

0 commit comments

Comments
 (0)