ProductService.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _react = _interopRequireDefault(require("react"));
  7. var _modularityFront = _interopRequireDefault(require("modularity-front"));
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  10. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  12. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  13. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  14. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  15. function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
  16. function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
  17. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  18. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  19. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  20. var ProductService =
  21. /*#__PURE__*/
  22. function (_Modularity$Service) {
  23. _inherits(ProductService, _Modularity$Service);
  24. function ProductService(props) {
  25. var _this;
  26. _classCallCheck(this, ProductService);
  27. _this = _possibleConstructorReturn(this, _getPrototypeOf(ProductService).call(this, props));
  28. _this.loadProduct(1);
  29. _this.input.onUpdate(function (v) {
  30. _this.loadProduct(v);
  31. }); //inputs key,function,regex
  32. _this.RoutingSystem.onRouteChange('ProductService', function () {
  33. var query = _this.RoutingSystem.getRoute();
  34. console.log("yeeueyye");
  35. if (query.params) {
  36. console.log(query.params.id);
  37. _this.loadProduct(query.params.id);
  38. }
  39. }, '/product/[0-9]+');
  40. _this.RoutingSystem.onRouteChange('ProductService', function () {
  41. console.log("something");
  42. }, '/products/[0-9]+');
  43. return _this;
  44. }
  45. _createClass(ProductService, [{
  46. key: "loadProduct",
  47. value: function loadProduct(v) {
  48. var _this2 = this;
  49. fetch('/products/' + v).then(function (results) {
  50. return results.json();
  51. }).then(function (json) {
  52. return _this2.product.set(json);
  53. }).catch(function (e) {
  54. console.log(e);
  55. });
  56. }
  57. }, {
  58. key: "render",
  59. value: function render() {
  60. var _this3 = this;
  61. return _react.default.createElement("div", {
  62. className: "ServiceInfo"
  63. }, "ID : ", this.__renderID(), _react.default.createElement("div", null, "Data", _react.default.createElement("div", null, _react.default.createElement("input", {
  64. type: "text",
  65. onChange: function onChange(e) {
  66. return _this3.loadProduct(e.target.value);
  67. },
  68. name: ""
  69. })), _react.default.createElement(_modularityFront.default.ModuleUtilities.OutputLink, {
  70. output: this.product
  71. }), _get(_getPrototypeOf(ProductService.prototype), "render", this).call(this)));
  72. }
  73. }]);
  74. return ProductService;
  75. }(_modularityFront.default.Service);
  76. ProductService.Outputs = {
  77. product: {},
  78. string: {}
  79. };
  80. ProductService.Inputs = {
  81. input: {
  82. type: _modularityFront.default.Module.Types.Number
  83. }
  84. };
  85. ProductService.Category = "Services";
  86. var _default = ProductService;
  87. exports.default = _default;