Skip to content

Allow unbind for eve.once #22

@trokster

Description

@trokster

Couldn't find a clean way to do it so my approach is to pass in a third variable ( array or pointer ) then modify eve.once to assign f2 to that variable, so i can unsub with eve.off("evt", f2).

eve.once = function (name, f, unbinder) {
var f2 = function () {
eve.unbind(name, f2);
return f.apply(this, arguments);
};
if(unbinder) unbinder.push(f2);
return eve.on(name, f2);
};

It's absolutely ugly but does the job for now. Does anyone have a cleaner way to implement ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions