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

Side by Side Diff: lib/observe/html.dart

Issue 12225039: Support for observable models, fixes #259 (Closed) Base URL: https://github.com/dart-lang/web-ui.git@master
Patch Set: small formatting fixes Created 7 years, 10 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
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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
5 // TODO(jmesserly): can we handle this better? This seems like an unforunate
Siggi Cherem (dart-lang) 2013/02/13 01:43:24 nit: unforunate -> unfor[t]unate
Jennifer Messerly 2013/02/13 05:43:15 What an unforunate typo!
6 // limitation of our read barriers.
Siggi Cherem (dart-lang) 2013/02/13 01:43:24 I guess there is the general problem of handling n
Jennifer Messerly 2013/02/13 05:43:15 yeah, I dunno. Mostly we aren't observing the DOM
7
8 /** Helpers for exposing dart:html as observable data. */
9 library web_ui.observe.html;
10
11 import 'dart:html';
12 import 'package:web_ui/observe.dart';
13
14 ObservableReference<String> _hash;
15
16 /** An observable version of [window.location.hash]. */
17 String get locationHash {
18 if (_hash == null) {
19 _hash = new ObservableReference(window.location.hash);
20
21 window.onHashChange.listen(_updateLocationHash);
22 window.onPopState.listen(_updateLocationHash);
23 }
24
25 return _hash.value;
26 }
27
28 /** Pushes a new URL state, similar to the affect of clicking a link. */
29 set locationHash(String value) {
30 window.history.pushState(null, '', value);
31 _updateLocationHash(null);
32 }
33
34
35 // listen on changes to #hash in the URL
36 // Note: listen on both popState and hashChange, because IE9 doesnh't support
37 // history API, and it doesn't work properly on Opera 12.
38 // See http://dartbug.com/5483
39 _updateLocationHash(_) {
40 if (_hash != null) {
41 _hash.value = window.location.hash;
42 }
43 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698