前端框架Aurelia - Delegate vs Trigger

本文介绍了事件委托(event delegation)技术,该技术通过利用DOM事件的冒泡特性,将多个元素的事件处理集中到一个顶级节点,从而提高应用性能。并详细说明了在哪些情况下应使用事件触发(trigger)而非事件委托。

1.When use which

The short answer is:  Use delegate except when you cannot use delegate.
哈哈哈哈写文档的真的太可爱了。

Event delegation is a technique used to improve application performance. It drastically reduces the number of event subscriptions by leveraging the "bubbling" characteristic of most DOM events. With event delegation, handlers are not attached to individual elements. Instead, a single event handler is attached to a top-level node such as the body element. When an event bubbles up to this shared top-level handler the event delegation logic calls the appropriate handler based on the event's target .

意思是用delegate是为了减少事件订阅,一个event handler会被attach to一个顶级的node比如说body。
当时间冒泡到顶级的handler时候会根据event的target来调用合适的handler。

 Once you're on the event's MDN page, check whether the event bubbles. Only events that bubble can be used with Aurelia's delegate binding command. The blurfocusload and unload events do not bubble so you'll need to use the trigger binding command to subscribe to these events.

只有可以冒泡的事件才能使用Aurelia的绑定delegate。
blur,focus,load,unload并不能事件冒泡所以不能用delegate只能用trigger。

Use trigger on buttons when the following conditions are met:
  1. You need to disable the button.
  2. The button's content is made up of other elements (as opposed to just text).
This will ensure clicks on disabled button's children won't bubble up to the delegate event handler.

注意: 下面两种情况请在button上使用trigger
1.想要disable这个button
2.这个button的内容是由其他内容组成,而不仅仅只是text。
这会保证disabled button children上的点击不会冒泡到delegate event handler。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值