Skip to content

Commit c107fe8

Browse files
committed
store [nfc]: Simplify name GlobalStore.settings, from globalSettings
It's natural that the settings found directly on the global store are the global settings.
1 parent 6483514 commit c107fe8

File tree

7 files changed

+17
-19
lines changed

7 files changed

+17
-19
lines changed

lib/model/store.dart

+3-5
Original file line numberDiff line numberDiff line change
@@ -58,23 +58,21 @@ abstract class GlobalStore extends ChangeNotifier {
5858
required GlobalSettingsData globalSettings,
5959
required Iterable<Account> accounts,
6060
})
61-
: settingsNotifier = GlobalSettingsStore(data: globalSettings),
61+
: settings = GlobalSettingsStore(data: globalSettings),
6262
_accounts = Map.fromEntries(accounts.map((a) => MapEntry(a.id, a)));
6363

64-
final GlobalSettingsStore settingsNotifier; // TODO rename as the store
65-
6664
/// The store for the user's account-independent settings.
6765
///
6866
/// When the settings data changes, the [GlobalSettingsStore] will notify
6967
/// its listeners, but the [GlobalStore] will not notify its own listeners.
7068
/// Consider using [GlobalStoreWidget.settingsOf], which automatically
7169
/// subscribes to changes in the [GlobalSettingsStore].
72-
GlobalSettingsStore get globalSettings => settingsNotifier;
70+
final GlobalSettingsStore settings;
7371

7472
/// Update the global settings in the store.
7573
Future<void> updateGlobalSettings(GlobalSettingsCompanion data) async {
7674
await doUpdateGlobalSettings(data);
77-
settingsNotifier.update(data);
75+
settings.update(data);
7876
}
7977

8078
/// Update the global settings in the underlying data store.

lib/widgets/store.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class _GlobalStoreInheritedWidget extends InheritedNotifier<GlobalStore> {
110110
required Widget child,
111111
}) : super(notifier: store,
112112
child: _GlobalSettingsStoreInheritedWidget(
113-
store: store.settingsNotifier, child: child));
113+
store: store.settings, child: child));
114114

115115
GlobalStore get store => notifier!;
116116
}

test/model/settings_test.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,37 @@ void main() {
1717
testAndroidIos('globalSettings.browserPreference is null; use our per-platform defaults for HTTP links', () {
1818
final globalStore = eg.globalStore(globalSettings: GlobalSettingsData(
1919
browserPreference: null));
20-
check(globalStore).globalSettings.getUrlLaunchMode(httpLink).equals(
20+
check(globalStore).settings.getUrlLaunchMode(httpLink).equals(
2121
defaultTargetPlatform == TargetPlatform.android
2222
? UrlLaunchMode.inAppBrowserView : UrlLaunchMode.externalApplication);
2323
});
2424

2525
testAndroidIos('globalSettings.browserPreference is null; use our per-platform defaults for non-HTTP links', () {
2626
final globalStore = eg.globalStore(globalSettings: GlobalSettingsData(
2727
browserPreference: null));
28-
check(globalStore).globalSettings.getUrlLaunchMode(nonHttpLink).equals(
28+
check(globalStore).settings.getUrlLaunchMode(nonHttpLink).equals(
2929
defaultTargetPlatform == TargetPlatform.android
3030
? UrlLaunchMode.platformDefault : UrlLaunchMode.externalApplication);
3131
});
3232

3333
testAndroidIos('globalSettings.browserPreference is inApp; follow the user preference for http links', () {
3434
final globalStore = eg.globalStore(globalSettings: GlobalSettingsData(
3535
browserPreference: BrowserPreference.inApp));
36-
check(globalStore).globalSettings.getUrlLaunchMode(httpLink).equals(
36+
check(globalStore).settings.getUrlLaunchMode(httpLink).equals(
3737
UrlLaunchMode.inAppBrowserView);
3838
});
3939

4040
testAndroidIos('globalSettings.browserPreference is inApp; use platform default for non-http links', () {
4141
final globalStore = eg.globalStore(globalSettings: GlobalSettingsData(
4242
browserPreference: BrowserPreference.inApp));
43-
check(globalStore).globalSettings.getUrlLaunchMode(nonHttpLink).equals(
43+
check(globalStore).settings.getUrlLaunchMode(nonHttpLink).equals(
4444
UrlLaunchMode.platformDefault);
4545
});
4646

4747
testAndroidIos('globalSettings.browserPreference is external; follow the user preference', () {
4848
final globalStore = eg.globalStore(globalSettings: GlobalSettingsData(
4949
browserPreference: BrowserPreference.external));
50-
check(globalStore).globalSettings.getUrlLaunchMode(httpLink).equals(
50+
check(globalStore).settings.getUrlLaunchMode(httpLink).equals(
5151
UrlLaunchMode.externalApplication);
5252
});
5353
});

test/model/store_checks.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension GlobalSettingsStoreChecks on Subject<GlobalSettingsStore> {
3535
}
3636

3737
extension GlobalStoreChecks on Subject<GlobalStore> {
38-
Subject<GlobalSettingsStore> get globalSettings => has((x) => x.globalSettings, 'globalSettings');
38+
Subject<GlobalSettingsStore> get settings => has((x) => x.settings, 'settings');
3939
Subject<Iterable<Account>> get accounts => has((x) => x.accounts, 'accounts');
4040
Subject<Iterable<int>> get accountIds => has((x) => x.accountIds, 'accountIds');
4141
Subject<Iterable<({ int accountId, Account account })>> get accountEntries => has((x) => x.accountEntries, 'accountEntries');

test/model/store_test.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ void main() {
3535
group('GlobalStore.updateGlobalSettings', () {
3636
test('smoke', () async {
3737
final globalStore = eg.globalStore();
38-
check(globalStore).globalSettings.themeSetting.equals(null);
38+
check(globalStore).settings.themeSetting.equals(null);
3939

4040
await globalStore.updateGlobalSettings(
4141
GlobalSettingsCompanion(themeSetting: Value(ThemeSetting.dark)));
42-
check(globalStore).globalSettings.themeSetting.equals(ThemeSetting.dark);
42+
check(globalStore).settings.themeSetting.equals(ThemeSetting.dark);
4343
});
4444

4545
test('should notify listeners', () async {
4646
int notifyCount = 0;
4747
final globalStore = eg.globalStore();
48-
globalStore.settingsNotifier.addListener(() => notifyCount++);
48+
globalStore.settings.addListener(() => notifyCount++);
4949
check(notifyCount).equals(0);
5050

5151
await globalStore.updateGlobalSettings(

test/widgets/settings_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void main() {
4545
.checked.equals(title == expectedCheckedTitle);
4646
}
4747
check(testBinding.globalStore)
48-
.globalSettings.themeSetting.equals(expectedThemeSetting);
48+
.settings.themeSetting.equals(expectedThemeSetting);
4949
}
5050

5151
testWidgets('smoke', (tester) async {
@@ -97,7 +97,7 @@ void main() {
9797
check(tester.widget<SwitchListTile>(useInAppBrowserSwitchFinder))
9898
.value.equals(checked);
9999
check(testBinding.globalStore)
100-
.globalSettings.browserPreference.equals(expectedBrowserPreference);
100+
.settings.browserPreference.equals(expectedBrowserPreference);
101101
}
102102

103103
testWidgets('smoke', (tester) async {

test/widgets/theme_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void main() {
111111

112112
await tester.pumpWidget(const TestZulipApp(child: Placeholder()));
113113
await tester.pump();
114-
check(testBinding.globalStore).globalSettings.themeSetting.isNull();
114+
check(testBinding.globalStore).settings.themeSetting.isNull();
115115

116116
final element = tester.element(find.byType(Placeholder));
117117
check(zulipThemeData(element)).brightness.equals(Brightness.light);
@@ -129,7 +129,7 @@ void main() {
129129

130130
await tester.pumpWidget(const TestZulipApp(child: Placeholder()));
131131
await tester.pump();
132-
check(testBinding.globalStore).globalSettings.themeSetting.isNull();
132+
check(testBinding.globalStore).settings.themeSetting.isNull();
133133

134134
final element = tester.element(find.byType(Placeholder));
135135
check(zulipThemeData(element)).brightness.equals(Brightness.light);

0 commit comments

Comments
 (0)