1 | import { arraysEqual } from './array';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | var createResolver = function (local) { return function (newValue) {
|
7 | for (var _i = 0, _a = local.refs; _i < _a.length; _i++) {
|
8 | var ref = _a[_i];
|
9 | if (typeof ref === 'function') {
|
10 | ref(newValue);
|
11 | }
|
12 | else if (ref) {
|
13 |
|
14 | ref.current = newValue;
|
15 | }
|
16 | }
|
17 | }; };
|
18 |
|
19 |
|
20 |
|
21 | export var createMergedRef = function (value) {
|
22 | var local = {
|
23 | refs: [],
|
24 | };
|
25 | return function () {
|
26 | var newRefs = [];
|
27 | for (var _i = 0; _i < arguments.length; _i++) {
|
28 | newRefs[_i] = arguments[_i];
|
29 | }
|
30 | if (!local.resolver || !arraysEqual(local.refs, newRefs)) {
|
31 | local.resolver = createResolver(local);
|
32 | }
|
33 | local.refs = newRefs;
|
34 | return local.resolver;
|
35 | };
|
36 | };
|
37 |
|
\ | No newline at end of file |