utility.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. "use strict";
  2. // Copyright 2014 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 utility functions and objects.
  15. ///
  16. /// @module vwf/kernel/utility
  17. define( [ "module" ], function( module ) {
  18. var exports = {
  19. /// ID of the pseudo node that appears as the parent of the simulation's global nodes.
  20. ///
  21. /// @field
  22. globalRootID: 0,
  23. /// The URI of the VWF proto-prototype node `node.vwf`. `protoNodeDescriptor` contains the
  24. /// descriptor associated with this URI.
  25. ///
  26. /// @field
  27. protoNodeURI: "http://vwf.example.com/node.vwf",
  28. /// The component descriptor of the VWF proto-prototype node `node.vwf`.
  29. ///
  30. /// @field
  31. protoNodeDescriptor: { extends: null }, // TODO: detect protoNodeDescriptor in createChild() a different way and remove this explicit null prototype
  32. /// Wrap `nodeID` in an object in such a way that it can stand in for a node reference
  33. /// without being confused with any other application value. The returned object will
  34. /// contain `nodeID` in the `id` field. `valueIsNodeReference` may be used to determine if
  35. /// an arbitrary value is such a node reference.
  36. ///
  37. /// @param {ID} nodeID
  38. ///
  39. /// @returns {Object}
  40. nodeReference: function( nodeID ) {
  41. return Object.create( nodeReferencePrototype, {
  42. id: { value: nodeID } // TODO: same wrapper for same id so that === works
  43. } );
  44. },
  45. /// Determine if a value is a node reference. If it is, it will contain the `nodeID` in the
  46. /// `id` field.
  47. ///
  48. /// @param {Object} value
  49. ///
  50. /// @returns {Boolean}
  51. valueIsNodeReference: function( value ) {
  52. return nodeReferencePrototype.isPrototypeOf( value );
  53. },
  54. };
  55. /// The key prototype for application values that reference nodes.
  56. ///
  57. /// Application values that reference VWF nodes are objects of the form `{ id: id }` that also
  58. /// extend this object. Application values include property values, method parameters and
  59. /// results, and event listener parameters.
  60. ///
  61. /// `nodeReferencePrototype` serves as a key to distinguish real node references from other
  62. /// arbitrary values.
  63. ///
  64. /// @field
  65. var nodeReferencePrototype = {};
  66. // Return the module.
  67. return exports;
  68. } );