Comments (14)
我昨天正好也想到这个话题,直觉现有的 all 的设计是有问题的,但是没细想,准备好好看下代码再说。
from events.
非得要设计个 all 的话,可以让 all 不接受绑定,只接受触发,这样就避免重复的问题了
from events.
有道理,可以再仔细想想,其实我不太喜欢这个 API ,默认就返回事件名,那么单独绑定后同一个 callback 也能判断了。—
Sent from Mailbox for iPhone
On Sat, Mar 1, 2014 at 12:12 PM, wǒ_is神仙 [email protected] wrote:
非得要设计个 all 的话,可以让 all 不接受绑定,只接受触发,这样就避免重复的问题了
Reply to this email directly or view it on GitHub:
#13 (comment)
from events.
为啥要有 all ,有人用过吗?
from events.
同認為 all 無用
from events.
从未用过all,虽然觉得*比all更好。唯一能想到的用处是,统计这个事件对象总共触发了多少次事件比较方便。
from events.
我有过这样的需求,但都是在自己的业务逻辑中实现。
现在仔细想来,这个很容易出问题的 API 由 Events 提供也完全合理。
只是觉得目前的实现方案可能有点问题。
案例
我的观点
all
事件建议使用*
。all
事件由 Events 提供完全合理。all
事件应该仔细考虑on
、off
和trigger
方法,而不是简单屏蔽。
from events.
all 借鉴自 Backbone 的 API: http://backbonejs.org/#Events-catalog
可以用来做事件的路由。
如果我们实际上用不到,可以考虑去除。
from events.
触发两次,好像不是 bug,本身就如此设计的。谁测测 Backbone 目前的逻辑。
from events.
backbone是两次
from events.
仔细想了下,还是觉得不应该重复。
如果一个cb同时绑定a和b的话,同时触发a和b就应该是2次。
但all是一个抽象出来的集合,实际上是不存在的。因此一个cb同时存在于all和a的话,触发all相当于包括触发一次a,此时cb被执行2次就不合理了。
from events.
可以考虑去掉 all
下周组建一个虚拟项目小组,开始每个组件讨论下,确定修改方案
下周人员我圈定后,找大家 kick off 下
2014-03-08 18:33 GMT+08:00 army8735 [email protected]:
仔细想了下,还是觉得不应该重复。
如果一个cb同时绑定a和b的话,同时触发a和b就应该是2次。
但all是一个抽象出来的集合,实际上是不存在的。因此一个cb同时存在于all和a的话,触发all相当于包括触发一次a,此时cb被执行2次就不合理了。—
Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-37094528
.
王保平 / 玉伯(射雕)
送人玫瑰手有余香
from events.
Validator 中就有使用 all
的例子, see https://github.com/aralejs/validator/blob/master/src/core.js#L182 用来做一次事件的转发~~
虽少, 但还是有的.
from events.
仔细想并看了代码很久,handler 无所谓同一个还是不同一个。
试想同一个 handler 绑定到同一个事件,触发这个事件时, handler 就应该调用 2次。
结论:现在的逻辑貌似没什么问题。
case 1
on(a, h1);
on(b, h1);
trigger(a);
result:
h1()
case 1'
on(a, h1);
on(b, h1);
trigger(all); // diff.
result:
h1()
h1()
case 2
on(a, h1);
on(all, h1);
trigger(a);
result:
h1()
h1()
case 2‘
on(a, h1);
on(all, h1);
trigger(all);
result:
h1()
h1()
from events.
Related Issues (20)
- 关于trigger时异常处理的建议 HOT 24
- trigger('all') 所绑定的事件会调用两次 HOT 4
- Events 不应该提供 mixTo 方法。 HOT 2
- element 想实例化 以后 再生成 HOT 2
- trigger 触发的是所有实例上的on绑定么? HOT 15
- 关于事件重复绑定及解绑 HOT 2
- 'args' is defined but never used
- 注册事件时可否支持defer回调 HOT 2
- IE6-8 不支持Object.keys Array.forEach HOT 14
- event mixto 不兼容IE7 HOT 2
- 代码应该有兼容问题 IE8- 直接报错吧 HOT 1
- 先trigger,然后on的时候可以改成触发事件吗 HOT 3
- 关于回调函数截取效率的问题 HOT 2
- 是否有必要添加这样一种事件类别 HOT 5
- trigger 返回值为 callback 的状态 HOT 1
- 增加 once HOT 11
- 绑定多事件时无法获得触发的事件名 HOT 4
- mixTo 的一点问题 HOT 4
- 别名 emit
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from events.