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

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: 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
« no previous file with comments | « lib/observe.dart ('k') | lib/observe/list.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 unfortunate
6 // limitation of our read barriers.
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 /**
29 * Pushes a new URL state, similar to the affect of clicking a link.
30 * Has no effect if the [value] already equals [window.location.hash].
31 */
32 set locationHash(String value) {
33 if (value == window.location.hash) return;
34
35 window.history.pushState(const {}, '', value);
36 _updateLocationHash(null);
37 }
38
39
40 // listen on changes to #hash in the URL
41 // Note: listen on both popState and hashChange, because IE9 doesnh't support
42 // history API, and it doesn't work properly on Opera 12.
43 // See http://dartbug.com/5483
44 _updateLocationHash(_) {
45 if (_hash != null) {
46 _hash.value = window.location.hash;
47 }
48 }
OLDNEW
« no previous file with comments | « lib/observe.dart ('k') | lib/observe/list.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698