OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 Polymer({ | 5 Polymer({ |
6 is: 'bookmarks-folder-node', | 6 is: 'bookmarks-folder-node', |
7 | 7 |
8 behaviors: [ | |
9 bookmarks.StoreClient, | |
10 ], | |
11 | |
8 properties: { | 12 properties: { |
9 /** @type {BookmarkTreeNode} */ | 13 itemId: { |
10 item: Object, | 14 type: String, |
15 observer: 'updateFromStore', | |
16 }, | |
11 | 17 |
12 isSelectedFolder: { | 18 /** @type {BookmarkNode} */ |
19 item_: Object, | |
20 | |
21 /** @private */ | |
22 isClosed_: Boolean, | |
23 | |
24 /** @private */ | |
25 selectedFolder_: String, | |
26 | |
27 /** @private */ | |
28 isSelectedFolder_: { | |
13 type: Boolean, | 29 type: Boolean, |
14 value: false, | 30 value: false, |
15 reflectToAttribute: true, | 31 reflectToAttribute: true, |
32 computed: 'computeIsSelected_(itemId, selectedFolder_)' | |
16 }, | 33 }, |
17 }, | 34 }, |
18 | 35 |
36 attached: function() { | |
37 this.watch('item_', function(state) { | |
38 return state.nodes[this.itemId]; | |
39 }.bind(this)); | |
40 this.watch('isClosed_', function(state) { | |
41 return !!state.closedFolders[this.itemId]; | |
42 }.bind(this)); | |
43 this.watch('selectedFolder_', function(state) { | |
44 return state.selectedFolder; | |
45 }); | |
46 | |
47 this.updateFromStore(); | |
48 }, | |
49 | |
19 /** | 50 /** |
20 * @private | 51 * @private |
21 * @return {string} | 52 * @return {string} |
22 */ | 53 */ |
23 getFolderIcon_: function() { | 54 getFolderIcon_: function() { |
24 return this.isSelectedFolder ? 'bookmarks:folder-open' : 'cr:folder'; | 55 return this.isSelectedFolder_ ? 'bookmarks:folder-open' : 'cr:folder'; |
25 }, | 56 }, |
26 | 57 |
27 /** | 58 /** |
28 * @private | 59 * @private |
29 * @return {string} | 60 * @return {string} |
30 */ | 61 */ |
31 getArrowIcon_: function() { | 62 getArrowIcon_: function() { |
32 return this.item.isOpen ? 'cr:arrow-drop-up' : 'cr:arrow-drop-down'; | 63 return this.isClosed_ ? 'cr:arrow-drop-down' : 'cr:arrow-drop-up'; |
33 }, | 64 }, |
34 | 65 |
35 /** @private */ | 66 /** @private */ |
36 selectFolder_: function() { | 67 selectFolder_: function() { |
37 this.fire('selected-folder-changed', this.item.id); | 68 this.dispatch(bookmarks.actions.selectFolder(this.item_.id)); |
38 }, | 69 }, |
39 | 70 |
40 /** | 71 /** |
41 * Occurs when the drop down arrow is tapped. | 72 * Occurs when the drop down arrow is tapped. |
42 * @private | 73 * @private |
43 */ | 74 */ |
44 toggleFolder_: function() { | 75 toggleFolder_: function() { |
45 this.fire('folder-open-changed', { | 76 this.dispatch( |
46 id: this.item.id, | 77 bookmarks.actions.changeFolderOpen(this.item_.id, this.isClosed_)); |
47 open: !this.item.isOpen, | |
48 }); | |
49 }, | 78 }, |
50 | 79 |
51 /** | 80 /** |
81 * @param {string} itemId | |
82 * @param {string} selectedFolder | |
83 * @return {boolean} | |
84 * @private | |
85 */ | |
86 computeIsSelected_: function(itemId, selectedFolder) { | |
87 return itemId == selectedFolder; | |
88 }, | |
89 | |
90 /** | |
52 * @private | 91 * @private |
53 * @return {boolean} | 92 * @return {boolean} |
54 */ | 93 */ |
55 hasChildFolder_: function() { | 94 hasChildFolder_: function() { |
56 for (var i = 0; i < this.item.children.length; i++) { | 95 for (var i = 0; i < this.item_.children.length; i++) { |
57 if (!this.item.children[i].url) | 96 var child = this.getState().nodes[this.item_.children[i]]; |
97 if (!child.url) | |
58 return true; | 98 return true; |
59 } | 99 } |
60 return false; | 100 return false; |
61 }, | 101 }, |
62 | 102 |
63 /** | 103 /** |
64 * @param {BookmarkTreeNode} item | 104 * @param {string} itemId |
65 * @private | 105 * @private |
66 * @return {boolean} | 106 * @return {boolean} |
67 */ | 107 */ |
68 isFolder_: function(item) { | 108 isFolder_: function(itemId) { |
69 return !item.url; | 109 return !this.getState().nodes[itemId].url; |
70 } | 110 } |
calamity
2017/03/09 04:58:57
It's weird that this essentially does the same thi
tsergeant
2017/03/09 06:27:54
This actually caught me out earlier ('why do we ha
| |
71 }); | 111 }); |
OLD | NEW |