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

Side by Side Diff: lib/observe/reference.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/map.dart ('k') | lib/observe/set.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 library web_ui.observe.reference;
6
7 import 'package:web_ui/observe.dart';
8
9 /**
10 * An observable reference to an value. Use this if you want to store a single
11 * value. NOTE: it is generally better to use the `@observable` annotation on
12 * your observable class. This class is provided for demonstration purposes, or
13 * if you happen to need a single unnamed observable reference.
14 */
15 class ObservableReference<T> {
16 Object _observers;
17 T _value;
18
19 ObservableReference([T initialValue]) : _value = initialValue;
20
21 T get value {
22 if (observeReads) _observers = notifyRead(_observers);
23 return _value;
24 }
25
26 void set value(T newValue) {
27 if (_observers != null && _value != newValue) {
28 _observers = notifyWrite(_observers);
29 }
30 _value = newValue;
31 }
32 }
OLDNEW
« no previous file with comments | « lib/observe/map.dart ('k') | lib/observe/set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698