UNPKG

re-use-form

Version:

Easy-to-use React form hooks with built-in validation support

45 lines (32 loc) 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } var WeakMapCache = /*#__PURE__*/function () { function WeakMapCache(enabled) { _classCallCheck(this, WeakMapCache); this.enabled = enabled; this.cache = {}; } _createClass(WeakMapCache, [{ key: "fetch", value: function fetch(path, handler, fn) { if (!this.enabled) return fn(); if (!(path in this.cache)) { this.cache[path] = new WeakMap(); } var cached = this.cache[path].get(handler); if (!cached) { cached = fn(); this.cache[path].set(handler, cached); } return cached; } }]); return WeakMapCache; }(); exports["default"] = WeakMapCache;