Skip to content

Commit dd95ea6

Browse files
author
Gerasimos Maropoulos
committed
Implement the full nodejs EventEmmiter
1 parent 7716aed commit dd95ea6

File tree

3 files changed

+371
-105
lines changed

3 files changed

+371
-105
lines changed

README.md

+67-46
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,73 @@
1-
[Travis Widget]: https://img.shields.io/travis/kataras/go-events.svg?style=flat-square
2-
[Travis]: http://travis-ci.org/kataras/go-events
3-
[License Widget]: https://img.shields.io/badge/license-MIT%20%20License%20-E91E63.svg?style=flat-square
4-
[License]: https://github.com/kataras/go-events/blob/master/LICENSE
5-
[Release Widget]: https://img.shields.io/badge/release-v0.0.1-blue.svg?style=flat-square
6-
[Release]: https://github.com/kataras/go-events/releases
7-
[Chat Widget]: https://img.shields.io/badge/community-chat-00BCD4.svg?style=flat-square
8-
[Chat]: https://kataras.rocket.chat/channel/go-events
9-
[ChatMain]: https://kataras.rocket.chat/channel/go-events
10-
[ChatAlternative]: https://gitter.im/kataras/go-events
11-
[Report Widget]: https://img.shields.io/badge/report%20card-A%2B-F44336.svg?style=flat-square
12-
[Report]: http://goreportcard.com/report/kataras/go-events
13-
[Documentation Widget]: https://img.shields.io/badge/docs-reference-5272B4.svg?style=flat-square
14-
[Documentation]: https://godoc.org/github.com/kataras/go-events
15-
[Language Widget]: https://img.shields.io/badge/powered_by-Go-3362c2.svg?style=flat-square
16-
[Language]: http://golang.org
17-
[Platform Widget]: https://img.shields.io/badge/platform-All-yellow.svg?style=flat-square
18-
[Awesome Widget]: https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg?style=flat-square
19-
[Awesome WidgetAlternative]: https://img.shields.io/badge/awesome-%E2%9C%93-ff69b4.svg?style=flat-square
20-
[Awesome]: https://github.com/avelino/awesome-go
21-
221
<p align="center">
232
<img src="/logo.jpg" height="400">
24-
</p>
3+
<br/>
4+
5+
<a href="https://travis-ci.org/kataras/go-events"><img src="https://img.shields.io/travis/kataras/go-events.svg?style=flat-square" alt="Build Status"></a>
6+
7+
8+
<a href="https://github.com/avelino/awesome-go"><img src="https://img.shields.io/badge/awesome-%E2%9C%93-ff69b4.svg?style=flat-square" alt="Awesome GoLang"></a>
9+
10+
<a href="http://goreportcard.com/report/kataras/go-events"><img src="https://img.shields.io/badge/-A%2B-F44336.svg?style=flat-square" alt="Report A+"></a>
11+
12+
13+
<a href="https://github.com/kataras/go-events/blob/master/LICENSE"><img src="https://img.shields.io/badge/%20license-MIT%20-E91E63.svg?style=flat-square" alt="License"></a>
14+
15+
16+
17+
<a href="https://github.com/kataras/go-events/releases"><img src="https://img.shields.io/badge/%20release%20-%20v0.0.2-blue.svg?style=flat-square" alt="Releases"></a>
18+
19+
<a href="https://godoc.org/github.com/kataras/go-events"><img src="https://img.shields.io/badge/%20docs-reference-5272B4.svg?style=flat-square" alt="Read me docs"></a>
20+
21+
<a href="https://kataras.rocket.chat/channel/go-events"><img src="https://img.shields.io/badge/%20community-chat-00BCD4.svg?style=flat-square" alt="Chat"></a>
2522

26-
# Events [![Travis Widget]][Travis] [![Awesome Widget]][Awesome] [![License Widget]][License] [![Release Widget]][Release]
23+
<br/><br/>
2724

28-
Simple nodejs-style EventEmmiter for Go Programming Language.
25+
Simple EventEmmiter for Go Programming Language. Inspired by <a href="https://nodejs.org/api/events.html">Nodejs EventEmitter</a>.
2926

27+
</p>
3028

3129

3230
Quick view
3331
------------
32+
`New() EventEmmiter // New returns a new, empty, EventEmmiter`
33+
34+
35+
```go
36+
// AddListener is an alias for .On(eventName, listener).
37+
AddListener(EventName, ...Listener)
38+
// Emit fires a particular event,
39+
// Synchronously calls each of the listeners registered for the event named
40+
// eventName, in the order they were registered,
41+
// passing the supplied arguments to each.
42+
Emit(EventName, ...interface{})
43+
// EventNames returns an array listing the events for which the emitter has registered listeners.
44+
// The values in the array will be strings.
45+
EventNames() []EventName
46+
// GetMaxListeners returns the max listeners for this emmiter
47+
// see SetMaxListeners
48+
GetMaxListeners() int
49+
// ListenerCount returns the length of all registered listeners to a particular event
50+
ListenerCount(EventName) int
51+
// Listeners returns a copy of the array of listeners for the event named eventName.
52+
Listeners(EventName) []Listener
53+
// On registers a particular listener for an event, func receiver parameter(s) is/are optional
54+
On(EventName, ...Listener)
55+
// Once adds a one time listener function for the event named eventName.
56+
// The next time eventName is triggered, this listener is removed and then invoked.
57+
Once(EventName, ...Listener)
58+
// RemoveAllListeners removes all listeners, or those of the specified eventName.
59+
// Note that it will remove the event itself.
60+
// Returns an indicator if event and listeners were found before the remove.
61+
RemoveAllListeners(EventName) bool
62+
// Clear removes all events and all listeners, restores Events to an empty value
63+
Clear()
64+
// SetMaxListeners obviously this function allows the MaxListeners
65+
// to be decrease or increase. Set to zero for unlimited
66+
SetMaxListeners(int)
67+
// Len returns the length of all registered events
68+
Len() int
69+
```
3470

35-
- `New` returns a new, empty EventEmmiter
36-
- `On` is the func which registers the event listeners for a specific event
37-
- `Emit` fires a particular event, this will call all functions(listeners) registered to this particular event
38-
- `Remove` remove all registered listeners from a particular event
39-
- `Len` returns the length of all registered events
40-
- `LenListeners` returns the length of all registered listeners to a particular event
4171

4272
```go
4373
import "github.com/kataras/go-events"
@@ -81,18 +111,16 @@ events.On("my_event", func(payload ...interface{}) {
81111
})
82112

83113
println(events.Len()) // prints 1
84-
println(events.LenListeners("my_event")) // prints 2
114+
println(events.ListenerCount("my_event")) // prints 2
85115

86116
// Remove our event, when/if we don't need this or we want to clear all of its listeners
87-
events.Remove("my_event")
117+
events.RemoveAllListeners("my_event")
88118

89119
println(events.Len()) // prints 0
90-
println(events.LenListeners("my_event")) // prints 0
120+
println(events.ListenerCount("my_event")) // prints 0
91121

92122

93123
```
94-
[![Documentation Widget]][Documentation] [![Chat Widget]][Chat]
95-
96124
Installation
97125
------------
98126

@@ -102,7 +130,6 @@ The only requirement is the [Go Programming Language](https://golang.org/dl).
102130
$ go get -u github.com/kataras/go-events
103131
```
104132

105-
[![Language Widget]][Language] ![Platform Widget]
106133

107134
FAQ
108135
------------
@@ -112,7 +139,7 @@ Explore [these questions](https://github.com/kataras/go-events/issues?go-events=
112139
Versioning
113140
------------
114141

115-
Current: v0.0.1
142+
Current: v0.0.2
116143

117144
Read more about Semantic Versioning 2.0.0
118145

@@ -135,18 +162,12 @@ Contributing
135162

136163
If you are interested in contributing to the go-events project, please make a PR.
137164

138-
[![Report Widget]][Report]
139-
140-
141-
README template
142-
------------
143-
144-
https://github.com/kataras/github-go-readme
145-
146-
147165
License
148166
------------
149167

150168
This project is licensed under the MIT License.
151169

152170
License can be found [here](LICENSE).
171+
172+
[Chat Widget]: https://img.shields.io/badge/community-chat-00BCD4.svg?style=flat-square
173+
[Chat]: https://kataras.rocket.chat/channel/go-events

0 commit comments

Comments
 (0)