Skip to content

Commit ab1a699

Browse files
authored
Update article.md
1 parent e7c0145 commit ab1a699

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

2-ui/2-events/05-dispatch-events/article.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,15 @@ alert(event.clientX); // undefined, the unknown property is ignored!
205205

206206
## Events-in-events are synchronous
207207

208-
Usually events are processed in a queue. That is: if the browser is processing `onclick` and a new event occurs, e.g. mouse moved, then its handling is queued up, corresponding `mousemove` handlers will be called after `onclick` processing is finished.
208+
معمولا رویدادها در یک صف پردازش می شوند. یعنی: اگر مرورگر در حال پردازش `onclick` باشد و یک رویداد جدید رخ دهد، به عنوان مثال: ماوس حرکت می کند، سپس handling آن در صف قرار می گیرد، پس از اتمام پردازش `onclick`، کنترل کننده های مربوط به `mousemove` فراخوانی می شوند.
209209

210-
The notable exception is when one event is initiated from within another one, e.g. using `dispatchEvent`. Such events are processed immediately: the new event handlers are called, and then the current event handling is resumed.
210+
استثنا قابل توجه زمانی است که یک رویداد از درون رویداد دیگری آغاز می شود، به عنوان مثال: با استفاده از `dispatchEvent` چنین رویدادهایی بلافاصله پردازش می‌شوند: کنترل‌کننده‌های رویداد جدید فراخوانی می‌شوند و سپس مدیریت رویداد فعلی از سر گرفته می‌شود.
211211

212-
For instance, in the code below the `menu-open` event is triggered during the `onclick`.
212+
به عنوان مثال، در کد زیر، رویداد `menu-open` در حین کلیک فعال می شود.
213213

214-
It's processed immediately, without waiting for `onclick` handler to end:
214+
بلافاصله پردازش می شود، بدون اینکه منتظر پایان کنترل کننده `onclick` باشد:
215215

216+
بدون اینکه برای `onclick` handler صبر کند تا تمام شود، شروع به process شدن میشود:
216217

217218
```html run autorun
218219
<button id="menu">Menu (click me)</button>
@@ -233,15 +234,15 @@ It's processed immediately, without waiting for `onclick` handler to end:
233234
</script>
234235
```
235236

236-
The output order is: 1 -> nested -> 2.
237+
ترتیب خروجی این است: 1 -> nested -> 2.
237238

238-
Please note that the nested event `menu-open` is caught on the `document`. The propagation and handling of the nested event is finished before the processing gets back to the outer code (`onclick`).
239+
لطفاً توجه داشته باشید که منوی رویداد تودرتو که باز است در `document` وجود دارد. انتشار و مدیریت رویداد تودرتو قبل از اینکه پردازش به کد خارجی بازگردد (`onclick`) به پایان می رسد.
239240

240-
That's not only about `dispatchEvent`, there are other cases. If an event handler calls methods that trigger other events -- they are processed synchronously too, in a nested fashion.
241+
این فقط مربوط به `dispatchEvent` نیست، موارد دیگری نیز وجود دارد. اگر یک کنترل کننده رویداد متدهایی را فراخوانی کند که رویدادهای دیگر را راه‌اندازی می‌کنند، آنها نیز به صورت همزمان و به صورت تودرتو پردازش می‌شوند.
241242

242-
Let's say we don't like it. We'd want `onclick` to be fully processed first, independently from `menu-open` or any other nested events.
243+
بیایید بگوییم که آن را دوست نداریم. ما می خواهیم ابتدا `onclick` به طور کامل پردازش شود، مستقل از `menu-open` یا هر رویداد تو در تو.
243244

244-
Then we can either put the `dispatchEvent` (or another event-triggering call) at the end of `onclick` or, maybe better, wrap it in the zero-delay `setTimeout`:
245+
سپس می‌توانیم `dispatchEvent` (یا یک تماس event-triggering) را در انتهای `onclick` قرار دهیم یا، شاید بهتر، آن را در `setTimeout` با تاخیر صفر قرار دهیم:
245246

246247
```html run
247248
<button id="menu">Menu (click me)</button>
@@ -260,10 +261,11 @@ Then we can either put the `dispatchEvent` (or another event-triggering call) at
260261
document.addEventListener('menu-open', () => alert('nested'));
261262
</script>
262263
```
264+
حالا `dispatchEvent` یه صورت asynchronously بعد از اینکه اجرای کد فعلی به اتمام رسید، run میشود، که شامل `menu.onclick`. پس event handler ها به صورت جدت و مستقل فعالیت میکنند.
265+
266+
خروجی خ.اهد بود:1 -> 2 -> nested.
263267

264-
Now `dispatchEvent` runs asynchronously after the current code execution is finished, including `menu.onclick`, so event handlers are totally separate.
265268

266-
The output order becomes: 1 -> 2 -> nested.
267269

268270
## Summary
269271

0 commit comments

Comments
 (0)