Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: samples/pop-pop-win/web/platform_web.dart

Issue 200723008: samples/poppopwin: upgrade to first-class sample (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 library ppw_platform_web; 1 library ppw_platform_web;
2 2
3 import 'dart:async'; 3 import 'dart:async';
4 import 'dart:html'; 4 import 'dart:html';
5 import 'dart:js' as js; 5 import 'dart:js' as js;
6 import 'package:poppopwin/platform_target.dart'; 6 import 'package:poppopwin/platform_target.dart';
7 7
8 class PlatformWeb extends PlatformTarget { 8 class PlatformWeb extends PlatformTarget {
9 static const String _BIG_HASH = '#big'; 9 static const String _BIG_HASH = '#big';
10 static const String _ABOUT_HASH = '#about'; 10 static const String _ABOUT_HASH = '#about';
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 js.context.callMethod('ga', args); 47 js.context.callMethod('ga', args);
48 } 48 }
49 49
50 bool get renderBig => _urlHash == _BIG_HASH; 50 bool get renderBig => _urlHash == _BIG_HASH;
51 51
52 bool get showAbout => _urlHash == _ABOUT_HASH; 52 bool get showAbout => _urlHash == _ABOUT_HASH;
53 53
54 Stream get aboutChanged => _aboutController.stream; 54 Stream get aboutChanged => _aboutController.stream;
55 55
56 void toggleAbout([bool value]) { 56 void toggleAbout([bool value]) {
57 final Location loc = window.location; 57 var loc = window.location;
58 // ensure we treat empty hash like '#', which makes comparison easy later 58 // ensure we treat empty hash like '#', which makes comparison easy later
59 final hash = loc.hash.length == 0 ? '#' : loc.hash; 59 var hash = loc.hash.length == 0 ? '#' : loc.hash;
60 60
61 final isOpen = hash == _ABOUT_HASH; 61 var isOpen = hash == _ABOUT_HASH;
62 if(value == null) { 62 if(value == null) {
63 // then toggle the current value 63 // then toggle the current value
64 value = !isOpen; 64 value = !isOpen;
65 } 65 }
66 66
67 var targetHash = value ? _ABOUT_HASH : '#'; 67 var targetHash = value ? _ABOUT_HASH : '#';
68 if(targetHash != hash) { 68 if(targetHash != hash) {
69 loc.assign(targetHash); 69 loc.assign(targetHash);
70 } 70 }
71 _aboutController.add(null); 71 _aboutController.add(null);
72 } 72 }
73 73
74 String get _urlHash => window.location.hash; 74 String get _urlHash => window.location.hash;
75 75
76 void _processUrlHash() { 76 void _processUrlHash() {
77 final Location loc = window.location; 77 var loc = window.location;
Jennifer Messerly 2014/03/19 01:06:54 fwiw, nothing wrong with using "final". It seems t
kevmoo 2014/03/19 03:24:06 Just trying to align w/ our general code guideline
Jennifer Messerly 2014/03/19 14:26:43 makes sense :)
78 final hash = loc.hash; 78 var hash = loc.hash;
79 final href = loc.href; 79 var href = loc.href;
80 80
81 final History history = window.history; 81 final History history = window.history;
82 switch(hash) { 82 switch(hash) {
83 case "#reset": 83 case "#reset":
84 assert(href.endsWith(hash)); 84 assert(href.endsWith(hash));
85 var newLoc = href.substring(0, href.length - hash.length); 85 var newLoc = href.substring(0, href.length - hash.length);
86 86
87 window.localStorage.clear(); 87 window.localStorage.clear();
88 88
89 loc.replace(newLoc); 89 loc.replace(newLoc);
90 break; 90 break;
91 case _BIG_HASH: 91 case _BIG_HASH:
92 loc.reload(); 92 if (!renderBig) loc.reload();
93 break; 93 break;
94 case _ABOUT_HASH: 94 case _ABOUT_HASH:
95 _aboutController.add(null); 95 _aboutController.add(null);
96 break; 96 break;
97 } 97 }
98 } 98 }
99 } 99 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698