Repository navigation
Expand file tree
/
Copy pathpond.dart
More file actions
65 lines (56 loc) · 2.61 KB
/
Copy pathpond.dart
File metadata and controls
65 lines (56 loc) · 2.61 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import 'dart:async';
import 'package:flood_core/flood_core.dart';
import 'package:todo_core/features/todo/todo_repository.dart';
import 'package:todo_core/features/user/user.dart';
import 'package:todo_core/features/user/user_entity.dart';
import 'package:todo_core/features/user/user_repository.dart';
Future<CorePondContext> getCorePondContext({
EnvironmentConfig? environmentConfig,
FutureOr<List<CorePondComponent>> Function(CorePondContext context)? initialCoreComponents,
List<RepositoryImplementation> Function(CorePondContext context)? repositoryImplementations,
List<AuthServiceImplementation> Function(CorePondContext context)? authServiceImplementations,
MessagingService? Function(CorePondContext context)? messagingService,
LoggerService? Function(CorePondContext context)? loggerService,
TaskRunner? Function(CorePondContext context)? taskRunner,
}) async {
final corePondContext = CorePondContext();
await corePondContext.register(FloodCoreComponent(
environmentConfig: environmentConfig,
initialCoreComponents: initialCoreComponents,
repositoryImplementations: repositoryImplementations,
authServiceImplementations: authServiceImplementations,
actionWrapper: <P, R>(action) => action.log(context: corePondContext),
authService: (context) => AuthService.static.adapting(memoryIsAdmin: true),
taskRunner: taskRunner,
loggerService: loggerService,
messagingService: messagingService,
));
await corePondContext.register(UserDeviceTokenCoreComponent(
onRegisterDeviceToken: (dropContext, userId, deviceToken) async {
final userEntity = await Query.getByIdOrNull<UserEntity>(userId).get(dropContext);
if (userEntity == null) {
return;
}
await dropContext.updateEntity(userEntity, (User user) => user..deviceTokenProperty.set(deviceToken));
},
onRemoveDeviceToken: (dropContext, userId, deviceToken) async {
final userEntity = await Query.getByIdOrNull<UserEntity>(userId).get(dropContext);
if (userEntity == null) {
return;
}
await dropContext.updateEntity(userEntity, (User user) => user..deviceTokenProperty.set(null));
},
));
await corePondContext.register(UserRepository());
await corePondContext.register(TodoRepository());
return corePondContext;
}
Future<CorePondContext> getTestingCorePondContext() async {
final corePondContext = await getCorePondContext(
environmentConfig: EnvironmentConfig.static.testing(),
);
await corePondContext
.locate<AuthCoreComponent>()
.signup(AuthCredentials.email(email: 'asdf@asdf.com', password: 'mypassword'));
return corePondContext;
}