view.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. /// @module vwf/kernel/view
  15. /// @requires vwf/view
  16. define( [ "module", "vwf/view" ], function( module, view ) {
  17. return view.load( module, {
  18. // == Module Definition ====================================================================
  19. }, function( viewFunctionName ) {
  20. // == View API =============================================================================
  21. // The kernel bypasses vwf/kernel/view and calls directly into the first driver stage.
  22. return undefined;
  23. }, function( kernelFunctionName ) {
  24. // == Kernel API ===========================================================================
  25. switch ( kernelFunctionName ) {
  26. // -- Read-write functions -------------------------------------------------------------
  27. // TODO: setState
  28. // TODO: getState
  29. // TODO: hashState
  30. case "createNode":
  31. return function( nodeComponent, nodeAnnotation, baseURI, when, callback /* nodeID */ ) {
  32. // Interpret `createNode( nodeComponent, when, callback )` as
  33. // `createNode( nodeComponent, undefined, undefined, when, callback )` and
  34. // `createNode( nodeComponent, nodeAnnotation, when, callback )` as
  35. // `createNode( nodeComponent, nodeAnnotation, undefined, when, callback )`.
  36. // `nodeAnnotation` was added in 0.6.12, and `baseURI` was added in 0.6.25.
  37. if ( typeof baseURI == "function" || baseURI instanceof Function ) {
  38. callback = baseURI;
  39. when = nodeAnnotation;
  40. baseURI = undefined;
  41. nodeAnnotation = undefined;
  42. } else if ( typeof when == "function" || when instanceof Function ) {
  43. callback = when;
  44. when = baseURI;
  45. baseURI = undefined;
  46. }
  47. // Make the call.
  48. this.kernel.send( undefined, kernelFunctionName, undefined,
  49. [ nodeComponent, nodeAnnotation ], when || 0, callback /* result */ );
  50. };
  51. case "deleteNode":
  52. return function( nodeID, when, callback ) {
  53. this.kernel.send( nodeID, kernelFunctionName, undefined,
  54. undefined, when || 0, callback /* result */ );
  55. };
  56. // TODO: setNode
  57. // TODO: getNode
  58. case "createChild":
  59. return function( nodeID, childName, childComponent, childURI, when, callback /* childID */ ) {
  60. this.kernel.send( nodeID, kernelFunctionName, childName,
  61. [ childComponent, childURI ], when || 0, callback /* result */ );
  62. };
  63. case "deleteChild":
  64. return function( nodeID, childName, when, callback ) {
  65. this.kernel.send( nodeID, kernelFunctionName, childName,
  66. undefined, when || 0, callback /* result */ );
  67. };
  68. case "addChild":
  69. return function( nodeID, childID, childName, when, callback ) {
  70. this.kernel.send( nodeID, kernelFunctionName, undefined,
  71. [ childID, childName ], when || 0, callback /* result */ ); // TODO: swap childID & childName?
  72. };
  73. case "removeChild":
  74. return function( nodeID, childID, when, callback ) {
  75. this.kernel.send( nodeID, kernelFunctionName, undefined,
  76. [ childID ], when || 0, callback /* result */ ); // TODO: swap childID & childName?
  77. };
  78. case "setProperties":
  79. return function( nodeID, properties, when, callback ) {
  80. this.kernel.send( nodeID, kernelFunctionName, undefined,
  81. [ properties ], when || 0, callback /* result */ );
  82. };
  83. case "getProperties":
  84. return function( nodeID, when, callback ) {
  85. this.kernel.send( nodeID, kernelFunctionName, undefined,
  86. undefined, when || 0, callback /* result */ );
  87. };
  88. case "createProperty":
  89. return function( nodeID, propertyName, propertyValue, propertyGet, propertySet, when, callback ) {
  90. this.kernel.send( nodeID, kernelFunctionName, propertyName,
  91. [ propertyValue, propertyGet, propertySet ], when || 0, callback /* result */ ); // TODO: { value: propertyValue, get: propertyGet, set: propertySet } ? -- vwf.receive() needs to parse
  92. };
  93. // TODO: deleteProperty
  94. case "setProperty":
  95. return function( nodeID, propertyName, propertyValue, when, callback ) {
  96. this.kernel.send( nodeID, kernelFunctionName, propertyName,
  97. [ propertyValue ], when || 0, callback /* result */ );
  98. };
  99. case "getProperty":
  100. return function( nodeID, propertyName, when, callback ) {
  101. this.kernel.send( nodeID, kernelFunctionName, propertyName,
  102. undefined, when || 0, callback /* result */ );
  103. };
  104. case "createMethod":
  105. return function( nodeID, methodName, methodParameters, methodBody, when, callback ) {
  106. this.kernel.send( nodeID, kernelFunctionName, methodName,
  107. [ methodParameters, methodBody ], when || 0, callback /* result */ ); // TODO: { parameters: methodParameters, body: methodBody } ? -- vwf.receive() needs to parse
  108. };
  109. // TODO: deleteMethod
  110. case "setMethod":
  111. return function( nodeID, methodName, methodHandler, when, callback ) {
  112. this.kernel.send( nodeID, kernelFunctionName, methodName,
  113. [ methodHandler ], when || 0, callback /* result */ );
  114. };
  115. case "getMethod":
  116. return function( nodeID, methodName, when, callback ) {
  117. this.kernel.send( nodeID, kernelFunctionName, methodName,
  118. undefined, when || 0, callback /* result */ );
  119. };
  120. case "callMethod":
  121. return function( nodeID, methodName, methodParameters, when, callback ) {
  122. this.kernel.send( nodeID, kernelFunctionName, methodName,
  123. [ methodParameters ], when || 0, callback /* result */ );
  124. };
  125. case "createEvent":
  126. return function( nodeID, eventName, eventParameters, when, callback ) {
  127. this.kernel.send( nodeID, kernelFunctionName, eventName,
  128. [ eventParameters ], when || 0, callback /* result */ );
  129. };
  130. // TODO: deleteEvent
  131. case "addEventListener":
  132. return function( nodeID, eventName, eventHandler, eventContextID, eventPhases, when, callback ) {
  133. this.kernel.send( nodeID, kernelFunctionName, eventName,
  134. [ eventHandler, eventContextID, eventPhases ], when || 0, callback /* result */ );
  135. };
  136. case "removeEventListener":
  137. return function( nodeID, eventName, eventListenerID, when, callback ) {
  138. this.kernel.send( nodeID, kernelFunctionName, eventName,
  139. [ eventListenerID ], when || 0, callback /* result */ );
  140. };
  141. case "flushEventListeners":
  142. return function( nodeID, eventName, eventContextID, when, callback ) {
  143. this.kernel.send( nodeID, kernelFunctionName, eventName,
  144. [ eventContextID ], when || 0, callback /* result */ );
  145. };
  146. case "fireEvent":
  147. return function( nodeID, eventName, eventParameters, when, callback ) {
  148. this.kernel.send( nodeID, kernelFunctionName, eventName,
  149. [ eventParameters ], when || 0, callback /* result */ );
  150. };
  151. case "dispatchEvent":
  152. return function( nodeID, eventName, eventParameters, eventNodeParameters, when, callback ) {
  153. this.kernel.send( nodeID, kernelFunctionName, eventName,
  154. [ eventParameters, eventNodeParameters ], when || 0, callback /* result */ );
  155. };
  156. case "execute":
  157. return function( nodeID, scriptText, scriptType, when, callback ) {
  158. this.kernel.send( nodeID, kernelFunctionName, undefined,
  159. [ scriptText, scriptType ], when || 0, callback /* result */ ); // TODO: { text: scriptText, type: scriptType } ? -- vwf.receive() needs to parse
  160. };
  161. case "random":
  162. return function( nodeID, when, callback ) {
  163. this.kernel.send( nodeID, kernelFunctionName, undefined,
  164. undefined, when || 0, callback /* result */ );
  165. };
  166. case "seed":
  167. return function( nodeID, seed, when, callback ) {
  168. this.kernel.send( nodeID, kernelFunctionName, undefined,
  169. [ seed ], when || 0, callback /* result */ );
  170. };
  171. // -- Read-only functions --------------------------------------------------------------
  172. case "time":
  173. case "client":
  174. case "moniker":
  175. case "application":
  176. case "intrinsics":
  177. case "uri":
  178. case "name":
  179. case "prototype":
  180. case "prototypes":
  181. case "behaviors":
  182. case "ancestors":
  183. case "parent":
  184. case "children":
  185. case "descendants":
  186. case "find":
  187. case "test":
  188. case "findClients":
  189. return function() {
  190. return this.kernel[kernelFunctionName].apply( this.kernel, arguments );
  191. };
  192. }
  193. } );
  194. } );