Changes

Jump to: navigation, search

Labs/Ubiquity/Ubiquity Source Tip Author Tutorial

71 bytes removed, 06:49, 22 June 2009
Implementing Asynchronous Noun Suggestions
CmdUtils.CreateCommand( {
namenames: ["lookup on freebase-lookup"], takesarguments: [{ topicrole: "object", nountype: noun_type_freebase_topic , label: "topic" }, preview: function preview( containerpblock, topic arguments ) { var text = topicarguments.object.text || "any topic"; containerpblock.innerHTML = "Go to the Freebase topic page for " + text + ".";
},
execute: function goToFreebase( topic arguments ) { if ( topic arguments.object.text ) { Utils.openUrlInBrowser( "http://www.freebase.com/view" + topicarguments.object.data.id );
}
}
* The parser's callback function expects only one suggestion (not an array of suggestions), so it must be called one time for each suggestion, even if the noun type has multiple suggestions available at the same time (as in the Freebase example above). This is a bit different from the synchronous case, in which the <code>suggest</code> function is expected to return an array.
* A noun type's <code>suggest</code> function typically returns an empty array when it intends to make asynchronous suggestions, but it can return one or more suggestions synchronously if it has them available. '''Note:''' Due to bug [https://ubiquity.mozilla.com/trac/ticket/619 #619], it's currently ''required'' that the <code>suggest</code> function return at least one suggestion synchronously.
* Because the work being done to generate asynchronous suggestions is generally somewhat expensive, and because a noun type's <code>suggest</code> function may be called for every keystroke the user makes, you should probably consider implementing a delay before starting the work and/or caching the work at some level. Ubiquity currently leaves this up to each noun type individually.
* A much more robust implementation of Freebase-derived noun types can be found [http://graynorton.com/ubiquity/freebase-nouns.html here].
1,007
edits

Navigation menu