-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathfeature_access_stream_factory.dart
More file actions
50 lines (40 loc) · 1.9 KB
/
feature_access_stream_factory.dart
File metadata and controls
50 lines (40 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import 'dart:async';
import 'package:logging/logging.dart';
import 'package:rxdart/rxdart.dart';
import 'package:webtrit_phone/data/data.dart';
import 'package:webtrit_phone/models/models.dart';
import 'package:webtrit_phone/repositories/repositories.dart';
import 'package:webtrit_phone/services/services.dart';
import 'package:webtrit_phone/utils/core_support.dart';
final _logger = Logger('FeatureAccessStreamFactory');
class FeatureAccessStreamFactory {
final AppThemes appThemes;
final SystemInfoRepository systemInfoRepository;
final RemoteConfigService remoteConfigService;
FeatureAccessStreamFactory({
required this.appThemes,
required this.systemInfoRepository,
required this.remoteConfigService,
});
Future<FeatureAccess> getInitialSnapshot() async {
final systemInfo = await systemInfoRepository.getSystemInfo(fetchPolicy: FetchPolicy.cacheOnly);
return _build(systemInfo, remoteConfigService.snapshot);
}
Stream<FeatureAccess> create() async* {
final initialSystemInfo = await systemInfoRepository.getSystemInfo(fetchPolicy: FetchPolicy.cacheOnly);
final initialConfig = remoteConfigService.snapshot;
yield* CombineLatestStream.combine2<WebtritSystemInfo?, RemoteConfigSnapshot, FeatureAccess>(
systemInfoRepository.infoStream.cast<WebtritSystemInfo?>().startWith(initialSystemInfo),
remoteConfigService.onConfigUpdated.startWith(initialConfig),
(systemInfo, remoteConfig) {
_logger.info('Updating FeatureAccess from reactive stream');
return _build(systemInfo, remoteConfig);
},
);
}
FeatureAccess _build(WebtritSystemInfo? systemInfo, RemoteConfigSnapshot remoteConfig) {
final coreSupport = CoreSupportFactory.create(systemInfo);
final overrides = FeatureOverridesFactory.create(remoteConfig);
return FeatureAccess.create(appThemes.appConfig, appThemes.embeddedResources, coreSupport, systemInfo, overrides);
}
}