1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | var React = require('react');
|
14 |
|
15 | var areEqual = require("fbjs/lib/areEqual");
|
16 |
|
17 | var useMemo = React.useMemo,
|
18 | useRef = React.useRef,
|
19 | useState = React.useState;
|
20 |
|
21 | function useMemoVariables(variables) {
|
22 | var _variablesChangedGene2;
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | var variablesChangedGenerationRef = useRef(0);
|
29 |
|
30 | var _useState = useState(variables),
|
31 | mirroredVariables = _useState[0],
|
32 | setMirroredVariables = _useState[1];
|
33 |
|
34 | var variablesChanged = !areEqual(variables, mirroredVariables);
|
35 |
|
36 | if (variablesChanged) {
|
37 | var _variablesChangedGene;
|
38 |
|
39 | variablesChangedGenerationRef.current = ((_variablesChangedGene = variablesChangedGenerationRef.current) !== null && _variablesChangedGene !== void 0 ? _variablesChangedGene : 0) + 1;
|
40 | setMirroredVariables(variables);
|
41 | }
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | var memoVariables = useMemo(function () {
|
47 | return variables;
|
48 | }, [variablesChangedGenerationRef.current]);
|
49 | return [memoVariables, (_variablesChangedGene2 = variablesChangedGenerationRef.current) !== null && _variablesChangedGene2 !== void 0 ? _variablesChangedGene2 : 0];
|
50 | }
|
51 |
|
52 | module.exports = useMemoVariables; |
\ | No newline at end of file |