Search code examples
javascriptgoogle-drive-apigoogle-drive-realtime-api

Tracking ChangeEvent source in collaborative maps


I have a collaborative map, with collaborative maps as values. When an event happens on the value maps, I want to know to which key (of the outer map) the event belongs. Anyone can suggest a clean way of achieving this?

CMap(key, cmapb(k,string)) , ChangeEvent happens on cmapb string, I want to know key of CMap. k is unique only for individual key(so tracking k and then finding key which contains k is not an option).

ValueChangedEvent CollaborativeMap

Edit:

I am attaching the EventListener this way before adding records(cmapb) to CMAP:

records.addEventListener(gapi.drive.realtime.EventType.VALUE_CHANGED, updateJSON); 

If I could pass the id of records on updateJSON, I could then iterate through CMAP to find which value has that id. Although I do not know how I can pass the id, as well as the ChangeEvent.


Solution

  • I'm not sure what exactly you are trying to model here. Are you actually adding arbitrary elements to these maps? Otherwise, you might look at using custom objects, where you could have a field for the key and other fields for the other objects you are storing. (See https://developers.google.com/drive/realtime/build-model#lifecycle_of_a_custom_collaborative_data_object)

    If you really just want to have access to that value in the function, you can do that with a standard javascript, e.g closure, or a bind function.