mmir.grammar.AsyncGrammar
loads the default grammar asynchronously using a WebWorker
NOTE usage of the grammar is also async:
calls on
interpret(text, callback)
are re-directed to the WebWorker
Methods
-
destroy(force)
-
destroy / terminate the WebWorker for async grammar execution NOTE: can be re-initialized using
mmir.grammar.AsyncGrammar#init
Name Type Description force
Boolean optional OPTIONAL if true, will force termination of WebWorker, otherwise waits for pending commands to finish. -
init(langCode, listener, phrase, grammarCode){Boolean}
-
Initialize a grammar to be loaded & executed asynchronously
Name Type Description langCode
String the grammar's ID listener
function the callback that is triggered when the grammar has been initialized: listener(initializationResult)
phrase
String optional a phrase that should be immediately interpreted, after grammar has been loaded (for large grammars, this may reduce delays for subsequent calls, by fully initializing the grammar) grammarCode
String optional for injecting JavaScript grammar code into the WebWorker: instead of loading the compiled grammar (for large grammars, this may reduce delays for subsequent calls, by fully initializing the grammar) for langCode
, willeval()
thegrammarCode
within the WebWorker ThegrammarCode
corrsponds to fieldmmir.grammar.GrammarConverter.js_grammar_definition
, after grammar was compiled.
NOTE this argument is positional! If nophrase
should be use, it needs to be specified asundefined
, e.g.asyncGrammar.init('myGrammar', onInitCallback, void(0), compiledGrammarCode)
Returns:
Type Description Boolean true
if initialization has started, iffalse
initialization could not be started, due to errors or missing/invalid arguments -
isDestroyed(){Boolean}
-
check, if async-grammar worker has been destroyed
Returns:
Type Description Boolean true, if async-grammar worker has been destroyed, otherwise false -
isInit(grammarId){Boolean}
-
check, if grammar has been (or currently is in the process of beeing) intialized for async execution
Name Type Description grammarId
String the grammar ID to check - See:
Returns:
Type Description Boolean true, if grammar has been initialized for async-execution