Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP1universalStack: JavaScript/TypeScript
eventsdomperformancethird-party
Prefer a library's native events over DOM observers
When an editor or widget exposes an update/change event, subscribe to it instead of polling or watching the DOM with a MutationObserver.
PR: hegnar-zephr-components · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const observer = new MutationObserver(() => updateContent()); |
| 2 | observer.observe(editorDiv, { childList: true, subtree: true }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | editor.on('update', ({ editor }) => updateContent(editor.getHTML())); |
Explanation (EN)
Objašnjenje (HR)