Ember.DataAdapter Class
The DataAdapter
helps a data persistence library
interface with tools that debug Ember such
as the Ember Extension
for Chrome and Firefox.
This class will be extended by a persistence library which will override some of the methods with library-specific code.
The methods likely to be overridden are:
getFilters
detect
columnsForType
getRecords
getRecordColumnValues
getRecordKeywords
getRecordFilterValues
getRecordColor
observeRecord
The adapter will need to be registered
in the application's container as dataAdapter:main
Example:
Application.initializer({
name: "data-adapter",
initialize: function(container, application) {
application.register('data-adapter:main', DS.DataAdapter);
}
});
Item Index
Methods
Methods
_getObjectsOnNamespaces
()
Array
private
Loops over all namespaces and all objects attached to them
Returns:
Array of model type strings
columnsForType
-
type
Get the columns for a given model type.
Parameters:
-
type
ClassThe model type
Returns:
An array of columns of the following format: name: {String} name of the column desc: {String} Humanized description (what would show in a table column name)
detect
-
klass
Detect whether a class is a model.
Test that against the model class of your persistence library
Parameters:
-
klass
ClassThe class to test
Returns:
boolean Whether the class is a model class or not
getFilters
()
Array
public
Specifies how records can be filtered.
Records returned will need to have a filterValues
property with a key for every name in the returned array.
Returns:
List of objects defining filters.
The object should have a name
and desc
property.
getModelTypes
()
Array
private
Fetches all models defined in the application.
Returns:
Array of model types
getRecordColor
-
record
Each record can have a color that represents its state.
Parameters:
-
record
ObjectThe record instance
Returns:
The record's color Possible options: black, red, blue, green
getRecordColumnValues
()
Object
private
Gets the values for each column.
Returns:
Keys should match column names defined by the model type.
getRecordFilterValues
-
record
Returns the values of filters defined by getFilters
.
Parameters:
-
record
ObjectThe record instance
Returns:
The filter values
getRecordKeywords
()
Array
private
Returns keywords to match when searching records.
Returns:
Relevant keywords for search.
getRecords
()
Array
private
Fetches all loaded records for a given type.
Returns:
An array of records. This array will be observed for changes, so it should update when new records are added/removed.
observeModelType
-
type
-
typesUpdated
Adds observers to a model type class.
Parameters:
-
type
ClassThe model type class
-
typesUpdated
FunctionCalled when a type is modified.
Returns:
The function to call to remove observers
observerRecord
-
record
-
recordUpdated
Observes all relevant properties and re-sends the wrapped record when a change occurs.
Parameters:
-
record
ObjectThe record instance
-
recordUpdated
FunctionThe callback to call when a record is updated.
Returns:
The function to call to remove all observers.
watchModelTypes
-
typesAdded
-
typesUpdated
Fetch the model types and observe them for changes.
Parameters:
Returns:
Method to call to remove all observers
watchRecords
-
recordsAdded
-
recordsUpdated
-
recordsRemoved
Fetch the records of a given type and observe them for changes.
Parameters:
-
recordsAdded
FunctionCallback to call to add records. Takes an array of objects containing wrapped records. The object should have the following properties: columnValues: {Object} key and value of a table cell object: {Object} the actual record object
-
recordsUpdated
FunctionCallback to call when a record has changed. Takes an array of objects containing wrapped records.
-
recordsRemoved
FunctionCallback to call when a record has removed. Takes the following parameters: index: the array index where the records were removed count: the number of records removed
Returns:
Method to call to remove all observers
willDestroy
()
private
Clear all observers before destruction
wrapModelType
-
type
-
Optional
Wraps a given model type and observes changes to it.
Parameters:
-
type
ClassA model class
-
Optional
Stringname of the class
Returns:
contains the wrapped type and the function to remove observers Format: type: {Object} the wrapped type The wrapped type has the following format: name: {String} name of the type count: {Integer} number of records available columns: {Columns} array of columns to describe the record object: {Class} the actual Model type class release: {Function} The function to remove observers
wrapRecord
-
record
Wraps a record and observers changes to it.
Parameters:
-
record
ObjectThe record instance.
Returns:
The wrapped record. Format: columnValues: {Array} searchKeywords: {Array}
Properties
attributeLimit
Unknown
private
Number of attributes to send as columns. (Enough to make the record identifiable).
Default: 3
container
Unknown
The container of the application being debugged. This property will be injected on creation.
Default: null
containerDebugAdapter
Unknown
The container-debug-adapter which is used to list all models.
Default: undefined
releaseMethods
Unknown
private
Stores all methods that clear observers. These methods will be called on destruction.