Skip to content

Commit 9732ca2

Browse files
committed
api: Add + operator on ServerEmojiData
This operator which right now is only intended for test usage, makes it easy to combine two emoji data objects with the control of which one overrides which.
1 parent 6b3a734 commit 9732ca2

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/api/route/realm.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:flutter/foundation.dart';
12
import 'package:http/http.dart' as http;
23
import 'package:json_annotation/json_annotation.dart';
34

@@ -137,6 +138,16 @@ class ServerEmojiData {
137138

138139
ServerEmojiData({required this.codeToNames});
139140

141+
/// Returns this emoji data merged with [other].
142+
///
143+
/// Returns a new `ServerEmojiData` object combining [codeToNames] of [this]
144+
/// and [other]. If there is any duplicate code key, its resulting names value
145+
/// will be from [other.codeToNames].
146+
@visibleForTesting
147+
ServerEmojiData operator +(ServerEmojiData other) {
148+
return ServerEmojiData(codeToNames: {...codeToNames, ...other.codeToNames});
149+
}
150+
140151
factory ServerEmojiData.fromJson(Map<String, dynamic> json) =>
141152
_$ServerEmojiDataFromJson(json);
142153

0 commit comments

Comments
 (0)