1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.default = exports.ObservableMap = void 0;
|
5 |
|
6 | var _useForceUpdate = _interopRequireDefault(require("./useForceUpdate"));
|
7 |
|
8 | var _useStableMemo = _interopRequireDefault(require("./useStableMemo"));
|
9 |
|
10 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11 |
|
12 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
13 |
|
14 | function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
|
15 |
|
16 | function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
|
17 |
|
18 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
19 |
|
20 | function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
21 |
|
22 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
23 |
|
24 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
25 |
|
26 | var ObservableMap = function (_Map) {
|
27 | _inheritsLoose(ObservableMap, _Map);
|
28 |
|
29 | function ObservableMap(listener, init) {
|
30 | var _this;
|
31 |
|
32 | _this = _Map.call(this, init) || this;
|
33 | _this.listener = listener;
|
34 | return _this;
|
35 | }
|
36 |
|
37 | var _proto = ObservableMap.prototype;
|
38 |
|
39 | _proto.set = function set(key, value) {
|
40 | _Map.prototype.set.call(this, key, value);
|
41 |
|
42 |
|
43 |
|
44 | if (this.listener) this.listener(this);
|
45 | return this;
|
46 | };
|
47 |
|
48 | _proto.delete = function _delete(key) {
|
49 | var result = _Map.prototype.delete.call(this, key);
|
50 |
|
51 | this.listener(this);
|
52 | return result;
|
53 | };
|
54 |
|
55 | _proto.clear = function clear() {
|
56 | _Map.prototype.clear.call(this);
|
57 |
|
58 | this.listener(this);
|
59 | };
|
60 |
|
61 | return ObservableMap;
|
62 | }( _wrapNativeSuper(Map));
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | exports.ObservableMap = ObservableMap;
|
88 |
|
89 | function useMap(init) {
|
90 | var forceUpdate = (0, _useForceUpdate.default)();
|
91 | return (0, _useStableMemo.default)(function () {
|
92 | return new ObservableMap(forceUpdate, init);
|
93 | }, []);
|
94 | }
|
95 |
|
96 | var _default = useMap;
|
97 | exports.default = _default; |
\ | No newline at end of file |