-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.dart
35 lines (30 loc) · 1.15 KB
/
session.dart
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
library seaside.session;
import 'package:shelf/shelf.dart';
import 'component.dart';
import 'continuation.dart';
import 'keys.dart';
/// User session persistent as long as the user is interacting with it.
class Session {
final String sessionKey;
final Map<String, Continuation> _continuations = {};
final Component component;
Session(this.sessionKey, this.component);
/// Handles the creation and resolution of continuations, including the
/// rendering of the response using the root component.
Response call(Request request) {
_continuations[request.requestedUri.queryParameters[continuationParam]]
?.call(request);
final continuationKey = createContinuationKey();
final continuation = Continuation(sessionKey, continuationKey, component);
_continuations[continuationKey] = continuation;
final headContents =
component.withAllChildren.map((component) => component.head).join();
final bodyContents = component.body(continuation);
return Response.ok('''
<html>
<head>$headContents</head>
<body>$bodyContents</body>
</html>
''', headers: {'Content-Type': 'text/html'});
}
}