Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mark-5/p5-backbone-events
a port of the Backbone.js event API
https://github.com/mark-5/p5-backbone-events
perl
Last synced: about 1 month ago
JSON representation
a port of the Backbone.js event API
- Host: GitHub
- URL: https://github.com/mark-5/p5-backbone-events
- Owner: mark-5
- Created: 2015-08-29T18:47:05.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-07T05:19:41.000Z (over 9 years ago)
- Last Synced: 2023-06-03T04:11:35.398Z (over 1 year ago)
- Topics: perl
- Language: Perl
- Size: 180 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NAME
Backbone::Events - a port of the Backbone.js event API
# VERSION
version 0.0.3
# SYNOPSIS
package MyProducer {
use Moo;
with 'Backbone::Events';
};
my $pub = MyProducer->new;package MySubscriber {
use Moo;
with 'Backbone::Events';
};
my $sub = MySubscriber->new;$sub->listen_to($pub, 'some-event', sub { ... })
...
$pub->trigger('some-event', qw(args for callback));# DESCRIPTION
Backbone::Events is a Moo::Role which provides a simple interface for binding
and triggering custom named events. Events do not have to be declared before
they are bound, and may take passed arguments.Events can be optionally namespaced by prepending the event with the
namespace: '$namespace:$event'.# METHODS
## on($event, $callback)
Bind a callback to an object.
Callbacks bound to the special 'all' event will be triggered when any event
occurs, and are passed the name of the event as the first argument.Returns the callback that was passed. This is mainly so anonymous functions
can be returned, and later passed back to 'off'.## off(\[$event\], \[$callback\])
Remove a previously-bound callback from an object.
## trigger($event, @args)
Trigger callbacks for the given event.
## once($event, $callback)
Just like 'on', but causes the bound callback to fire only once before being
removed.Returns the callback that was passed. This is mainly so anonymous functions
can be returned, and later passed back to 'off'.## listen\_to($other, $event, $callback)
Tell an object to listen to a particular event on an other object.
The other object must consume the Backbone::Events role.Returns the callback that was passed. This is mainly so anonymous functions
can be returned, and later passed back to 'stop\_listening'.## stop\_listening(\[$other\], \[$event\], \[$callback\])
Tell an object to stop listening to events.
## listen\_to\_once($other, $event, $callback)
Just like 'listen\_to', but causes the bound callback to fire only once before
being removed.Returns the callback that was passed. This is mainly so anonymous functions
can be returned, and later passed back to 'stop\_listening'.# SEE ALSO
[http://backbonejs.org/#Events](http://backbonejs.org/#Events)
# AUTHOR
Mark Flickinger
# COPYRIGHT AND LICENSE
This software is copyright (c) 2015 by Mark Flickinger.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.