-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.dart
More file actions
28 lines (22 loc) · 841 Bytes
/
Copy pathapplication.dart
File metadata and controls
28 lines (22 loc) · 841 Bytes
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
library seaside.application;
import 'package:shelf/shelf.dart';
import 'component.dart';
import 'keys.dart';
import 'session.dart';
/// Constructs the root component from the initial request.
typedef ComponentFactory = Component Function(Request initialRequest);
/// The starting point of a Seaside application.
class Application {
final Map<String, Session> _sessions = {};
final ComponentFactory _componentFactory;
Application(this._componentFactory);
/// Handles the creation and dispatching to sessions.
Response call(Request request) {
var sessionKey = request.requestedUri.queryParameters[sessionParam];
if (!_sessions.containsKey(sessionKey)) {
_sessions[sessionKey = createSessionKey()] =
Session(sessionKey, _componentFactory(request));
}
return _sessions[sessionKey](request);
}
}