1

Sounds pretty simple, however...

This number holds an enumerated type, and should be a field within a custom realtime object. Here's its declaration in the custom object registration routine:

MyRTObjectType.prototype.myEnumeratedType =
    gapi.drive.realtime.custom.collaborativeField('myEnumeratedType');

I can store it in the model as a simple javascript number, and initialize it like this:

function initializeMyRTObjectType() {
    // other fields here
    this.myEnumeratedType = 0;
}

...but the following doesn't work, of course, since it's just a number:

myRTObject.myEnumeratedType.addEventListener(
    gapi.drive.realtime.EventType.OBJECT_CHANGED, self.onTypeChanged);

I can add the event listener to the whole object:

myRTObject.addEventListener(
    gapi.drive.realtime.EventType.OBJECT_CHANGED, self.onTypeChanged);

But I'm only interested in changes to that number (and if I were interested in other changes, I wouldn't want to examine every field to see what's changed).

So let's say I store it as a realtime string, initializing it like this:

function initializeMyRTObjectType() {
    var model = gapi.drive.realtime.custom.getModel(this);
    // other fields here
    this.myEnumeratedType = model.createString();
}

Now I'll get my change events, but they won't necessarily be atomic, and I can't know whether a change, say from "100" to "1001", is merely a change enroute to "101", and so whether I should react to it (this exact example may not be valid, but the idea is there...)

So the question is, is there either a way to know that all (compounded?) changes, insertions/deletions are complete on a string field, or (better) a different recommended way to store a number, and get atomic notification when it has been changed?

HeyHeyJC
  • 2,627
  • 1
  • 18
  • 27
  • If you've found a cleaner way to do this than the answer, I'd love to know --- I have almost precisely the same problem. – David Given Feb 07 '16 at 00:59

1 Answers1

2

You also get a VALUE_CHANGED event on the containing object like you would for a map:

myRTObject.addEventListener(gapi.drive.realtime.EventType.VALUE_CHANGED,
  function(event) {
    if (event.property === 'myEnumeratedType') {
      // business logic
    }
  });
Christopher Best
  • 466
  • 4
  • 14
  • Yeah, this covers it. One handler like this is likely better than hanging listeners on each (collaborative) field. The question of knowing when compounded changes are complete still stands, though..? I may ask it as a separate question. – HeyHeyJC Jun 05 '15 at 15:58