Lädt...


🔧 How to write elegant code 1: Keep the chain of event calls short


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

The chain of event calls

There are some scenarios we keep throw up the event to the parent component. Then it handle the event in the component far way from the component which raise the event

Image description

This has the following disadvantages

  • Switching between different component source code increase the difficulty of developing
  • We coupling deeply these components. The architecture is fragile. If there is a component updated might break the event chain

If we calculate the distance of event calls chain in this way:

  • when the event is handled in the same component which fire it, the distance is 0
  • if the event if handled in the parent component we plus 1 to the distance. For example, the event is handled by the parent component, the distance is 1

In the example above, the distance is 3

Image description

The code is hard to read if the distance is larger than 1. If it’s 3, you will need to switch 4 files to read the event call chain completely.

How to fix it

Put the even handler beside the event listener

Questions

  • Q: Will this cause a lot of duplicate code? A: No. we can extract common code to composable or component to reuse the same code.
  • Q: Will this create a lot of duplicate components like modals? A: No, make sure the component only be created when it's needed. For example if you are using Vue.js use v-if instead of v-show for modal component to make sure it won’t be rendered when no needed. Also, use private variable instead of global variable to control if the modal is shown to make sure the toggle method will only trigger 1 modal to be open or close.
...

🔧 How to write elegant code 1: Keep the chain of event calls short


📈 69.26 Punkte
🔧 Programmierung

🔧 What Is Elegant Code? (aka Elegant Solutions For Everyday Python Problems)


📈 36.44 Punkte
🔧 Programmierung

🔧 KISS Principle: Giữ Mọi Thứ Đơn Giản Nhất Có Thể


📈 31.23 Punkte
🔧 Programmierung

🔧 Có thể bạn chưa biết (Phần 1)


📈 31.23 Punkte
🔧 Programmierung

🔧 Tìm Hiểu Về RAG: Công Nghệ Đột Phá Đang "Làm Mưa Làm Gió" Trong Thế Giới Chatbot


📈 31.23 Punkte
🔧 Programmierung

🔧 How To Write Elegant Code with C# Pattern Matching


📈 26.71 Punkte
🔧 Programmierung

🔧 How To Write Elegant Code with C# Switch Expressions


📈 26.71 Punkte
🔧 Programmierung

🪟 Lenovo's Yoga 9i 2-in-1 is 'just short of a masterpiece,' and its new price is just short of jaw dropping


📈 22.79 Punkte
🪟 Windows Tipps

🎥 The brief said short so she made the story short 🎯 #Shorts


📈 22.79 Punkte
🎥 Video | Youtube

🔧 Rust Clean Code: Crafting Elegant, Efficient, and Maintainable Software


📈 19.79 Punkte
🔧 Programmierung

🔧 Observables in Node.js: Transforming Asynchronous Chaos into Elegant Code


📈 19.79 Punkte
🔧 Programmierung

🔧 How I automated all the elegant 🥱 code required to extend a feature 🧑‍💻


📈 19.79 Punkte
🔧 Programmierung

🔧 Art of Code: Elegant Solutions in Software Development


📈 19.79 Punkte
🔧 Programmierung

🔧 Daily Standup Meeting: Ways To Keep It Short and Effective


📈 19.62 Punkte
🔧 Programmierung

📰 Short and Sweet: Enhancing LLM Performance with Constrained Chain-of-Thought


📈 19.48 Punkte
🔧 AI Nachrichten

🕵️ Using AI to write Malware?! (Short Film on the ethical reasoning)


📈 18.31 Punkte
🕵️ Reverse Engineering

🐧 [REQUEST] a short write up on kernel development for newbie kernel developers


📈 18.31 Punkte
🐧 Linux Tipps

📰 Microsoft Teams Calls Not Ringing on Incoming Calls [FIXED]


📈 18.01 Punkte
🖥️ Betriebssysteme

📰 Washington Post Writer Calls 2019 'The Year of OK Boomer', Calls for Inter-Generational Kindness


📈 18.01 Punkte
📰 IT Security Nachrichten

🪟 X introduces video and audio calls on Android; receive calls for free but pay to make


📈 18.01 Punkte
🪟 Windows Tipps

🐧 How To Make Voice Calls and Video Calls From WhatsApp Desktop App?


📈 18.01 Punkte
🐧 Linux Tipps

🔧 Advanced Event Handling in JavaScript: Custom Events, Event Delegation, and Event Loop


📈 17.53 Punkte
🔧 Programmierung

📰 Nach dem Event ist vor dem Event: Google lädt die größten Fans zu einem speziellen Pixel-Event ein


📈 17.53 Punkte
📰 IT Nachrichten

📰 7 Ways to Keep Your Online Calls Encrypted and Secured


📈 17.23 Punkte
📰 IT Security Nachrichten

📰 Zuckerberg Calls To Keep Building To 'Bring People Together,' Despite User Data Crisis


📈 17.23 Punkte
📰 IT Security Nachrichten

📰 Apple Calls For FCC To Keep 'Strong, Enforceable' Net Neutrality Protections


📈 17.23 Punkte
📰 IT Security Nachrichten

🍏 Apple calls on global supply chain to decarbonize by 2030


📈 17.09 Punkte
🍏 iOS / Mac OS

🔧 Use VSCode to write Terraform? AWS AI can now help you write your code!


📈 16.98 Punkte
🔧 Programmierung

🍏 Radiola: Ein elegant-einfacher Onlineradioplayer für den Mac


📈 16.65 Punkte
🍏 iOS / Mac OS

matomo