| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 } | 55 } |
| 56 this.watches_.push({ | 56 this.watches_.push({ |
| 57 localProperty: localProperty, | 57 localProperty: localProperty, |
| 58 valueGetter: valueGetter, | 58 valueGetter: valueGetter, |
| 59 }); | 59 }); |
| 60 }, | 60 }, |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * Helper to dispatch an action to the store, which will update the store | 63 * Helper to dispatch an action to the store, which will update the store |
| 64 * data and then (possibly) flow through to the UI. | 64 * data and then (possibly) flow through to the UI. |
| 65 * @param {Action} action | 65 * @param {?Action} action |
| 66 */ | 66 */ |
| 67 dispatch: function(action) { | 67 dispatch: function(action) { |
| 68 bookmarks.Store.getInstance().handleAction(action); | 68 bookmarks.Store.getInstance().dispatch(action); |
| 69 }, |
| 70 |
| 71 /** |
| 72 * Helper to dispatch a DeferredAction to the store, which will |
| 73 * asynchronously perform updates to the store data and UI. |
| 74 * @param {DeferredAction} action |
| 75 */ |
| 76 dispatchAsync: function(action) { |
| 77 bookmarks.Store.getInstance().dispatchAsync(action); |
| 69 }, | 78 }, |
| 70 | 79 |
| 71 /** @param {string} newState */ | 80 /** @param {string} newState */ |
| 72 onStateChanged: function(newState) { | 81 onStateChanged: function(newState) { |
| 73 this.watches_.forEach(function(watch) { | 82 this.watches_.forEach(function(watch) { |
| 74 var oldValue = this[watch.localProperty]; | 83 var oldValue = this[watch.localProperty]; |
| 75 var newValue = watch.valueGetter(newState); | 84 var newValue = watch.valueGetter(newState); |
| 76 | 85 |
| 77 // Avoid poking Polymer unless something has actually changed. Reducers | 86 // Avoid poking Polymer unless something has actually changed. Reducers |
| 78 // must return new objects rather than mutating existing objects, so | 87 // must return new objects rather than mutating existing objects, so |
| (...skipping 13 matching lines...) Expand all Loading... |
| 92 /** @return {!BookmarksPageState} */ | 101 /** @return {!BookmarksPageState} */ |
| 93 getState: function() { | 102 getState: function() { |
| 94 return bookmarks.Store.getInstance().data; | 103 return bookmarks.Store.getInstance().data; |
| 95 }, | 104 }, |
| 96 }; | 105 }; |
| 97 | 106 |
| 98 return { | 107 return { |
| 99 StoreClient: StoreClient, | 108 StoreClient: StoreClient, |
| 100 }; | 109 }; |
| 101 }); | 110 }); |
| OLD | NEW |