您的位置:首页 > Web前端

前端框架Aurelia - Delegate vs Trigger

2017-03-23 20:05 375 查看

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 
blur
focus
load
 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:

You need to disable the button.
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。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Aurelia Delegate Trigger