1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6 |
|
7 | var slicedToArray = require('./slicedToArray-0711941d.js');
|
8 | require('./unsupportedIterableToArray-68db1d3b.js');
|
9 | var React = require('react');
|
10 | var React__default = _interopDefault(React);
|
11 |
|
12 | function initContainsComponent() {
|
13 | var ContainsContext = React__default.createContext({
|
14 | contains: false
|
15 | });
|
16 | return {
|
17 |
|
18 |
|
19 |
|
20 | Provider: function Provider(_ref) {
|
21 | var children = _ref.children;
|
22 |
|
23 | var _useState = React.useState(0),
|
24 | _useState2 = slicedToArray._slicedToArray(_useState, 2),
|
25 | count = _useState2[0],
|
26 | setCount = _useState2[1];
|
27 |
|
28 | var contextValue = React.useMemo(function () {
|
29 | return {
|
30 | updateCount: function updateCount(diff) {
|
31 | setCount(function (count) {
|
32 | return count + diff;
|
33 | });
|
34 | },
|
35 | contains: count > 0
|
36 | };
|
37 | }, [count]);
|
38 | return React__default.createElement(ContainsContext.Provider, {
|
39 | value: contextValue
|
40 | }, children);
|
41 | },
|
42 |
|
43 |
|
44 |
|
45 | useContains: function useContains() {
|
46 | return React.useContext(ContainsContext).contains;
|
47 | },
|
48 |
|
49 | useRegister: function useRegister() {
|
50 | var _useContext = React.useContext(ContainsContext),
|
51 | updateCount = _useContext.updateCount;
|
52 |
|
53 | React.useEffect(function () {
|
54 | if (!updateCount) {
|
55 | return;
|
56 | }
|
57 |
|
58 | updateCount(1);
|
59 | return function () {
|
60 | updateCount(-1);
|
61 | };
|
62 |
|
63 | }, []);
|
64 | }
|
65 | };
|
66 | }
|
67 |
|
68 | exports.initContainsComponent = initContainsComponent;
|
69 |
|