OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Defines StoreClient, a Polymer behavior to tie a front-end | 6 * @fileoverview Defines StoreClient, a Polymer behavior to tie a front-end |
7 * element to back-end data from the store. | 7 * element to back-end data from the store. |
8 */ | 8 */ |
9 | 9 |
10 cr.define('bookmarks', function() { | 10 cr.define('bookmarks', function() { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 | 79 |
80 /** @param {string} newState */ | 80 /** @param {string} newState */ |
81 onStateChanged: function(newState) { | 81 onStateChanged: function(newState) { |
82 this.watches_.forEach(function(watch) { | 82 this.watches_.forEach(function(watch) { |
83 var oldValue = this[watch.localProperty]; | 83 var oldValue = this[watch.localProperty]; |
84 var newValue = watch.valueGetter(newState); | 84 var newValue = watch.valueGetter(newState); |
85 | 85 |
86 // Avoid poking Polymer unless something has actually changed. Reducers | 86 // Avoid poking Polymer unless something has actually changed. Reducers |
87 // must return new objects rather than mutating existing objects, so | 87 // must return new objects rather than mutating existing objects, so |
88 // any real changes will pass through correctly. | 88 // any real changes will pass through correctly. |
89 if (oldValue == newValue || newValue == undefined) | 89 if (oldValue == newValue || newValue === undefined) |
90 return; | 90 return; |
91 | 91 |
92 this[watch.localProperty] = newValue; | 92 this[watch.localProperty] = newValue; |
93 }.bind(this)); | 93 }.bind(this)); |
94 }, | 94 }, |
95 | 95 |
96 updateFromStore: function() { | 96 updateFromStore: function() { |
97 if (bookmarks.Store.getInstance().isInitialized()) | 97 if (bookmarks.Store.getInstance().isInitialized()) |
98 this.onStateChanged(bookmarks.Store.getInstance().data); | 98 this.onStateChanged(bookmarks.Store.getInstance().data); |
99 }, | 99 }, |
100 | 100 |
101 /** @return {!BookmarksPageState} */ | 101 /** @return {!BookmarksPageState} */ |
102 getState: function() { | 102 getState: function() { |
103 return bookmarks.Store.getInstance().data; | 103 return bookmarks.Store.getInstance().data; |
104 }, | 104 }, |
105 }; | 105 }; |
106 | 106 |
107 return { | 107 return { |
108 StoreClient: StoreClient, | 108 StoreClient: StoreClient, |
109 }; | 109 }; |
110 }); | 110 }); |
OLD | NEW |