1 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
|
2 |
|
3 | 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); }
|
4 |
|
5 | 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); }
|
6 |
|
7 | 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; } }
|
8 |
|
9 | function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
|
10 |
|
11 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
12 |
|
13 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
14 |
|
15 | import useForceUpdate from './useForceUpdate';
|
16 | import useStableMemo from './useStableMemo';
|
17 | export var ObservableSet = function (_Set) {
|
18 | _inheritsLoose(ObservableSet, _Set);
|
19 |
|
20 | function ObservableSet(listener, init) {
|
21 | var _this;
|
22 |
|
23 | _this = _Set.call(this, init) || this;
|
24 | _this.listener = listener;
|
25 | return _this;
|
26 | }
|
27 |
|
28 | var _proto = ObservableSet.prototype;
|
29 |
|
30 | _proto.add = function add(value) {
|
31 | _Set.prototype.add.call(this, value);
|
32 |
|
33 |
|
34 |
|
35 | if (this.listener) this.listener(this);
|
36 | return this;
|
37 | };
|
38 |
|
39 | _proto.delete = function _delete(value) {
|
40 | var result = _Set.prototype.delete.call(this, value);
|
41 |
|
42 | this.listener(this);
|
43 | return result;
|
44 | };
|
45 |
|
46 | _proto.clear = function clear() {
|
47 | _Set.prototype.clear.call(this);
|
48 |
|
49 | this.listener(this);
|
50 | };
|
51 |
|
52 | return ObservableSet;
|
53 | }( _wrapNativeSuper(Set));
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | function useSet(init) {
|
75 | var forceUpdate = useForceUpdate();
|
76 | return useStableMemo(function () {
|
77 | return new ObservableSet(forceUpdate, init);
|
78 | }, []);
|
79 | }
|
80 |
|
81 | export default useSet; |
\ | No newline at end of file |