• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tbranyen / diffhtml / 12189631411

05 Dec 2024 11:09PM CUT coverage: 98.581%. Remained the same
12189631411

Pull #349

github

web-flow
Merge 3ee60590a into f25d1c4ac
Pull Request #349: Bump path-to-regexp and express in /packages/diffhtml-static-sync

840 of 896 branches covered (93.75%)

4795 of 4864 relevant lines covered (98.58%)

427.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.44
/packages/diffhtml-components/lib/lifecycle/invoke-refs.js
1
import { EMPTY, ComponentTreeCache, InstanceCache, VTree } from '../util/types';
2✔
2
import diff from '../util/binding';
2✔
3

2✔
4
const { Internals } = diff;
2✔
5

2✔
6
/**
2✔
7
 * @param {any} target
2✔
8
 * @param {VTree} vTree
2✔
9
 * @param {HTMLElement | VTree | null=} value
2✔
10
 */
2✔
11
export const invokeRef = (target = EMPTY.OBJ, vTree, value) => {
2✔
12
  let { ref } = target.props || target;
173✔
13

173✔
14
  // Allow refs to be passed to HTML elements. When in a DOM environment
173✔
15
  // a Node will be passed to the ref function and assigned.
173✔
16
  if (!ref) {
173✔
17
    target = Internals.NodeCache.get(vTree);
146✔
18
    ref = vTree.attributes.ref;
146✔
19
  }
146✔
20

173✔
21
  // Only backfill the value with target if no value was provided (either null
173✔
22
  // or a truthy value).
173✔
23
  if (value === undefined) {
173✔
24
    value = target;
129✔
25
  }
129✔
26

173✔
27
  if (typeof ref === 'function') {
173✔
28
    ref(value);
30✔
29
  }
30✔
30
  else if (typeof ref === 'object' && ref) {
143!
31
    ref.current = value;
×
32
  }
×
33
  else if (typeof ref === 'string') {
143!
34
    target.refs = { ...target.refs, [ref]: value };
×
35
  }
×
36
};
2✔
37

2✔
38
/**
2✔
39
 * @param {VTree} vTree - Element to start search, crawl for refs to invoke
2✔
40
 * @param {HTMLElement | VTree | null} value - Value to populate ref with
2✔
41
 */
2✔
42
export function invokeRefsForVTree(vTree, value) {
2✔
43
  const componentTree = ComponentTreeCache.get(vTree);
44✔
44

44✔
45
  if (vTree.childNodes.length) {
44✔
46
    vTree.childNodes.filter(Boolean).forEach(childNode => {
10✔
47
      invokeRefsForVTree(childNode, value);
18✔
48
    });
10✔
49
  }
10✔
50

44✔
51
  const instance = InstanceCache.get(componentTree || vTree);
44✔
52

44✔
53
  if (!instance) {
44✔
54
    invokeRef(Internals.NodeCache.get(vTree), vTree, value);
41✔
55
    return;
41✔
56
  }
41✔
57

3✔
58
  // If any instances exist, loop through them and invoke the respective `ref`
3✔
59
  // logic.
3✔
60
  invokeRef(instance, vTree, value);
3✔
61
}
44✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc