OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 cr.define('bookmarks', function() { | |
6 var TestStore = function(data) { | |
7 this.data = Object.assign(bookmarks.util.createEmptyState(), data); | |
8 this.actions_ = []; | |
9 this.observers_ = []; | |
10 }; | |
11 | |
12 TestStore.prototype = { | |
13 addObserver: function(client) { | |
14 this.observers_.push(client); | |
15 }, | |
16 | |
17 removeObserver: function(client) {}, | |
18 | |
19 isInitialized: function() { | |
20 return true; | |
21 }, | |
22 | |
23 handleAction: function(action) { | |
24 this.actions_.push(action); | |
calamity
2017/03/09 04:58:57
Is this stack for multi-action UI interactions?
tsergeant
2017/03/09 06:27:55
That's the idea. Nothing ended up needing it, thou
| |
25 }, | |
26 | |
27 get lastAction() { | |
28 return this.actions_[this.actions_.length - 1]; | |
29 }, | |
30 | |
31 notifyObservers: function() { | |
32 // For simplicity, we don't want tests to have to worry about modifying | |
33 // the whole state tree when they want to change a single property. An | |
34 // alternative is to perform a deep clone in here. | |
35 this.observers_.forEach((client) => client.onStateChanged(this.data)); | |
calamity
2017/03/09 04:58:57
This might want to explain why a deep copy may be
tsergeant
2017/03/09 06:27:55
Reworded as a TODO. WDYT?
calamity
2017/03/10 03:34:21
Sounds good.
| |
36 }, | |
37 }; | |
38 | |
39 return { | |
40 TestStore: TestStore, | |
41 }; | |
42 }); | |
OLD | NEW |