2

I am trying to use the API in this page.

The definition is like this below:

vline.Promise.<vline.Collection> getMessages([Number opt_limit])

I want to use the return value of this API, however I don't understand what the <> means. I have researched about the JavaScript language but I couldn't find any clues.

My script is:

vlinesession.getPerson(userId).done(function(person) {       
    person.postMessage(msg); //it works.
    var log = person.getMessages(20); //how can I parse 'log'?
}

Can anyone give me a hint or some samples on how to use this API?

Boann
  • 48,794
  • 16
  • 117
  • 146
whitebear
  • 11,200
  • 24
  • 114
  • 237
  • not so much a problem with Javascript, as a problem with documentation. – Spudley Jul 29 '13 at 13:44
  • 4
    It's not standard Javascript, I'd guess it's supposed to resemble the syntax of generics in other languages. So a `Promise` is a promise that "returns" a `Foo` - most likely passes it to its completion handler, since CPS is common in JS. I'm guessing you "parse" log by doing `log.done(function(messages) { ... });` where `messages` will be a `Collection` of messages. (Whatever `Collection` is, look up the documentation for it.) – millimoose Jul 29 '13 at 13:44

3 Answers3

6

This is explained on the vline.Promise documentation page:

In the documentation, you will frequently see functions with a return value of the form vline.Promise.<foo.Bar>. This is a short-hand way of saying that the function returns a Promise and the result provided to success callbacks on that Promise will be of type foo.Bar. We may refer to this less formally as a "promise of a foo.Bar".

cmbuckley
  • 40,217
  • 9
  • 77
  • 91
2

@cbuckley is correct in his description, but I want to expand on it and give an example.

vline.Promise.<vline.Collection> getMessages([Number opt_limit])

This indicates that it is returning a vline.Promise with the result to the success callback being of type vline.Collection.

Here's an example:

vlinesession.getPerson(userId).done(function(person) {       
    person.getMessages().done(function(msgCollection) {   // msgCollection is a vline.Collection of vline.Message's
        for (var i = 0; i < msgCollection.getSize(); i++) {
            var msg = msgCollection.getAt(i);       // this is the vline.Message
            console.log('Message from: ' + msg.getSender() + 
                        ' with body: ' + msg.getBody());
        }
    }); 
});

Note that I left out the fail handlers for brevity, but you should include those as well to make your code robust.

tomtheengineer
  • 4,127
  • 1
  • 17
  • 15
0

<vline.Collection> should be replaced with something else, it's not javascript syntax.

towry
  • 4,131
  • 1
  • 18
  • 25