function.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. "use strict";
  6. // Make this available to both AMD and CJS environments
  7. define(function (require, exports, module) {
  8. // ReactJS
  9. const React = require("devtools/client/shared/vendor/react");
  10. // Reps
  11. const { isGrip, cropString } = require("./rep-utils");
  12. // Shortcuts
  13. const { span } = React.DOM;
  14. /**
  15. * This component represents a template for Function objects.
  16. */
  17. let Func = React.createClass({
  18. displayName: "Func",
  19. propTypes: {
  20. object: React.PropTypes.object.isRequired
  21. },
  22. getTitle: function (grip) {
  23. if (this.props.objectLink) {
  24. return this.props.objectLink({
  25. object: grip
  26. }, "function ");
  27. }
  28. return "";
  29. },
  30. summarizeFunction: function (grip) {
  31. let name = grip.userDisplayName || grip.displayName || grip.name || "function";
  32. return cropString(name + "()", 100);
  33. },
  34. render: function () {
  35. let grip = this.props.object;
  36. return (
  37. // Set dir="ltr" to prevent function parentheses from
  38. // appearing in the wrong direction
  39. span({dir: "ltr", className: "objectBox objectBox-function"},
  40. this.getTitle(grip),
  41. this.summarizeFunction(grip)
  42. )
  43. );
  44. },
  45. });
  46. // Registration
  47. function supportsObject(grip, type) {
  48. if (!isGrip(grip)) {
  49. return (type == "function");
  50. }
  51. return (type == "Function");
  52. }
  53. // Exports from this module
  54. exports.Func = {
  55. rep: Func,
  56. supportsObject: supportsObject
  57. };
  58. });