Datasource

extends:
Jump To: Members Events

A GraphLoader that connects to a Thinkmap 2.9.2+ datasource

Instance Methods

Defined in Datasource:

Events

This request is fired when a related request is issued by the client for an entity. This is most typical event that is used for annotating requests between the server and the client as the related request serves as the most common request in Thinkmap. Here is an example of attaching some attributes the the related request before it is fired to the server: datasource.on('relatedrequest',function(entity, condition, rs, req) { if (!req.attributes) { req.attributes = {}; } req.attributes.minYearForMovies = minYear; })

entityrequest : function ( ( Object | thinkmap.graph.Entity | thinkmap.graph.Selection ) , Object )

Entity Requests are fired when the fetchEntity method of datasource is called. The first parameters is whatever was passed into the fetchEntity method and the second parameter is the request object itself

sendrequest : function ( Object )

this event is fired right before the datasource is about to me a request to a thinkmap server. This is fired on every type of request and is a low level api when compared to the related request and entity request events. The single parameter represents the message object that will be sent to the server and can be modified by any event listeners. This event is typically used to modify the request by adding custom attributes that the server may need to fulfill its request. //add an attribute to a request datasource.on('sendrequest',function(request) { // create the attributes object in case it isn't present if(!request.attributes) request.attributes = {}; request.attributes.userid = 'thinkmap-user'; request.attributes.timestamp = Date.now(); });

readresponse : function ( Object , Object )

this event is fired once the datasource receives the response from the thinkmap server. The first parameter is the response object from the server and the second paramter is the request fired from the client that generated the respoinse.

At the time the event is fired, the response has not been officially merged into the thinkmap client. Any event listeners on this event can therefore modify this response by adding/deleting entities, changing properties, etc before the response is officially turned into graph entities on the client.

relationsupdate : function ( Object )

this event is fired when the relationships (edges) of a node are invalidated and the datasource makes a new related request and the relations that come back are different from the ones that currently exist on the client. The single parameter is an object that has the following properties: entity - the node that has its related edges being fetched, newRelations: a selection that contains its current relations that just came back from the datasource, oldRelations: a selection of the old Relations of the entity (there can be an intersection between newRelations and oldRelations). // removes any relations in the graph that were not returned by the datasource //for the particular entity. This would only occur if datasource.invalidateRelations was called for the //particular entity datasource.on('relationsupdate', function(result) { var toRemove = result.newRelations.complement(result.oldRelations); graph.remove(toRemove); });

This is a sophisticated event that is typically used by applications that have server side data stores that are constantly updating and the relationships of what exist on the client can be changing. By providing the new and old relations, it makes it possible for the developer to know what entities need to be removed from certain graphs (such as displays).