kernel.js 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  1. "use strict";
  2. // Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  3. // Secretary of Defense (Personnel & Readiness).
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  6. // in compliance with the License. You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software distributed under the License
  11. // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  12. // or implied. See the License for the specific language governing permissions and limitations under
  13. // the License.
  14. /// Kernel API.
  15. ///
  16. /// @module vwf/api/kernel
  17. define( function() {
  18. var exports = {
  19. // TODO: setState
  20. // TODO: getState
  21. // TODO: hashState
  22. /// Create a node from a component specification. Construction may require loading data from
  23. /// multiple remote documents. This function returns before construction is complete. A callback
  24. /// is invoked once the node has fully loaded.
  25. ///
  26. /// A simple node consists of a set of properties, methods and events, but a node may specialize
  27. /// a prototype component and may also contain multiple child nodes, any of which may specialize
  28. /// a prototype component and contain child nodes, etc. So components cover a vast range of
  29. /// complexity. The application definition for the overall simulation is a single component
  30. /// instance.
  31. ///
  32. /// A node is a component instance--a single, anonymous specialization of its component. Nodes
  33. /// specialize components in the same way that any component may specialize a prototype
  34. /// component. The prototype component is made available as a base, then new or modified
  35. /// properties, methods, events, child nodes and scripts are attached to modify the base
  36. /// implemenation.
  37. ///
  38. /// To create a node, we first make the prototoype available by loading it (if it has not
  39. /// already been loaded). This is a recursive call to createNode() with the prototype
  40. /// specification. Then we add new, and modify existing, properties, methods, and events
  41. /// according to the component specification. Then we load an add any children, again
  42. /// recursively calling createNode() for each. Finally, we attach any new scripts and invoke an
  43. /// initialization function.
  44. ///
  45. /// @function
  46. ///
  47. /// @param {String|Object} nodeComponent
  48. /// @param {String} [nodeAnnotation]
  49. /// @param {String} [baseURI]
  50. /// @param {module:vwf/api/kernel~nodeCallback} [callback]
  51. ///
  52. /// @returns {}
  53. createNode: [ /* nodeComponent, nodeAnnotation, baseURI, callback( nodeID ) */ ],
  54. /// Delete a node.
  55. ///
  56. /// The node and all of its descendants will be removed from the application.
  57. ///
  58. /// @function
  59. ///
  60. /// @param {ID} nodeID
  61. ///
  62. /// @returns {}
  63. deleteNode: [ /* nodeID */ ],
  64. /// Set node will set the properties of the node specified by the given id and component.
  65. ///
  66. /// @function
  67. ///
  68. /// @param {ID} nodeID
  69. /// @param {String|Object} nodeComponent
  70. /// @param {module:vwf/api/kernel~nodeCallback} [callback]
  71. ///
  72. /// @returns {}
  73. setNode: [ /* nodeID, nodeComponent, callback( nodeID ) */ ],
  74. /// Get node will retrieve the component of the node specified by the given id.
  75. ///
  76. /// @function
  77. ///
  78. /// @param {ID} nodeID
  79. /// @param {Boolean} full
  80. /// @param {Boolean} normalize
  81. ///
  82. /// @returns {Object}
  83. getNode: [ /* nodeID, full, normalize */ ],
  84. // TODO: hashNode
  85. /// @function
  86. ///
  87. /// @param {ID} nodeID
  88. /// @param {String} childName
  89. /// @param {String|Object} childComponent
  90. /// @param {String} [childURI]
  91. /// @param {module:vwf/api/kernel~nodeCallback} [callback]
  92. ///
  93. /// @returns {}
  94. createChild: [ /* nodeID, childName, childComponent, childURI, callback( childID ) */ ],
  95. /// @function
  96. ///
  97. /// @param {ID} nodeID
  98. /// @param {String} childName
  99. ///
  100. /// @returns {}
  101. deleteChild: [ /* nodeID, childName */ ],
  102. /// addChild calls addingChild() on each model. The child is considered added after each model has
  103. /// run. Additionally, it calls addedChild() on each view. The view is being notified that a
  104. /// child has been added.
  105. ///
  106. /// @function
  107. ///
  108. /// @param {ID} nodeID
  109. /// @param {ID} childID
  110. /// @param {String} childName
  111. ///
  112. /// @returns {}
  113. addChild: [ /* nodeID, childID, childName */ ],
  114. /// removeChild calls removingChild() on each model. The child is considered removed after each model
  115. /// has run. Additionally, it calls removedChild() on each view. The view is being notified that a
  116. /// child has been removed.
  117. ///
  118. /// @function
  119. ///
  120. /// @param {ID} nodeID
  121. /// @param {ID} childID
  122. ///
  123. /// @returns {}
  124. removeChild: [ /* nodeID, childID */ ],
  125. /// setProperties sets all of the properties for a node. It will call settingProperties()
  126. /// on each model and satProperties() on each view.
  127. ///
  128. /// @function
  129. ///
  130. /// @param {ID} nodeID
  131. /// @param {Object} properties
  132. ///
  133. /// @returns {Object}
  134. setProperties: [ /* nodeID, properties */ ],
  135. /// getProperties will get all of the properties for a node. It will call
  136. /// gettingProperties() on each model and gotProperties() on each view.
  137. ///
  138. /// @function
  139. ///
  140. /// @param {ID} nodeID
  141. ///
  142. /// @returns {Object}
  143. getProperties: [ /* nodeID */ ],
  144. /// createProperty will create a property on a node and assign an initial value.
  145. /// It will call creatingProperty() on each model. The property is considered created after each
  146. /// model has run. Additionally, it wil call createdProperty() on each view. The view is being
  147. /// notified that a property has been created.
  148. ///
  149. /// @function
  150. ///
  151. /// @param {ID} nodeID
  152. /// @param {String} propertyName
  153. /// @param propertyValue
  154. /// @param {String} propertyGet
  155. /// @param {String} propertySet
  156. ///
  157. /// @returns {} propertyValue
  158. createProperty: [ /* nodeID, propertyName, propertyValue, propertyGet, propertySet */ ],
  159. // TODO: deleteProperty
  160. /// setProperty sets a specific property value on a node. It will call settingProperty()
  161. /// on each model. The first model to return a non-undefined value has performed the
  162. /// set and dictates the return value. The property is considered set after each model has run.
  163. /// It will also call satProperty() on each view. The view is being notified that a property has
  164. /// been set.
  165. ///
  166. /// @function
  167. ///
  168. /// @param {ID} nodeID
  169. /// @param {String} propertyName
  170. /// @param {Value} propertyValue
  171. ///
  172. /// @returns {Value} propertyValue
  173. setProperty: [ /* nodeID, propertyName, propertyValue */ ],
  174. /// getProperty will retrive a property value for a node. It will call gettingProperty()
  175. /// on each model. The first model to return a non-undefined value dictates the return value.
  176. /// It will also call gotProperty() on each view.
  177. ///
  178. /// @function
  179. ///
  180. /// @param {ID} nodeID
  181. /// @param {String} propertyName
  182. ///
  183. /// @returns {Value} propertyValue
  184. getProperty: [ /* nodeID, propertyName */ ],
  185. /// Create a method on a node. Methods are incoming function calls made to a node.
  186. ///
  187. /// @function
  188. ///
  189. /// @param {ID} nodeID
  190. /// The ID of a node containing a method `methodName`.
  191. /// @param {String} methodName
  192. /// The name of a method on the `nodeID` node.
  193. /// @param {String[]} methodParameters
  194. /// An array of names of the method's positional parameters. The method body uses these
  195. /// names to refer to the caller's arguments.
  196. /// @param {String} methodBody
  197. /// The body of a script to be used as the handler for the method. Strings will be
  198. /// interpreted as JavaScript; other script types may be supported in future releases.
  199. ///
  200. /// @returns {Handler} methodHandler
  201. createMethod: [ /* nodeID, methodName, methodParameters, methodBody */ ],
  202. // TODO: deleteMethod
  203. /// Set the handler for a method on a node.
  204. ///
  205. /// @function
  206. ///
  207. /// @param {ID} nodeID
  208. /// The ID of a node containing a method `methodName`.
  209. /// @param {String} methodName
  210. /// The name of a method on the `nodeID` node.
  211. /// @param {Handler} methodHandler
  212. /// A script to set as the handler for the method.
  213. ///
  214. /// @returns {Handler} methodHandler
  215. setMethod: [ /* nodeID, methodName, methodHandler */ ],
  216. /// Get the handler for a method on a node.
  217. ///
  218. /// @function
  219. ///
  220. /// @param {ID} nodeID
  221. /// The ID of a node containing a method `methodName`.
  222. /// @param {String} methodName
  223. /// The name of a method on the `nodeID` node.
  224. ///
  225. /// @returns {Handler} methodHandler
  226. getMethod: [ /* nodeID, methodName */ ],
  227. /// Invoke a method on a node.
  228. ///
  229. /// @function
  230. ///
  231. /// @param {ID} nodeID
  232. /// The ID of a node containing a method `methodName`.
  233. /// @param {String} methodName
  234. /// The name of a method on the `nodeID` node.
  235. /// @param {Value[]} methodParameters
  236. /// An array of values to pass as arguments to the method call.
  237. ///
  238. /// @returns {Value} returnValue
  239. callMethod: [ /* nodeID, methodName, methodParameters */ ],
  240. /// Create an event on a node.
  241. ///
  242. /// Events are outgoing function calls that a node makes to announce changes to the node, or
  243. /// to announce changes within a set of nodes that the node manages. Other nodes may attach
  244. /// listener functions to the event which will be called when the event fires.
  245. ///
  246. /// @function
  247. ///
  248. /// @param {ID} nodeID
  249. /// The ID of a node containing an event `eventName`.
  250. /// @param {String} eventName
  251. /// The name of an event on the `nodeID` node.
  252. /// @param {String[]} eventParameters
  253. /// An array of names of the event's positional parameters. The names are primarily used
  254. /// to describe arguments that the event will pass to listeners when the event is fired.
  255. /// The event's parameter list will be used as the default list for listeners that don't
  256. /// declare their own parameters.
  257. ///
  258. /// @returns {}
  259. createEvent: [ /* nodeID, eventName, eventParameters */ ],
  260. // TODO: deleteEvent
  261. /// Set a node's event and its listeners.
  262. ///
  263. /// @function
  264. ///
  265. /// @param {ID} nodeID
  266. /// The ID of a node containing an event `eventName`.
  267. /// @param {String} eventName
  268. /// The name of an event on the `nodeID` node.
  269. /// @param {Event} eventDescriptor
  270. /// The new event, including its listeners.
  271. ///
  272. /// @returns {Event}
  273. setEvent: [ /* nodeID, eventName, eventDescriptor */ ],
  274. /// Get a node's event and its listeners.
  275. ///
  276. /// @function
  277. ///
  278. /// @param {ID} nodeID
  279. /// The ID of a node containing an event `eventName`.
  280. /// @param {String} eventName
  281. /// The name of an event on the `nodeID` node.
  282. ///
  283. /// @returns {Event}
  284. getEvent: [ /* nodeID, eventName */ ],
  285. /// Add a function to a node's event to be called when the event fires.
  286. ///
  287. /// By default, the handler will be invoked in the context of the sender. For JavaScript
  288. /// handlers, this means that `this` will refer to the node with ID `nodeID`. To invoke the
  289. /// handler on a different node, provide an `eventContextID` when adding the listener.
  290. ///
  291. /// For dispatched events (invoked with `kernel.dispatchEvent`), events are fired from a
  292. /// series of nodes until the event is handled. Starting at the application root, the event
  293. /// is fired on the target's ancestors, downward, in a "capture" phase, then fired on the
  294. /// target node, then again fired on the target's ancestors, upward, in a "bubbling" phase.
  295. ///
  296. /// For dispatched events, after firing the event at a particular node, if any of the
  297. /// handlers returned a truthy value, the event is considered _handled_ and the dispatch
  298. /// process stops at that node. An event that is handled during the capture phase prevents
  299. /// lower nodes or the target node from receiving the event. Events handled during the
  300. /// bubbling phase catch events not handled by the target node or by lower nodes.
  301. ///
  302. /// By default, a listener will only be invoked if it is attached to the event target, or
  303. /// during the bubbling phase, if it attached to a node above the target. To also invoke a
  304. /// listener during the capture phase, pass `eventPhases` as the array `[ "capture" ]`.
  305. ///
  306. /// @function
  307. ///
  308. /// @param {ID} nodeID
  309. /// The ID of a node containing an event `eventName`.
  310. /// @param {String} eventName
  311. /// The name of an event on the `nodeID` node. When the event is fired, all of its
  312. /// listeners will be called.
  313. /// @param {Handler} eventHandler
  314. /// A script to be added as a handler for the event. The `eventParameters` that were
  315. /// provided to the `createEvent` call will be available to the handler body as function
  316. /// parameters if the handler doesn't declare its own parameters.
  317. /// @param {ID} [eventContextID]
  318. /// The ID of the node that the handler is _invoked on_. For JavaScript handlers, `this`
  319. /// will refer to the `eventContextID` node. If `eventContextID` is not provided, the
  320. /// handler will be invoked in the context of the global root pseudo-node.
  321. /// @param {String[]} [eventPhases]
  322. /// An array of strings indicating the event dispatch phases that this handler should
  323. /// respond to. Handlers will be invoked at the target and during the bubbling phase
  324. /// regardless of its `eventPhases`. To also invoke a handler during the capture phase,
  325. /// include `"capture"` in the `eventPhases` array.` `eventPhases` only applies to the
  326. /// propagation performed by `kernel.dispatchEvent`. Once `kernel.fireEvent` is called, it
  327. /// always invokes all of the event's handlers.
  328. ///
  329. /// @returns {ListenerID}
  330. addEventListener: [ /* nodeID, eventName, eventHandler, eventContextID, eventPhases */ ],
  331. /// Remove a listener function from a node's event. The handler will no longer be called
  332. /// when the event fires.
  333. ///
  334. /// @function
  335. ///
  336. /// @param {ID} nodeID
  337. /// The ID of a node containing an event `eventName`.
  338. /// @param {String} eventName
  339. /// The name of an event on the `nodeID` node.
  340. /// @param {ListenerID} eventListenerID
  341. /// A listener ID previously returned by `kernel.addEventListener` that identifies a
  342. /// listener attached to this `nodeID` and `eventName`.
  343. ///
  344. /// @returns {ListenerID}
  345. /// `eventListenerID` if the listener was removed successfully. Otherwise, a falsy value.
  346. removeEventListener: [ /* nodeID, eventName, eventListenerID */ ],
  347. /// Set the handler for a listener on a node's event.
  348. ///
  349. /// @function
  350. ///
  351. /// @param {ID} nodeID
  352. /// The ID of a node containing an event `eventName`.
  353. /// @param {String} eventName
  354. /// The name of an event on the `nodeID` node.
  355. /// @param {ListenerID} eventListenerID
  356. /// A listener ID previously returned by `kernel.addEventListener` that identifies a
  357. /// listener attached to this `nodeID` and `eventName`.
  358. /// @param {Listener} eventListener
  359. /// A script to set as the handler for the listener. The `eventParameters` that were
  360. /// provided to the `createEvent` call will be available to the handler body as function
  361. /// parameters if the handler doesn't declare its own parameters.
  362. ///
  363. /// @returns {Listener}
  364. setEventListener: [ /* nodeID, eventName, eventListenerID, eventListener */ ],
  365. /// Get the handler for a listener on a node's event.
  366. ///
  367. /// @function
  368. ///
  369. /// @param {ID} nodeID
  370. /// The ID of a node containing an event `eventName`.
  371. /// @param {String} eventName
  372. /// The name of an event on the `nodeID` node.
  373. /// @param {ListenerID} eventListenerID
  374. /// A listener ID previously returned by `kernel.addEventListener` that identifies a
  375. /// listener attached to this `nodeID` and `eventName`.
  376. ///
  377. /// @returns {Listener}
  378. getEventListener: [ /* nodeID, eventName, eventListenerID */ ],
  379. /// Remove all listener functions from a node's event that are associated with a particular
  380. /// context.
  381. ///
  382. /// @function
  383. ///
  384. /// @param {ID} nodeID
  385. /// The ID of a node containing an event `eventName`.
  386. /// @param {String} eventName
  387. /// The name of an event on the `nodeID` node.
  388. /// @param {ID} eventContextID
  389. /// The ID of a context node that handlers may be associated with. Handler context
  390. /// associations are made when `kernel.addEventListener` adds a handler to an event.
  391. ///
  392. /// @returns {}
  393. flushEventListeners: [ /* nodeID, eventName, eventContextID */ ],
  394. /// It will call firingEvent() on each model and firedEvent() on each view.
  395. ///
  396. /// @function
  397. ///
  398. /// @param {ID} nodeID
  399. /// The ID of a node containing an event `eventName`.
  400. /// @param {String} eventName
  401. /// The name of an event on the `nodeID` node.
  402. /// @param {Value[]} eventParameters
  403. /// An array of values to pass as arguments to calls into the event's listeners.
  404. ///
  405. /// @returns {}
  406. fireEvent: [ /* nodeID, eventName, eventParameters */ ],
  407. /// Dispatch an event toward a node. Using fireEvent(), capture (down) and bubble (up) along
  408. /// the path from the global root to the node. Cancel when one of the handlers returns a
  409. /// truthy value to indicate that it has handled the event.
  410. ///
  411. /// @function
  412. ///
  413. /// @param {ID} nodeID
  414. /// The ID of a node containing an event `eventName`.
  415. /// @param {String} eventName
  416. /// The name of an event on the `nodeID` node.
  417. /// @param {Value[]} eventParameters
  418. /// An array of values to pass as arguments to calls into the event's listeners. Values
  419. /// from `eventParameters` are sent with the `kernel.fireEvent` call to each node.
  420. /// @param {Object} eventNodeParameters
  421. /// A collection of `ID`-indexed arrays of values to pass as additional arguments for
  422. /// `kernel.fireEvent` calls to specific nodes.
  423. ///
  424. /// @returns {}
  425. dispatchEvent: [ /* nodeID, eventName, eventParameters, eventNodeParameters */ ],
  426. /// It will call executing() on each model. The script is considered executed after each model
  427. /// has run and all asynchronous calls made inside them have returned.
  428. /// It will then call executed() on each view to notify it that a script has been executed.
  429. /// It will then call the caller-provided callback to notify the caller that the
  430. /// script has been fully executed and all asynchronous actions have completed.
  431. ///
  432. /// @function
  433. ///
  434. /// @param {ID} nodeID
  435. /// @param {String} scriptText
  436. /// @param {String} scriptType
  437. /// @param {module:vwf/api/kernel~valueCallback} [callback]
  438. ///
  439. /// @returns {Value} returnValue
  440. execute: [ /* nodeID, scriptText, scriptType, callback( returnValue ) */ ],
  441. /// @function
  442. ///
  443. /// @param {ID} nodeID
  444. ///
  445. /// @returns {Number}
  446. random: [ /* nodeID */ ],
  447. /// @function
  448. ///
  449. /// @param {ID} nodeID
  450. /// @param {String} seed
  451. seed: [ /* nodeID, seed */ ],
  452. /// It will return the current simulation time.
  453. ///
  454. /// @function
  455. ///
  456. /// @returns {Number}
  457. time: [],
  458. /// It will return the moniker of the client responsible for the current action. Will be
  459. /// falsy for actions originating in the server, such as time ticks.
  460. ///
  461. /// @function
  462. ///
  463. /// @returns {String}
  464. client: [],
  465. /// It will return the identifer the server assigned to this client.
  466. ///
  467. /// @function
  468. ///
  469. /// @returns {String}
  470. moniker: [],
  471. /// Return the application root node. `kernel.application( initializedOnly )` is equivalent
  472. /// to `kernel.global( "application", initializedOnly )`.
  473. ///
  474. /// @function
  475. ///
  476. /// @param {Boolean} [initializedOnly]
  477. /// If set, only return the application node if the application has completed
  478. /// initialization. Drivers that manage application code should set `initializedOnly`
  479. /// since applications should never have access to uninitialized parts of the application
  480. /// graph.
  481. ///
  482. /// @returns {ID}
  483. /// The ID of the application root. `application` may return `undefined` if the entire
  484. /// application has been deleted.
  485. application: [ /* initializedOnly */ ],
  486. /// Return the node's intrinsic state. This consists of:
  487. ///
  488. /// source -- the URI of the node's data blob
  489. /// type -- the MIME type of the node's data blob
  490. ///
  491. /// The values are returned in an Object with the named properties. If the optional result
  492. /// parameter is provided, the fields are added there (without disturbing any other fields) and
  493. /// result is returned. Otherwise, a new object is created, filled, and returned.
  494. ///
  495. /// @function
  496. ///
  497. /// @param {ID} nodeID
  498. /// ID of the node to query.
  499. /// @param {Object} [result]
  500. /// An optional Object to receive the result.
  501. ///
  502. /// @returns {Object}
  503. intrinsics: [ /* nodeID, result */ ],
  504. /// Return the node's URI. This value will be the component URI for the root node of a component
  505. /// loaded from a URI, and undefined in all other cases.
  506. ///
  507. /// @function
  508. ///
  509. /// @param {ID} nodeID
  510. /// @param {Boolean} [searchAncestors]
  511. /// If set and the node doesn't have a URI, search the node's ancestors. Return the URI of
  512. /// the closest ancestor with a URI.
  513. /// @param {Boolean} [initializedOnly]
  514. /// If set, only search ancestors through those that have completed initialization.
  515. ///
  516. /// @returns {String}
  517. uri: [ /* nodeID, searchAncestors, initializedOnly */ ],
  518. /// Name calls naming() on each model. The first model to return a non-undefined value dictates
  519. /// the return value.
  520. ///
  521. /// @function
  522. ///
  523. /// @param {ID} nodeID
  524. ///
  525. /// @returns {String}
  526. name: [ /* nodeID */ ],
  527. /// Return a node's prototype.
  528. ///
  529. /// @function
  530. ///
  531. /// @param {ID} nodeID
  532. ///
  533. /// @returns {ID}
  534. /// The ID of the node's prototype, or `undefined` if called on the proto-prototype,
  535. /// `node.vwf`.
  536. prototype: [ /* nodeID */ ],
  537. /// Return a node's prototype, its prototype, etc. up to and including `node.vwf`.
  538. ///
  539. /// @function
  540. ///
  541. /// @param {ID} nodeID
  542. /// @param {Boolean} [includeBehaviors]
  543. /// If set, also include the node's and prototypes' behaviors.
  544. ///
  545. /// @returns {ID[]}
  546. /// An array of IDs of the node's prototypes.
  547. prototypes: [ /* nodeID, includeBehaviors */ ],
  548. /// Return a node's behaviors.
  549. ///
  550. /// @function
  551. ///
  552. /// @param {ID} nodeID
  553. ///
  554. /// @returns {ID[]}
  555. /// An array of IDs of the node's behaviors. An empty array is returned if the node
  556. /// doesn't have any behaviors.
  557. behaviors: [ /* nodeID */ ],
  558. /// Return the set of global root nodes. Each global node is the root of a tree.
  559. ///
  560. /// @function
  561. ///
  562. /// @param {Boolean} [initializedOnly]
  563. /// If set, only return root nodes that have completed initialization. Drivers that manage
  564. /// application code should set `initializedOnly` and should also only provide the
  565. /// `kernel.globals` result (even with `initializedOnly` set) to the application if the
  566. /// application itself has completed initialization. Applications should never have access
  567. /// to uninitialized parts of the simulation.
  568. ///
  569. /// @returns {Object}
  570. /// An object whose keys are the IDs of the global root nodes. `Object.keys` may be used
  571. /// on the result to get an array of IDs. The global trees are not ordered, and the order
  572. /// of the IDs is not significant.
  573. globals: [ /* initializedOnly */ ],
  574. /// Return a global root node selected by its URI or annotation.
  575. ///
  576. /// @function
  577. ///
  578. /// @param {String} globalReference
  579. /// A selector that identifies the root to return. `globalReference` may specify either a
  580. /// URI or annotation. The root nodes are searched first by URI, then by annotation if no
  581. /// match is found.
  582. /// @param {Boolean} [initializedOnly]
  583. /// If set, only return a root node if it has completed initialization. Drivers that
  584. /// manage application code should set `initializedOnly` and should also only provide the
  585. /// result of `kernel.global` (even with `initializedOnly` set) to the application if the
  586. /// application itself has completed initialization. Applications should never have access
  587. /// to uninitialized parts of the simulation.
  588. ///
  589. /// @returns {ID}
  590. /// The ID of the root node of the selected tree, or `undefined` if `globalReference`
  591. /// doesn't match any root or if `initializedOnly` is set and the selected tree has not
  592. /// completed initialization.
  593. global: [ /* globalReference, initializedOnly */ ],
  594. /// Return the node at the root of the tree containing a node.
  595. ///
  596. /// @function
  597. ///
  598. /// @param {ID} nodeID
  599. /// @param {Boolean} [initializedOnly]
  600. /// If set, only return the root node if the node and its ancestors have completed
  601. /// initialization. Drivers that manage application code should set `initializedOnly`
  602. /// since applications should never have access to uninitialized parts of the application
  603. /// graph.
  604. ///
  605. /// @returns {ID}
  606. /// The ID of the node at the root of the tree containing the node, or `undefined` if
  607. /// `initializedOnly` is set and the node or one of its ancestors has not completed
  608. /// initialization.
  609. root: [ /* nodeID, initializedOnly */ ],
  610. /// Return a node's parent, grandparent, its parent, etc.
  611. ///
  612. /// @function
  613. ///
  614. /// @param {ID} nodeID
  615. /// @param {Boolean} [initializedOnly]
  616. /// If set, only include parents of nodes that have completed initialization. If a portion
  617. /// of the tree containing the node is still initializing, the node's parent, grandparent,
  618. /// etc. will be included if the preceding node is initialized, but the remaining
  619. /// ancestors will be omitted. Drivers that manage application code should set
  620. /// `initializedOnly` since applications should never have access to uninitialized parts
  621. /// of the application graph.
  622. ///
  623. /// @returns {ID[]}
  624. /// An array of IDs of the node's ancestors. An empty array is returned for global,
  625. /// top-level nodes that don't have a parent.
  626. ancestors: [ /* nodeID, initializedOnly */ ],
  627. /// Return a node's parent.
  628. ///
  629. /// @function
  630. ///
  631. /// @param {ID} nodeID
  632. /// @param {Boolean} [initializedOnly]
  633. /// If set, only return the parent if the node has completed initialization. Drivers that
  634. /// manage application code should set `initializedOnly` since applications should never
  635. /// have access to uninitialized parts of the application graph.
  636. ///
  637. /// @returns {ID}
  638. /// The ID of the node's parent, or `undefined` for the application root node or other
  639. /// global, top-level nodes.
  640. parent: [ /* nodeID, initializedOnly */ ],
  641. /// Return a node's children.
  642. ///
  643. /// @function
  644. ///
  645. /// @param {ID} nodeID
  646. /// @param {Boolean} [initializedOnly]
  647. /// If set, only return children that have completed initialization. Uninitialized
  648. /// children will appear in the result as `undefined`. Drivers that manage application
  649. /// code should set `initializedOnly` since applications should never have access to
  650. /// uninitialized parts of the application graph.
  651. ///
  652. /// @returns {ID[]}
  653. /// An array of IDs of the node's children. An empty array is returned if the node
  654. /// doesn't have any children. The result always contains one element for each child,
  655. /// regardless of their initialization state and whether `initializedOnly` is set.
  656. /// However, `initializedOnly` will cause uninitialized children to appear as `undefined`.
  657. children: [ /* nodeID, initializedOnly */ ],
  658. /// Return a node's child selected by index or name.
  659. ///
  660. /// @function
  661. ///
  662. /// @param {ID} nodeID
  663. /// @param {String} childReference
  664. /// A selector indicating the child to return. If `childReference` is a number, the child
  665. /// at that index location is returned. Otherwise, a child with the name matching
  666. /// `childReference` (if any) is returned.
  667. /// @param {Boolean} [initializedOnly]
  668. /// If set, only return a child if it has completed initialization. Drivers that manage
  669. /// application code should set `initializedOnly` since applications should never have
  670. /// access to uninitialized parts of the application graph.
  671. ///
  672. /// @returns {ID}
  673. /// The ID of the selected child, or `undefined` if `childReference` doesn't match a child
  674. /// or if `initializedOnly` is set and the selected child has not completed
  675. /// initialization.
  676. child: [ /* nodeID, childReference, initializedOnly */ ],
  677. /// Return a node's children, grandchildren, their children, etc.
  678. ///
  679. /// @function
  680. ///
  681. /// @param {ID} nodeID
  682. /// @param {Boolean} [initializedOnly]
  683. /// If set, only return descendants that have completed initialization. Uninitialized
  684. /// descendants will appear in the result as `undefined`. Descendants of uninitialized
  685. /// descendants will not appear. Drivers that manage application code should set
  686. /// `initializedOnly` since applications should never have access to uninitialized parts
  687. /// of the application graph.
  688. ///
  689. /// @returns {ID[]}
  690. /// An array of IDs of the node's descendants. An empty array is returned if the node
  691. /// doesn't have any descendants. The result may contain `undefined` elements when
  692. /// `initializedOnly` is set and some descendants have not completed initialization.
  693. descendants: [ /* nodeID, initializedOnly */ ],
  694. /// Locate nodes matching a search pattern. matchPattern supports an XPath subset consisting of
  695. /// the following:
  696. ///
  697. /// "/" -- the application root node
  698. /// "/*" -- children of the application
  699. /// "/name" -- a child of the application having the specified name
  700. /// "/name1/name2/name3/..." -- a descendant of the application along the specified path
  701. /// "//name" -- descendants of the application having the specified name
  702. /// "//*" -- all descendants of the application
  703. /// "//element(*,uri)" -- descendants of the application having uri in their prototype chain
  704. ///
  705. /// ".." -- the reference node's parent
  706. /// "." -- the reference node
  707. /// "*", "./*" -- children of the reference node
  708. /// "name", "./name" -- a child of the reference node having the specified name
  709. /// "name1/name2/name3/..." -- a descendant of the reference node along the specified path
  710. /// ".//name" -- descendants of the reference node having the specified name
  711. /// ".//*" -- all descendants of the reference node
  712. /// ".//element(name)" -- same as ".//name"
  713. /// ".//element(*)" -- same as ".//*"
  714. /// ".//element(name,uri)" -- descendants having the specified name and extending uri
  715. /// ".//element(*,uri)" -- descendants extending uri
  716. ///
  717. /// "name[name2]" -- a child "name" which also has a child having the second name
  718. /// "name[name2/name3/...]" -- a child "name" which also has a descendant along the path
  719. /// "*[*]" -- children which also have at least one child
  720. /// "name[@property]" -- a child "name" which also has a truthy property with the provided name
  721. /// "*[@*]" -- children which also have at least one truthy property
  722. ///
  723. /// XPath elements are interpreted as VWF nodes and XPath attributes are interpreted as VWF
  724. /// properties. The expression must evaluate to an element (node) set since only nodes are
  725. /// distinctly addressable entities in VWF. Properties may be used in predicates.
  726. ///
  727. /// The following XPath axes are supported:
  728. /// ancestor-or-self, ancestor, parent, self, child, descendant, descendant-or-self, and
  729. /// attribute (predicates only)
  730. /// along with the following node tests:
  731. /// element(name,type), attribute(name) (in predicates only), and node()
  732. /// the shortcut notation:
  733. /// "//": descendant-or-self:node(), ".": self::node(), "..": "parent::node()",
  734. /// "name": "child::name", "@name": "attribute::name"
  735. /// and the wildcard name:
  736. /// "*"
  737. ///
  738. /// This is a naive implementation with several limitations. There is no particular
  739. /// optimization, and some queries can yield large intermediate or final results. Use caution
  740. /// when applying the descendant operators. The results will not necessarily maintain document
  741. /// order. Overlapping queries will cause nodes to be repeated in the results. For example, the
  742. /// query `*``/..` will return the reference node several times, once for each of its children.
  743. ///
  744. /// Names in XPath expressions may only contain the characters A-Z, a-z, 0-9, -, and .
  745. /// (period). As an extension, this implementation allows names to contain any character so
  746. /// long as it is quoted using either double or single quotes. Within a quoted name, use the
  747. /// charater "\" to escape the quoting character or the escape character. When assembling an
  748. /// expression, use vwf.utility.xpath.quoteName() to quote names that may have invalid
  749. /// characters.
  750. ///
  751. /// @function
  752. ///
  753. /// @param {ID} nodeID
  754. /// The reference node. Relative patterns are resolved with respect to this node. `nodeID`
  755. /// is ignored for absolute patterns.
  756. /// @param {String} matchPattern
  757. /// The search pattern.
  758. /// @param {Boolean} [initializedOnly]
  759. /// Interpret nodes that haven't completed initialization as though they don't have
  760. /// ancestors. Drivers that manage application code should set `initializedOnly` since
  761. /// applications should never have access to uninitialized parts of the application graph.
  762. /// @param {module:vwf/api/kernel~nodeCallback} [callback]
  763. /// A callback to receive the search results. If callback is provided, find invokes
  764. /// callback( matchID ) for each match. Otherwise the result is returned as an array.
  765. ///
  766. /// @returns {ID[]|undefined}
  767. /// If callback is provided, undefined; otherwise an array of the node ids of the result.
  768. find: [ /* nodeID, matchPattern, initializedOnly, callback( matchID ) */ ],
  769. /// Test a node against a search pattern. See vwf.api.kernel#find for details of the query
  770. /// syntax.
  771. ///
  772. /// @function
  773. ///
  774. /// @param {ID} nodeID
  775. /// The reference node. Relative patterns are resolved with respect to this node. `nodeID`
  776. /// is ignored for absolute patterns.
  777. /// @param {String} matchPattern
  778. /// The search pattern.
  779. /// @param {ID} testID
  780. /// A node to test against the pattern.
  781. /// @param {Boolean} [initializedOnly]
  782. /// Interpret nodes that haven't completed initialization as though they don't have
  783. /// ancestors. Drivers that manage application code should set `initializedOnly` since
  784. /// applications should never have access to uninitialized parts of the application graph.
  785. ///
  786. /// @returns {Boolean}
  787. /// true when testID matches the pattern.
  788. test: [ /* nodeID, matchPattern, testID, initializedOnly */ ],
  789. /// Return client object matching the given search pattern.
  790. ///
  791. /// @function
  792. ///
  793. /// @param {ID} nodeID
  794. /// The reference node. Relative patterns are resolved with respect to this node. `nodeID`
  795. /// is ignored for absolute patterns.
  796. /// @param {String} matchPattern
  797. /// The search pattern.
  798. /// @param {module:vwf/api/kernel~nodeCallback} [callback]
  799. /// A callback to receive the search results. If callback is provided, find invokes
  800. /// callback( matchID ) for each match. Otherwise the result is returned as an array.
  801. ///
  802. /// @returns {ID[]|undefined}
  803. /// If callback is provided, undefined; otherwise an array of the node ids of the result.
  804. ///
  805. /// @deprecated in version 0.6.21. Instead of `kernel.findClients( reference, "/pattern" )`,
  806. /// use `kernel.find( reference, "doc('http://vwf.example.com/clients.vwf')/pattern" )`.
  807. findClients: [ /* nodeID, matchPattern, callback( matchID ) */ ],
  808. /// Description.
  809. ///
  810. /// @callback module:vwf/api/kernel~nodeCallback
  811. ///
  812. /// @param {ID} nodeID
  813. /// Description.
  814. ///
  815. /// @callback module:vwf/api/kernel~valueCallback
  816. ///
  817. /// @param {Value} returnValue
  818. /// A `Handler` describes a function that may be attached to a property as a setter or
  819. /// getter, to a method, or to an event as a listener.
  820. ///
  821. /// A `Handler` is an object containing the following properties. Alternately, a `Handler`
  822. /// may be provided as a `string` or `function` representing just the `body` field.
  823. ///
  824. /// @typedef {Object|string|function} Handler
  825. ///
  826. /// @property {string[]} [name]
  827. /// The function's name. VWF doesn't make use of the name, but the field is included so
  828. /// that named JavaScript functions can make a round-trip translation through a `Handler`
  829. /// intact.
  830. /// @property {string[]} [parameters]
  831. /// An array of names of the function's positional parameters. The function body uses
  832. /// these names to refer to the caller's arguments. `parameters` may be omitted if the
  833. /// function doesn't declare any parameters, or if `body` is a JavaScript `function`, in
  834. /// which case the parameters are taken from the JavaScript function itself.
  835. /// @property {string|function} body
  836. /// A representation of the statements making up the function body. For handlers of `type`
  837. /// `application/javascript`, `body` should be a string containing JavaScript text that is
  838. /// correct for the span between the opening and closing braces of a JavaScript function
  839. /// definition: `function(...) {` |<= this is the body text =>| `}`. `body` may also be
  840. /// provided as a JavaScript `function` value, in which case the handler's `body` and
  841. /// `arguments` will be taken from the function.
  842. /// @property {string} [type]
  843. /// The {@link https://www.iana.org/assignments/media-types Media Type} of the `body`
  844. /// text. When `body` is a `string`, the default type is `"application/javascript"`, and
  845. /// `type` may be omitted. `type` should be omitted if `body` is a JavaScript `function`
  846. /// value since the type is implicit in that case.
  847. /// A `ListenerID` is a JavaScript primitive value that identifies an event listener. Each
  848. /// listener is assigned a `ListenerID` when it is created that is unique within the node
  849. /// and event.
  850. ///
  851. /// @typedef {string|number|boolean|null} ListenerID
  852. /// A `Listener` is an extended `Handler` with additional fields for event listeners.
  853. ///
  854. /// Like a `Handler`, a `Listener` may be provided as a `string` or `function` representing
  855. /// just the `body` field.
  856. ///
  857. /// @typedef {Object|string|function} Listener
  858. ///
  859. /// @property {ListenerID} [id]
  860. /// A unique ID as returned by `kernel.addEventListener` that identifies the listener for
  861. /// a particular `nodeID` and `eventName`.
  862. /// @property {string[]} [name]
  863. /// @see {@link module:vwf/api/kernel.Handler}
  864. /// @property {string[]} [parameters]
  865. /// @see {@link module:vwf/api/kernel.Handler}
  866. /// @property {string|function} body
  867. /// @see {@link module:vwf/api/kernel.Handler}
  868. /// @property {string} [type]
  869. /// @see {@link module:vwf/api/kernel.Handler}
  870. /// @property {ID} [context]
  871. /// The ID of a node that the handler will be _invoked on_. For JavaScript handlers,
  872. /// `this` will refer to the `context` node. If `context` is not provided, the context
  873. /// will be the global root pseudo-node.
  874. /// @property {String[]} [phases]
  875. /// An array of strings indicating the event dispatch phases that this handler should
  876. /// respond to. Listeners will be invoked at the target and during the bubbling phase
  877. /// regardless of its `phases`. To also invoke a handler during the capture phase, include
  878. /// `"capture"` in the `phases` array.` `phases` only applies to the propagation performed
  879. /// by `kernel.dispatchEvent`. Once `kernel.fireEvent` is called, it always invokes all of
  880. /// the event's handlers.
  881. /// An `Event` describes an event and its listeners.
  882. ///
  883. /// @typedef {Object} Event
  884. ///
  885. /// @property {string[]} [parameters]
  886. /// An array of names of the event's positional parameters. The names are primarily used
  887. /// to describe arguments that the event will pass to listeners when the event is fired.
  888. /// The event's parameter list will be used as the default list for listeners that don't
  889. /// declare their own parameters. `parameters` may be omitted if the event doesn't declare
  890. /// any parameters.
  891. /// @property {Listener[]} [listeners]
  892. /// An array of listeners to be invoked when the event is fired. Listeners will be invoked
  893. /// in the order provided.
  894. };
  895. return exports;
  896. } );