| Name | Type | Description |
|---|---|---|
options |
Object |
Properties to be assigned to the BaseObject. Must match the keys of the
BaseObject's |
Members
-
The class name. Minification will break
this.constructor.name; this allows for readable logging even in minified code.
Methods
-
BaseObject.buildFromServer (data, constructorParams)BaseObject static
-
Returns a new instance of the BaseObject populated with the passed data that came from ESPN, mapping the attributes defined in the value of responseMap to the matching key. Use this method when constructing BaseObjects with server responses.
Name Type Description dataObject Data originating from the server.
constructorParamsObject Params to be passed to the instance's constructor. Useful for passing parent data, such as
leagueId.Returns:
Type Description BaseObject A new instance of the BaseObject populated with the passed data.
Type Definitions
-
The
responseMapcan have two values: a string or a ResponseMapValueObject. When string, the data found on that response is directly mapped to the BaseObject without mutation. When ResponseMapValueObject, the data at thekeywill be used to create BaseObject(s) or manually parsed with a providedmanualParse function. Either result is attached to the BaseObject being populated.Properties:
Name Type Description keyString The key on the response data where the data can be found. This must be defined.
BaseObjectBaseObject The BaseObject to create with the response data.
isArrayBoolean Whether or not the response data is an array. Useful for attributes such as "teams".
deferBoolean Whether or not to wait to parse the entry until a second pass of the map. This is useful for populating items with cached instances that are not guaranteed to be parsed/cached during initial parsing. Example: Using Team instances on League.
manualParsefunction A function to manually apply logic to the response. This function must return its result to be attached to the populated BaseObject. The arguments to this function are: (data at the key), (the whole response), (the instance being populated).
Example
static responseMap = { teamId: 'teamId', team: { key: 'team_on_response', BaseObject: true }, teams: { key: 'teams_on_response', BaseObject: Team, isArray: true }, manualTeams: { key: 'manual_teams_on_response', BaseObject: Team, manualParse: (responseData, response, constructorParams, instance) => ( Team.buildFromServer(responseData) ) } };