A GraphLoader that connects to a Thinkmap 2.9.2+ datasource
Get the remote entity id of the given entity
Fetch an entity,selection, or remote id asynchronously from the datasource.
This method fetches entities from a remote datasource using the remoteid or remoteid associated with the given entity. Any entities passed to this method without a remoteid will not be fetched.
the id, entity, or entities to fetch
an array of entities fetched from the datasource
datasource.fetchEntity(['actor',68]).oncomplete(function(result) {console.log(result)})
datasource.fetchEntity(['movie','The Breakfast Club', 1985]).oncomplete(function(result) {console.log(result)})
Mark this entity's relations as being invalid. They will be reloaded from the datasource on the next related request.
the entity to invalidate
Merges a message object returned from a Thinkmap datasource into the underlying graph.
This is an advanced method that should only be called on custom requests to a datasource (sendRequest) that returns a message containing entities. The message must conform to the Thinkmap Datasource API for the entities to be properly merged into the graph.
The returned result contains several arrays that break down the values returned from the message such as "all", "root","nodes","edges", and byId which is an object key:value pair of ids to entity.
Search this datasource (asynchronously).
search string
Sends an asynchronous message to the datasource.
This message should only be called for custom requests with their own unique request ids. This method should not be called directly for any of the built in request types of Thinkmap (i.e. fetchEntity).
The message returned should be in JSON format as it will be evaulated as such. If entities are returned in the request, the message must meet the Thinkmap Datasource API Grammar and mergeMessage must be called on the message before the entities can be properly merged into the underlying graph.
Asynchronously fetch the entities related to the given entity, using any this graph loaders to retrieve the related entities.
This method is typically not called by users, but is called by the query API when fetching remote data.
the entity to fetch data for
the current query (part) being executed
a future entity that will be fulfilled when all data related to the given entity has been loaded by this loader, or null, if this loader does not provide related information for the given entity.
Add a listener to this EventSource
the name of the event to listen for
the callback to add
this eventsource
Dispatch an event from this EventSource, supplying arguments to the listeners via an Array, rather than var-args.
the name of the event to dispatch
this EventSource
Dispatch an event from this EventSource
the name of the event to dispatch
optional arguments sent to the event listeners
this EventSource
Fire an event from this EventSource
the name of the event to dispatch
optional arguments sent to the event listeners
this EventSource
Remove a listener from this EventSource
the name of the event to remove the listener for
the callback to remove
this eventsource
Add a listener to this EventSource
the name of the event to listen for
the callback
this eventsource
Add a listener to this EventSource, which will be called at most once and will be removed the first time the given event fires.
the name of the event to listen for
the callback to add
this eventsource
Remove a listener from this EventSource
the name of the event to remove the listener for
the callback to remove
this eventsource
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;
})
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
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();
});
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.
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).