Skip to content

Cannot one() recursively #121

@fabiosantoscode

Description

@fabiosantoscode

A bean.one(elm, type, handler) handler cannot itself invoke bean.one with the same element, type and function. Here's an example where I listen for one mousemove event, and in the handler decide to listen for another mousemove event, but the handler never comes along.

http://jsbin.com/hobaya/1/edit?html,js,output

Result: my handler is called only for the first mousemove event
Expected: my handler should be called every time there is a mousemove event, since I explicitly listened to it again.

I figured out a workaround, which is to listen to a copy of the function. That produces the same effect because the copy !== the original function.

http://jsbin.com/fosuvi/1/edit?html,js,output

Alternatively, using setImmediate or setTimeout to move the one() call outside the call stack that resulted in calling the handler also works.

http://jsbin.com/fepada/1/edit?html,js,output

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions