
Previously, nested components (that are never standalone) were making their own requests for comments, creating unecessary duplicate API requests. Some requests were made to the rest API directly (for example, gr-change-view requested comments this way), and some were through the gr-comment-api, which also helped handle comment manipulation and reorganization. Instead of ad-hoc comment requesting, move all comment requests to the top level (standalone) component, and use an object prototype to generate _changeComments as a property on gr-comment-api. This is an immutable object that can be passed to the inner components (file list, etc), and includes the methods needed to manipulate comments into the forms necessary. When a child component needs to trigger a refresh of the comments, fire an event that the parent event handles (see gr-file-list l.867). Bug: Issue 6953 Change-Id: Ic4b6cf16520baae65d8cf956c311a60f2a70a2e1
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
// Copyright (C) 2017 The Android Open Source Project
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
(function() {
|
|
'use strict';
|
|
|
|
Polymer({
|
|
is: 'comment-api-mock',
|
|
|
|
properties: {
|
|
_changeComments: Object,
|
|
},
|
|
|
|
loadComments() {
|
|
return this._reloadComments();
|
|
},
|
|
|
|
_reloadCommentsWithCallback(e) {
|
|
return this._reloadComments().then(() => {
|
|
return e.detail.resolve();
|
|
});
|
|
},
|
|
|
|
_reloadComments() {
|
|
return this.$.commentAPI.loadAll(this._changeNum)
|
|
.then(comments => {
|
|
this._changeComments = this.$.commentAPI._changeComments;
|
|
});
|
|
},
|
|
});
|
|
})();
|