* Checks if a given mutation record is relevant for resyncing a . * In general its relevant if: * - Non comment content of the select changed * - The value attribute of an option changed.
(mutation: MutationRecord)
| 51 | * - The value attribute of an option changed. |
| 52 | */ |
| 53 | function isRelevantSelectMutation(mutation: MutationRecord) { |
| 54 | // Consider changes that may add / remove options, or change their text content. |
| 55 | if (mutation.type === 'childList' || mutation.type === 'characterData') { |
| 56 | // If the target element is a comment it's not relevant. |
| 57 | if (mutation.target instanceof Comment) { |
| 58 | return false; |
| 59 | } |
| 60 | // Otherwise if any non-comment nodes were added / removed it is relevant. |
| 61 | for (const node of mutation.addedNodes) { |
| 62 | if (!(node instanceof Comment)) { |
| 63 | return true; |
| 64 | } |
| 65 | } |
| 66 | for (const node of mutation.removedNodes) { |
| 67 | if (!(node instanceof Comment)) { |
| 68 | return true; |
| 69 | } |
| 70 | } |
| 71 | // Otherwise it's not relevant. |
| 72 | return false; |
| 73 | } |
| 74 | // If the value attribute of an option changed, it's relevant. |
| 75 | if (mutation.type === 'attributes' && mutation.target instanceof HTMLOptionElement) { |
| 76 | return true; |
| 77 | } |
| 78 | // Everything else is not relevant. |
| 79 | return false; |
| 80 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…