OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 library pop_pop_win.platform_target; | |
5 | |
6 import 'dart:async'; | |
7 | |
8 abstract class PlatformTarget { | |
9 bool _initialized = false; | |
10 | |
11 factory PlatformTarget() => new _DefaultPlatform(); | |
12 | |
13 PlatformTarget.base(); | |
14 | |
15 bool get initialized => _initialized; | |
16 | |
17 void initialize() { | |
18 assert(!_initialized); | |
19 _initialized = true; | |
20 } | |
21 | |
22 Future clearValues(); | |
23 | |
24 Future setValue(String key, String value); | |
25 | |
26 Future<String> getValue(String key); | |
27 | |
28 int get size; | |
29 | |
30 bool get showAbout; | |
31 | |
32 void toggleAbout([bool value]); | |
33 | |
34 Stream get aboutChanged; | |
35 } | |
36 | |
37 class _DefaultPlatform extends PlatformTarget { | |
38 final Map<String, String> _values = new Map<String, String>(); | |
39 final StreamController _aboutController = new StreamController(sync: true); | |
40 bool _about = false; | |
41 | |
42 _DefaultPlatform() : super.base(); | |
43 | |
44 @override | |
45 Future clearValues() => new Future(_values.clear); | |
46 | |
47 @override | |
48 Future setValue(String key, String value) => | |
49 new Future(() { _values[key] = value; }); | |
50 | |
51 @override | |
52 Future<String> getValue(String key) => new Future(() => _values[key]); | |
53 | |
54 int get size => 7; | |
55 | |
56 void toggleAbout([bool value]) { | |
57 assert(_about != null); | |
58 if (value == null) { | |
59 value = !_about; | |
60 } | |
61 _about = value; | |
62 _aboutController.add(null); | |
63 } | |
64 | |
65 bool get showAbout => _about; | |
66 | |
67 Stream get aboutChanged => _aboutController.stream; | |
68 } | |
OLD | NEW |