Skip to content

Commit fde5205

Browse files
committed
binding [nfc]: Rename ZulipBinding from DataBinding
We'll need some more bindings in this spirit. It's not clear there'll be enough of them that we need to split them into mixins across multiple files, like Flutter upstream does, so we'll try just putting them all in a single bindings class. Start by giving that one class a more generic name to fit.
1 parent f669f16 commit fde5205

File tree

8 files changed

+45
-45
lines changed

8 files changed

+45
-45
lines changed

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ void main() {
1212
return true;
1313
}());
1414
LicenseRegistry.addLicense(additionalLicenses);
15-
LiveDataBinding.ensureInitialized();
15+
LiveZulipBinding.ensureInitialized();
1616
runApp(const ZulipApp());
1717
}

lib/model/binding.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ import 'store.dart';
1818
/// [TestWidgetsFlutterBinding].
1919
/// This version is simplified because we don't (yet?) have enough complexity
2020
/// to put into these bindings to need to use mixins to split them up.
21-
abstract class DataBinding {
22-
DataBinding() {
21+
abstract class ZulipBinding {
22+
ZulipBinding() {
2323
assert(_instance == null);
2424
initInstance();
2525
}
2626

27-
/// The single instance of [DataBinding].
28-
static DataBinding get instance => checkInstance(_instance);
29-
static DataBinding? _instance;
27+
/// The single instance of [ZulipBinding].
28+
static ZulipBinding get instance => checkInstance(_instance);
29+
static ZulipBinding? _instance;
3030

31-
static T checkInstance<T extends DataBinding>(T? instance) {
31+
static T checkInstance<T extends ZulipBinding>(T? instance) {
3232
assert(() {
3333
if (instance == null) {
3434
throw FlutterError.fromParts([
3535
ErrorSummary('Zulip binding has not yet been initialized.'),
3636
ErrorHint(
37-
'In the app, this is done by the `LiveDataBinding.ensureInitialized()` call '
37+
'In the app, this is done by the `LiveZulipBinding.ensureInitialized()` call '
3838
'in the `void main()` method.',
3939
),
4040
ErrorHint(
41-
'In a test, one can call `TestDataBinding.ensureInitialized()` as the '
41+
'In a test, one can call `TestZulipBinding.ensureInitialized()` as the '
4242
'first line in the test\'s `main()` method to initialize the binding.',
4343
),
4444
]);
@@ -69,13 +69,13 @@ abstract class DataBinding {
6969
/// The global store returned by [loadGlobalStore], and consequently by
7070
/// [GlobalStoreWidget.of] in application code, will be a [LiveGlobalStore].
7171
/// It therefore uses a live server and live, persistent local database.
72-
class LiveDataBinding extends DataBinding {
73-
/// Initialize the binding if necessary, and ensure it is a [LiveDataBinding].
74-
static LiveDataBinding ensureInitialized() {
75-
if (DataBinding._instance == null) {
76-
LiveDataBinding();
72+
class LiveZulipBinding extends ZulipBinding {
73+
/// Initialize the binding if necessary, and ensure it is a [LiveZulipBinding].
74+
static LiveZulipBinding ensureInitialized() {
75+
if (ZulipBinding._instance == null) {
76+
LiveZulipBinding();
7777
}
78-
return DataBinding.instance as LiveDataBinding;
78+
return ZulipBinding.instance as LiveZulipBinding;
7979
}
8080

8181
@override

lib/widgets/store.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class _GlobalStoreWidgetState extends State<GlobalStoreWidget> {
5555
void initState() {
5656
super.initState();
5757
(() async {
58-
final store = await DataBinding.instance.loadGlobalStore();
58+
final store = await ZulipBinding.instance.loadGlobalStore();
5959
setState(() {
6060
this.store = store;
6161
});

test/model/binding.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ import 'test_store.dart';
1616
///
1717
/// The global store returned by [loadGlobalStore], and consequently by
1818
/// [GlobalStoreWidget.of] in application code, will be a [TestGlobalStore].
19-
class TestDataBinding extends DataBinding {
20-
/// Initialize the binding if necessary, and ensure it is a [TestDataBinding].
19+
class TestZulipBinding extends ZulipBinding {
20+
/// Initialize the binding if necessary, and ensure it is a [TestZulipBinding].
2121
///
2222
/// This method is idempotent; calling it repeatedly simply returns the
2323
/// existing binding.
2424
///
25-
/// If there is an existing binding but it is not a [TestDataBinding],
25+
/// If there is an existing binding but it is not a [TestZulipBinding],
2626
/// this method throws an error.
27-
static TestDataBinding ensureInitialized() {
27+
static TestZulipBinding ensureInitialized() {
2828
if (_instance == null) {
29-
TestDataBinding();
29+
TestZulipBinding();
3030
}
3131
return instance;
3232
}
3333

3434
/// The single instance of the binding.
35-
static TestDataBinding get instance => DataBinding.checkInstance(_instance);
36-
static TestDataBinding? _instance;
35+
static TestZulipBinding get instance => ZulipBinding.checkInstance(_instance);
36+
static TestZulipBinding? _instance;
3737

3838
@override
3939
void initInstance() {
@@ -58,7 +58,7 @@ class TestDataBinding extends DataBinding {
5858
///
5959
/// Tests that mount a [GlobalStoreWidget], or that access [globalStore],
6060
/// should clean up by calling this method. Typically this is done using
61-
/// [addTearDown], like `addTearDown(TestDataBinding.instance.reset);`.
61+
/// [addTearDown], like `addTearDown(TestZulipBinding.instance.reset);`.
6262
void reset() {
6363
_globalStore?.dispose();
6464
_globalStore = null;
@@ -83,7 +83,7 @@ class TestDataBinding extends DataBinding {
8383
),
8484
ErrorHint(
8585
'Typically this is accomplished using [addTearDown], like '
86-
'`addTearDown(TestDataBinding.instance.reset);`.',
86+
'`addTearDown(TestZulipBinding.instance.reset);`.',
8787
),
8888
]);
8989
}

test/model/test_store.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import '../api/fake_api.dart';
1313
///
1414
/// The per-account stores will use [FakeApiConnection].
1515
///
16-
/// See also [TestDataBinding.globalStore], which provides one of these.
16+
/// See also [TestZulipBinding.globalStore], which provides one of these.
1717
class TestGlobalStore extends GlobalStore {
1818
TestGlobalStore({required super.accounts});
1919

test/widgets/action_sheet_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
2424
required Message message,
2525
required Narrow narrow,
2626
}) async {
27-
addTearDown(TestDataBinding.instance.reset);
27+
addTearDown(TestZulipBinding.instance.reset);
2828

29-
await TestDataBinding.instance.globalStore.add(eg.selfAccount, eg.initialSnapshot());
30-
final store = await TestDataBinding.instance.globalStore.perAccount(eg.selfAccount.id);
29+
await TestZulipBinding.instance.globalStore.add(eg.selfAccount, eg.initialSnapshot());
30+
final store = await TestZulipBinding.instance.globalStore.perAccount(eg.selfAccount.id);
3131
store.addUser(eg.user(userId: message.senderId));
3232
if (message is StreamMessage) {
3333
store.addStream(eg.stream(streamId: message.streamId));
@@ -61,7 +61,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
6161
}
6262

6363
void main() {
64-
TestDataBinding.ensureInitialized();
64+
TestZulipBinding.ensureInitialized();
6565

6666
group('QuoteAndReplyButton', () {
6767
ComposeBoxController? findComposeBoxController(WidgetTester tester) {
@@ -133,7 +133,7 @@ void main() {
133133
testWidgets('in stream narrow', (WidgetTester tester) async {
134134
final message = eg.streamMessage();
135135
await setupToMessageActionSheet(tester, message: message, narrow: StreamNarrow(message.streamId));
136-
final store = await TestDataBinding.instance.globalStore.perAccount(eg.selfAccount.id);
136+
final store = await TestZulipBinding.instance.globalStore.perAccount(eg.selfAccount.id);
137137

138138
final composeBoxController = findComposeBoxController(tester)!;
139139
final contentController = composeBoxController.contentController;
@@ -151,7 +151,7 @@ void main() {
151151
testWidgets('in topic narrow', (WidgetTester tester) async {
152152
final message = eg.streamMessage();
153153
await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message));
154-
final store = await TestDataBinding.instance.globalStore.perAccount(eg.selfAccount.id);
154+
final store = await TestZulipBinding.instance.globalStore.perAccount(eg.selfAccount.id);
155155

156156
final composeBoxController = findComposeBoxController(tester)!;
157157
final contentController = composeBoxController.contentController;
@@ -170,7 +170,7 @@ void main() {
170170
final message = eg.dmMessage(from: eg.selfUser, to: [eg.otherUser]);
171171
await setupToMessageActionSheet(tester,
172172
message: message, narrow: DmNarrow.ofMessage(message, selfUserId: eg.selfUser.userId));
173-
final store = await TestDataBinding.instance.globalStore.perAccount(eg.selfAccount.id);
173+
final store = await TestZulipBinding.instance.globalStore.perAccount(eg.selfAccount.id);
174174

175175
final composeBoxController = findComposeBoxController(tester)!;
176176
final contentController = composeBoxController.contentController;
@@ -188,7 +188,7 @@ void main() {
188188
testWidgets('request has an error', (WidgetTester tester) async {
189189
final message = eg.streamMessage();
190190
await setupToMessageActionSheet(tester, message: message, narrow: TopicNarrow.ofMessage(message));
191-
final store = await TestDataBinding.instance.globalStore.perAccount(eg.selfAccount.id);
191+
final store = await TestZulipBinding.instance.globalStore.perAccount(eg.selfAccount.id);
192192

193193
final composeBoxController = findComposeBoxController(tester)!;
194194
final contentController = composeBoxController.contentController;

test/widgets/content_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import '../example_data.dart' as eg;
1212
import '../model/binding.dart';
1313

1414
void main() {
15-
TestDataBinding.ensureInitialized();
15+
TestZulipBinding.ensureInitialized();
1616

1717
group('RealmContentNetworkImage', () {
1818
final authHeaders = authHeader(email: eg.selfAccount.email, apiKey: eg.selfAccount.apiKey);
1919

2020
Future<String?> actualAuthHeader(WidgetTester tester, String src) async {
21-
final globalStore = TestDataBinding.instance.globalStore;
22-
addTearDown(TestDataBinding.instance.reset);
21+
final globalStore = TestZulipBinding.instance.globalStore;
22+
addTearDown(TestZulipBinding.instance.reset);
2323
await globalStore.add(eg.selfAccount, eg.initialSnapshot());
2424

2525
final httpClient = _FakeHttpClient();

test/widgets/store_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import '../example_data.dart' as eg;
99
import '../model/store_checks.dart';
1010

1111
void main() {
12-
TestDataBinding.ensureInitialized();
12+
TestZulipBinding.ensureInitialized();
1313

1414
testWidgets('GlobalStoreWidget', (WidgetTester tester) async {
15-
addTearDown(TestDataBinding.instance.reset);
15+
addTearDown(TestZulipBinding.instance.reset);
1616

1717
GlobalStore? globalStore;
1818
await tester.pumpWidget(
@@ -29,17 +29,17 @@ void main() {
2929
await tester.pump();
3030
// Then after loading, mounts child instead, with provided store.
3131
check(tester.any(find.byType(CircularProgressIndicator))).isFalse();
32-
check(globalStore).identicalTo(TestDataBinding.instance.globalStore);
32+
check(globalStore).identicalTo(TestZulipBinding.instance.globalStore);
3333

34-
await TestDataBinding.instance.globalStore.add(eg.selfAccount, eg.initialSnapshot());
34+
await TestZulipBinding.instance.globalStore.add(eg.selfAccount, eg.initialSnapshot());
3535
check(globalStore).isNotNull()
3636
.accountEntries.single
3737
.equals((accountId: eg.selfAccount.id, account: eg.selfAccount));
3838
});
3939

4040
testWidgets('PerAccountStoreWidget basic', (tester) async {
41-
final globalStore = TestDataBinding.instance.globalStore;
42-
addTearDown(TestDataBinding.instance.reset);
41+
final globalStore = TestZulipBinding.instance.globalStore;
42+
addTearDown(TestZulipBinding.instance.reset);
4343
await globalStore.add(eg.selfAccount, eg.initialSnapshot());
4444

4545
await tester.pumpWidget(
@@ -60,8 +60,8 @@ void main() {
6060
});
6161

6262
testWidgets('PerAccountStoreWidget immediate data after first loaded', (tester) async {
63-
final globalStore = TestDataBinding.instance.globalStore;
64-
addTearDown(TestDataBinding.instance.reset);
63+
final globalStore = TestZulipBinding.instance.globalStore;
64+
addTearDown(TestZulipBinding.instance.reset);
6565
await globalStore.add(eg.selfAccount, eg.initialSnapshot());
6666

6767
await tester.pumpWidget(

0 commit comments

Comments
 (0)