Giter Site home page Giter Site logo

Comments (14)

hotoo avatar hotoo commented on August 15, 2024

我昨天正好也想到这个话题,直觉现有的 all 的设计是有问题的,但是没细想,准备好好看下代码再说。

from events.

antife-yinyue avatar antife-yinyue commented on August 15, 2024

非得要设计个 all 的话,可以让 all 不接受绑定,只接受触发,这样就避免重复的问题了

from events.

popomore avatar popomore commented on August 15, 2024

有道理,可以再仔细想想,其实我不太喜欢这个 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.

afc163 avatar afc163 commented on August 15, 2024

为啥要有 all ,有人用过吗?

from events.

lepture avatar lepture commented on August 15, 2024

同認為 all 無用

from events.

army8735 avatar army8735 commented on August 15, 2024

从未用过all,虽然觉得*比all更好。唯一能想到的用处是,统计这个事件对象总共触发了多少次事件比较方便。

from events.

hotoo avatar hotoo commented on August 15, 2024

我有过这样的需求,但都是在自己的业务逻辑中实现。
现在仔细想来,这个很容易出问题的 API 由 Events 提供也完全合理。
只是觉得目前的实现方案可能有点问题。

案例

  1. monitor-sens#L57
  2. monitor.js#L190

我的观点

  1. all 事件建议使用 *
  2. all 事件由 Events 提供完全合理。
  3. all 事件应该仔细考虑 onofftrigger 方法,而不是简单屏蔽。

from events.

lifesinger avatar lifesinger commented on August 15, 2024

all 借鉴自 Backbone 的 API: http://backbonejs.org/#Events-catalog
可以用来做事件的路由。

如果我们实际上用不到,可以考虑去除。

from events.

lifesinger avatar lifesinger commented on August 15, 2024

触发两次,好像不是 bug,本身就如此设计的。谁测测 Backbone 目前的逻辑。

from events.

army8735 avatar army8735 commented on August 15, 2024

backbone是两次

from events.

army8735 avatar army8735 commented on August 15, 2024

仔细想了下,还是觉得不应该重复。
如果一个cb同时绑定a和b的话,同时触发a和b就应该是2次。
但all是一个抽象出来的集合,实际上是不存在的。因此一个cb同时存在于all和a的话,触发all相当于包括触发一次a,此时cb被执行2次就不合理了。

from events.

lifesinger avatar lifesinger commented on August 15, 2024

可以考虑去掉 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.

lizzie avatar lizzie commented on August 15, 2024

Validator 中就有使用 all 的例子, see https://github.com/aralejs/validator/blob/master/src/core.js#L182 用来做一次事件的转发~~

虽少, 但还是有的.

from events.

hotoo avatar hotoo commented on August 15, 2024

仔细想并看了代码很久,handler 无所谓同一个还是不同一个。
试想同一个 handler 绑定到同一个事件,触发这个事件时, handler 就应该调用 2次。

结论:现在的逻辑貌似没什么问题。

case 1

on(a, h1);
on(b, h1);
trigger(a);

result:

  1. h1()

case 1'

on(a, h1);
on(b, h1);
trigger(all); // diff.

result:

  1. h1()
  2. h1()

case 2

on(a, h1);
on(all, h1);
trigger(a);

result:

  1. h1()
  2. h1()

case 2‘

on(a, h1);
on(all, h1);
trigger(all);

result:

  1. h1()
  2. h1()

from events.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.