| OLD | NEW |
| 1 <!-- | 1 <!-- |
| 2 // Copyright 2014 The Chromium Authors. All rights reserved. | 2 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 5 --> | 5 --> |
| 6 | 6 |
| 7 <script> | 7 <script> |
| 8 function detectEval() { | 8 function detectEval() { |
| 9 // Don't test for eval if we're running in a Chrome App environment. | 9 // Don't test for eval if we're running in a Chrome App environment. |
| 10 // We check for APIs set that only exist in a Chrome App context. | 10 // We check for APIs set that only exist in a Chrome App context. |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 if (this.state_ != UNOPENED) | 594 if (this.state_ != UNOPENED) |
| 595 throw Error('Observer has already been opened.'); | 595 throw Error('Observer has already been opened.'); |
| 596 | 596 |
| 597 this.callback_ = callback; | 597 this.callback_ = callback; |
| 598 this.target_ = target; | 598 this.target_ = target; |
| 599 this.connect_(); | 599 this.connect_(); |
| 600 this.state_ = OPENED; | 600 this.state_ = OPENED; |
| 601 return this.value_; | 601 return this.value_; |
| 602 }, | 602 }, |
| 603 | 603 |
| 604 setValue: function(newValue) { |
| 605 }, |
| 606 |
| 604 close: function() { | 607 close: function() { |
| 605 if (this.state_ != OPENED) | 608 if (this.state_ != OPENED) |
| 606 return; | 609 return; |
| 607 | 610 |
| 608 this.disconnect_(); | 611 this.disconnect_(); |
| 609 this.value_ = undefined; | 612 this.value_ = undefined; |
| 610 this.callback_ = undefined; | 613 this.callback_ = undefined; |
| 611 this.target_ = undefined; | 614 this.target_ = undefined; |
| 612 this.state_ = CLOSED; | 615 this.state_ = CLOSED; |
| 613 }, | 616 }, |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 | 883 |
| 881 // TODO(rafaelw): Having observed_ as the third callback arg here is | 884 // TODO(rafaelw): Having observed_ as the third callback arg here is |
| 882 // pretty lame API. Fix. | 885 // pretty lame API. Fix. |
| 883 this.report_([this.value_, oldValues, this.observed_]); | 886 this.report_([this.value_, oldValues, this.observed_]); |
| 884 return true; | 887 return true; |
| 885 } | 888 } |
| 886 }); | 889 }); |
| 887 | 890 |
| 888 function identFn(value) { return value; } | 891 function identFn(value) { return value; } |
| 889 | 892 |
| 890 function ObserverTransform(observable, getValueFn, setValueFn, | 893 function ObserverTransform(observable, getValueFn) { |
| 891 dontPassThroughSet) { | |
| 892 this.callback_ = undefined; | 894 this.callback_ = undefined; |
| 893 this.target_ = undefined; | 895 this.target_ = undefined; |
| 894 this.value_ = undefined; | 896 this.value_ = undefined; |
| 895 this.observable_ = observable; | 897 this.observable_ = observable; |
| 896 this.getValueFn_ = getValueFn || identFn; | 898 this.getValueFn_ = getValueFn || identFn; |
| 897 this.setValueFn_ = setValueFn || identFn; | |
| 898 // TODO(rafaelw): This is a temporary hack. PolymerExpressions needs this | |
| 899 // at the moment because of a bug in it's dependency tracking. | |
| 900 this.dontPassThroughSet_ = dontPassThroughSet; | |
| 901 } | 899 } |
| 902 | 900 |
| 903 ObserverTransform.prototype = { | 901 ObserverTransform.prototype = { |
| 904 open: function(callback, target) { | 902 open: function(callback, target) { |
| 905 this.callback_ = callback; | 903 this.callback_ = callback; |
| 906 this.target_ = target; | 904 this.target_ = target; |
| 907 this.value_ = | 905 this.value_ = |
| 908 this.getValueFn_(this.observable_.open(this.observedCallback_, this)); | 906 this.getValueFn_(this.observable_.open(this.observedCallback_, this)); |
| 909 return this.value_; | 907 return this.value_; |
| 910 }, | 908 }, |
| 911 | 909 |
| 912 observedCallback_: function(value) { | 910 observedCallback_: function(value) { |
| 913 value = this.getValueFn_(value); | 911 value = this.getValueFn_(value); |
| 914 if (areSameValue(value, this.value_)) | 912 if (areSameValue(value, this.value_)) |
| 915 return; | 913 return; |
| 916 var oldValue = this.value_; | 914 var oldValue = this.value_; |
| 917 this.value_ = value; | 915 this.value_ = value; |
| 918 this.callback_.call(this.target_, this.value_, oldValue); | 916 this.callback_.call(this.target_, this.value_, oldValue); |
| 919 }, | 917 }, |
| 920 | 918 |
| 919 setValue: function(oldValue) { |
| 920 }, |
| 921 |
| 921 discardChanges: function() { | 922 discardChanges: function() { |
| 922 this.value_ = this.getValueFn_(this.observable_.discardChanges()); | 923 this.value_ = this.getValueFn_(this.observable_.discardChanges()); |
| 923 return this.value_; | 924 return this.value_; |
| 924 }, | 925 }, |
| 925 | 926 |
| 926 deliver: function() { | 927 deliver: function() { |
| 927 return this.observable_.deliver(); | 928 return this.observable_.deliver(); |
| 928 }, | 929 }, |
| 929 | 930 |
| 930 setValue: function(value) { | |
| 931 value = this.setValueFn_(value); | |
| 932 if (!this.dontPassThroughSet_ && this.observable_.setValue) | |
| 933 return this.observable_.setValue(value); | |
| 934 }, | |
| 935 | |
| 936 close: function() { | 931 close: function() { |
| 937 if (this.observable_) | 932 if (this.observable_) |
| 938 this.observable_.close(); | 933 this.observable_.close(); |
| 939 this.callback_ = undefined; | 934 this.callback_ = undefined; |
| 940 this.target_ = undefined; | 935 this.target_ = undefined; |
| 941 this.observable_ = undefined; | 936 this.observable_ = undefined; |
| 942 this.value_ = undefined; | 937 this.value_ = undefined; |
| 943 this.getValueFn_ = undefined; | 938 this.getValueFn_ = undefined; |
| 944 this.setValueFn_ = undefined; | |
| 945 } | 939 } |
| 946 } | 940 } |
| 947 | 941 |
| 948 function newSplice(index, removed, addedCount) { | 942 function newSplice(index, removed, addedCount) { |
| 949 return { | 943 return { |
| 950 index: index, | 944 index: index, |
| 951 removed: removed, | 945 removed: removed, |
| 952 addedCount: addedCount | 946 addedCount: addedCount |
| 953 }; | 947 }; |
| 954 } | 948 } |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 runEOM_: runEOM, | 1352 runEOM_: runEOM, |
| 1359 observerSentinel_: observerSentinel, | 1353 observerSentinel_: observerSentinel, |
| 1360 PathObserver: PathObserver, | 1354 PathObserver: PathObserver, |
| 1361 ArrayObserver: ArrayObserver, | 1355 ArrayObserver: ArrayObserver, |
| 1362 ArraySplice: ArraySplice, | 1356 ArraySplice: ArraySplice, |
| 1363 CompoundObserver: CompoundObserver, | 1357 CompoundObserver: CompoundObserver, |
| 1364 Path: Path, | 1358 Path: Path, |
| 1365 ObserverTransform: ObserverTransform | 1359 ObserverTransform: ObserverTransform |
| 1366 } | 1360 } |
| 1367 </script> | 1361 </script> |
| OLD | NEW |