Skip to content

Commit 8ab0adc

Browse files
binding: Add getGlobalStoreSync method
This will be useful in the later commits to query GlobalSettings while content HTML parsing phase.
1 parent fd7e3e3 commit 8ab0adc

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/model/binding.dart

+18-2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ abstract class ZulipBinding {
8383
/// a widget tree may not exist.
8484
Future<GlobalStore> getGlobalStore();
8585

86+
/// Get the app's singleton [GlobalStore] if already loaded, else null.
87+
///
88+
/// Where possible, use [GlobalStoreWidget.of] to get access to a [GlobalStore].
89+
/// Use this method only in contexts where getting access to a [BuildContext]
90+
/// is inconvenient.
91+
GlobalStore? getGlobalStoreSync();
92+
8693
/// Like [getGlobalStore], but assert this method was not previously called.
8794
///
8895
/// This is used by the implementation of [GlobalStoreWidget],
@@ -333,8 +340,17 @@ class LiveZulipBinding extends ZulipBinding {
333340
}
334341

335342
@override
336-
Future<GlobalStore> getGlobalStore() => _globalStore ??= LiveGlobalStore.load();
337-
Future<GlobalStore>? _globalStore;
343+
Future<GlobalStore> getGlobalStore() {
344+
return _globalStoreFuture ??= LiveGlobalStore.load().then((store) {
345+
return _globalStore = store;
346+
});
347+
}
348+
349+
@override
350+
GlobalStore? getGlobalStoreSync() => _globalStore;
351+
352+
Future<GlobalStore>? _globalStoreFuture;
353+
GlobalStore? _globalStore;
338354

339355
@override
340356
Future<GlobalStore> getGlobalStoreUniquely() {

test/model/binding.dart

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ class TestZulipBinding extends ZulipBinding {
104104
@override
105105
Future<GlobalStore> getGlobalStore() => Future.value(globalStore);
106106

107+
@override
108+
GlobalStore? getGlobalStoreSync() => globalStore;
109+
107110
@override
108111
Future<GlobalStore> getGlobalStoreUniquely() {
109112
assert(() {

0 commit comments

Comments
 (0)