UNPKG

react-js-plugins

Version:

A powerful and efficient React utility library designed to enhance application performance by streamlining and simplifying the management of complex asynchronous operations.

59 lines (58 loc) 2.06 kB
/** * @license HEXE * Copyright (c) 2020-2024 Shivaji & Collaborators * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import React from 'react'; var HEXE = /** @class */ (function () { function HEXE() { this.hs = {}; this.ss = {}; this.setHook = this.setHook.bind(this); this.getHook = this.getHook.bind(this); this.putHooks = this.putHooks.bind(this); } HEXE.prototype.setHook = function (name, hookFunction) { [ { value: name, id: 'name', type: 'string' }, { value: hookFunction, id: 'hook', type: 'function' }, ].forEach(function (_a) { var value = _a.value, id = _a.id, type = _a.type; if (type === 'string' && typeof value !== 'string') { throw new TypeError("\"".concat(id, "\" expected to be of type ").concat(type)); } if (type === 'function' && typeof value !== 'function') { throw new TypeError("\"".concat(id, "\" expected to be of type ").concat(type)); } }); this.hs[name] = { name: name, hook: hookFunction, }; return this; }; HEXE.prototype.putHooks = function (name, value) { this.ss[name] = value; }; HEXE.prototype.component = function () { var _this = this; /* Author: Shivaji & Shyamal */ var Component = function () { Object.values(_this.hs).forEach(function (_a) { var name = _a.name, hook = _a.hook; _this.putHooks(name, hook()); }); return /*#__PURE__*/ React.createElement(React.Fragment, null); }; return Component; }; HEXE.prototype.getHook = function (name) { return this.ss[name]; }; return HEXE; }()); var o = new HEXE(); var ReactHooksWrapper = o.component(); var getHook = o.getHook, setHook = o.setHook; export { ReactHooksWrapper, getHook, setHook };