Skip to content

Commit bc7a0ec

Browse files
SYU15runspired
authored andcommitted
[DOC debug-adapter]: Add comments for each method in debug-adapter (#6352)
1 parent 7c7ebdf commit bc7a0ec

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

packages/-ember-data/addon/-private/system/debug/debug-adapter.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ import Model from '@ember-data/model';
1818
@private
1919
*/
2020
export default DataAdapter.extend({
21+
/**
22+
Specifies how records can be filtered based on the state of the record
23+
Records returned will need to have a `filterValues`
24+
property with a key for every name in the returned array
25+
@public
26+
@method getFilters
27+
@return {Array} List of objects defining filters
28+
The object should have a `name` and `desc` property
29+
*/
2130
getFilters() {
2231
return [
2332
{ name: 'isNew', desc: 'New' },
@@ -26,10 +35,24 @@ export default DataAdapter.extend({
2635
];
2736
},
2837

38+
/**
39+
Detect whether a class is a DS.Model
40+
@public
41+
@method detect
42+
@param {DS.Model} typeClass
43+
@return {Boolean} Whether the typeClass is a DS.Model class or not
44+
*/
2945
detect(typeClass) {
3046
return typeClass !== Model && Model.detect(typeClass);
3147
},
3248

49+
/**
50+
Creates a human readable string used for column headers
51+
@public
52+
@method columnNameToDesc
53+
@param {String} name The attribute name
54+
@return {String} Human readable string based on the attribute name
55+
*/
3356
columnNameToDesc(name) {
3457
return capitalize(
3558
underscore(name)
@@ -38,6 +61,15 @@ export default DataAdapter.extend({
3861
);
3962
},
4063

64+
/**
65+
Get the columns for a given model type
66+
@public
67+
@method columnsForType
68+
@param {DS.Model} typeClass
69+
@return {Array} An array of columns of the following format:
70+
name: {String} The name of the column
71+
desc: {String} Humanized description (what would show in a table column name)
72+
*/
4173
columnsForType(typeClass) {
4274
let columns = [
4375
{
@@ -57,6 +89,16 @@ export default DataAdapter.extend({
5789
return columns;
5890
},
5991

92+
/**
93+
Fetches all loaded records for a given type
94+
@public
95+
@method getRecords
96+
@param {DS.Model} modelClass of the record
97+
@param {String} modelName of the record
98+
@return {Array} An array of DS.Model records
99+
This array will be observed for changes,
100+
so it should update when new records are added/removed
101+
*/
60102
getRecords(modelClass, modelName) {
61103
if (arguments.length < 2) {
62104
// Legacy Ember.js < 1.13 support
@@ -72,6 +114,14 @@ export default DataAdapter.extend({
72114
return this.get('store').peekAll(modelName);
73115
},
74116

117+
/**
118+
Gets the values for each column
119+
This is the attribute values for a given record
120+
@public
121+
@method getRecordColumnValues
122+
@param {DS.Model} record to get values from
123+
@return {Object} Keys should match column names defined by the model type
124+
*/
75125
getRecordColumnValues(record) {
76126
let count = 0;
77127
let columnValues = { id: get(record, 'id') };
@@ -85,6 +135,13 @@ export default DataAdapter.extend({
85135
return columnValues;
86136
},
87137

138+
/**
139+
Returns keywords to match when searching records
140+
@public
141+
@method getRecordKeywords
142+
@param {DS.Model} record
143+
@return {Array} Relevant keywords for search based on the record's attribute values
144+
*/
88145
getRecordKeywords(record) {
89146
let keywords = [];
90147
let keys = A(['id']);
@@ -93,6 +150,14 @@ export default DataAdapter.extend({
93150
return keywords;
94151
},
95152

153+
/**
154+
Returns the values of filters defined by `getFilters`
155+
These reflect the state of the record
156+
@public
157+
@method getRecordFilterValues
158+
@param {DS.Model} record
159+
@return {Object} The record state filter values
160+
*/
96161
getRecordFilterValues(record) {
97162
return {
98163
isNew: record.get('isNew'),
@@ -101,6 +166,14 @@ export default DataAdapter.extend({
101166
};
102167
},
103168

169+
/**
170+
Returns a color that represents the record's state
171+
@public
172+
@method getRecordColor
173+
@param {DS.Model} record
174+
@return {String} The record color
175+
Possible options: black, blue, green
176+
*/
104177
getRecordColor(record) {
105178
let color = 'black';
106179
if (record.get('isNew')) {
@@ -111,6 +184,15 @@ export default DataAdapter.extend({
111184
return color;
112185
},
113186

187+
/**
188+
Observes all relevant properties and re-sends the wrapped record
189+
when a change occurs
190+
@public
191+
@method observerRecord
192+
@param {DS.Model} record
193+
@param {Function} recordUpdated Callback used to notify changes
194+
@return {Function} The function to call to remove all observers
195+
*/
114196
observeRecord(record, recordUpdated) {
115197
let releaseMethods = A();
116198
let keysToObserve = A(['id', 'isNew', 'hasDirtyAttributes']);

0 commit comments

Comments
 (0)