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 suiteSetup(function() { | 5 suiteSetup(function() { |
6 cr.define('bookmarks', function() { | 6 cr.define('bookmarks', function() { |
7 var TestStore = function(data) { | 7 var TestStore = function(data) { |
8 bookmarks.Store.call(this); | 8 bookmarks.Store.call(this); |
9 this.data_ = Object.assign(bookmarks.util.createEmptyState(), data); | 9 this.data_ = Object.assign(bookmarks.util.createEmptyState(), data); |
10 this.initialized_ = true; | 10 this.initialized_ = true; |
11 | 11 |
12 this.lastAction_ = null; | 12 this.lastAction_ = null; |
13 this.acceptInit_ = false; | 13 this.acceptInit_ = false; |
14 this.enableReducers_ = false; | 14 this.enableReducers_ = false; |
15 /** @type {!Map<string, !PromiseResolver>} */ | 15 /** @type {!Map<string, !PromiseResolver>} */ |
16 this.resolverMap_ = new Map(); | 16 this.resolverMap_ = new Map(); |
17 }; | 17 }; |
18 | 18 |
19 TestStore.prototype = { | 19 TestStore.prototype = { |
20 __proto__: bookmarks.Store.prototype, | 20 __proto__: bookmarks.Store.prototype, |
21 | 21 |
| 22 /** @override */ |
22 init: function(state) { | 23 init: function(state) { |
23 if (this.acceptInit_) | 24 if (this.acceptInit_) |
24 bookmarks.Store.prototype.init.call(this, state); | 25 bookmarks.Store.prototype.init.call(this, state); |
25 }, | 26 }, |
26 | 27 |
27 get lastAction() { | 28 get lastAction() { |
28 return this.lastAction_; | 29 return this.lastAction_; |
29 }, | 30 }, |
30 | 31 |
31 resetLastAction() { | 32 resetLastAction() { |
(...skipping 18 matching lines...) Expand all Loading... |
50 * With reducers disabled (the default), TestStore is a stub which | 51 * With reducers disabled (the default), TestStore is a stub which |
51 * requires state be managed manually (suitable for unit tests). With | 52 * requires state be managed manually (suitable for unit tests). With |
52 * reducers enabled, TestStore becomes a proxy for observing actions | 53 * reducers enabled, TestStore becomes a proxy for observing actions |
53 * (suitable for integration tests). | 54 * (suitable for integration tests). |
54 * @param {boolean} enabled | 55 * @param {boolean} enabled |
55 */ | 56 */ |
56 setReducersEnabled: function(enabled) { | 57 setReducersEnabled: function(enabled) { |
57 this.enableReducers_ = enabled; | 58 this.enableReducers_ = enabled; |
58 }, | 59 }, |
59 | 60 |
| 61 /** @override */ |
60 reduce_: function(action) { | 62 reduce_: function(action) { |
61 this.lastAction_ = action; | 63 this.lastAction_ = action; |
62 if (this.enableReducers_) | 64 if (this.enableReducers_) |
63 bookmarks.Store.prototype.reduce_.call(this, action); | 65 bookmarks.Store.prototype.reduce_.call(this, action); |
64 if (this.resolverMap_.has(action.name)) | 66 if (this.resolverMap_.has(action.name)) |
65 this.resolverMap_.get(action.name).resolve(action); | 67 this.resolverMap_.get(action.name).resolve(action); |
66 }, | 68 }, |
67 | 69 |
68 /** | 70 /** |
69 * Notifies UI elements that the store data has changed. When reducers are | 71 * Notifies UI elements that the store data has changed. When reducers are |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 return action; | 108 return action; |
107 }); | 109 }); |
108 }, | 110 }, |
109 }; | 111 }; |
110 | 112 |
111 return { | 113 return { |
112 TestStore: TestStore, | 114 TestStore: TestStore, |
113 }; | 115 }; |
114 }); | 116 }); |
115 }); | 117 }); |
OLD | NEW |