Skip to content

Commit

Permalink
[DOC debug-adapter]: Add comments for each method in debug-adapter (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
SYU15 authored and runspired committed Aug 20, 2019
1 parent 7c7ebdf commit bc7a0ec
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions packages/-ember-data/addon/-private/system/debug/debug-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ import Model from '@ember-data/model';
@private
*/
export default DataAdapter.extend({
/**
Specifies how records can be filtered based on the state of the record
Records returned will need to have a `filterValues`
property with a key for every name in the returned array
@public
@method getFilters
@return {Array} List of objects defining filters
The object should have a `name` and `desc` property
*/
getFilters() {
return [
{ name: 'isNew', desc: 'New' },
Expand All @@ -26,10 +35,24 @@ export default DataAdapter.extend({
];
},

/**
Detect whether a class is a DS.Model
@public
@method detect
@param {DS.Model} typeClass
@return {Boolean} Whether the typeClass is a DS.Model class or not
*/
detect(typeClass) {
return typeClass !== Model && Model.detect(typeClass);
},

/**
Creates a human readable string used for column headers
@public
@method columnNameToDesc
@param {String} name The attribute name
@return {String} Human readable string based on the attribute name
*/
columnNameToDesc(name) {
return capitalize(
underscore(name)
Expand All @@ -38,6 +61,15 @@ export default DataAdapter.extend({
);
},

/**
Get the columns for a given model type
@public
@method columnsForType
@param {DS.Model} typeClass
@return {Array} An array of columns of the following format:
name: {String} The name of the column
desc: {String} Humanized description (what would show in a table column name)
*/
columnsForType(typeClass) {
let columns = [
{
Expand All @@ -57,6 +89,16 @@ export default DataAdapter.extend({
return columns;
},

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

/**
Gets the values for each column
This is the attribute values for a given record
@public
@method getRecordColumnValues
@param {DS.Model} record to get values from
@return {Object} Keys should match column names defined by the model type
*/
getRecordColumnValues(record) {
let count = 0;
let columnValues = { id: get(record, 'id') };
Expand All @@ -85,6 +135,13 @@ export default DataAdapter.extend({
return columnValues;
},

/**
Returns keywords to match when searching records
@public
@method getRecordKeywords
@param {DS.Model} record
@return {Array} Relevant keywords for search based on the record's attribute values
*/
getRecordKeywords(record) {
let keywords = [];
let keys = A(['id']);
Expand All @@ -93,6 +150,14 @@ export default DataAdapter.extend({
return keywords;
},

/**
Returns the values of filters defined by `getFilters`
These reflect the state of the record
@public
@method getRecordFilterValues
@param {DS.Model} record
@return {Object} The record state filter values
*/
getRecordFilterValues(record) {
return {
isNew: record.get('isNew'),
Expand All @@ -101,6 +166,14 @@ export default DataAdapter.extend({
};
},

/**
Returns a color that represents the record's state
@public
@method getRecordColor
@param {DS.Model} record
@return {String} The record color
Possible options: black, blue, green
*/
getRecordColor(record) {
let color = 'black';
if (record.get('isNew')) {
Expand All @@ -111,6 +184,15 @@ export default DataAdapter.extend({
return color;
},

/**
Observes all relevant properties and re-sends the wrapped record
when a change occurs
@public
@method observerRecord
@param {DS.Model} record
@param {Function} recordUpdated Callback used to notify changes
@return {Function} The function to call to remove all observers
*/
observeRecord(record, recordUpdated) {
let releaseMethods = A();
let keysToObserve = A(['id', 'isNew', 'hasDirtyAttributes']);
Expand Down

0 comments on commit bc7a0ec

Please sign in to comment.