]> git.r.bdr.sh - rbdr/custom_event_support.lua/blobdiff - README.md
I forgot how to markdown
[rbdr/custom_event_support.lua] / README.md
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..39b8db470391194d9d72a2a94a8fcc2b819d165d 100644 (file)
--- a/README.md
+++ b/README.md
@@ -0,0 +1,55 @@
+# custom_event_support.lua #
+
+This is a lua port of CustomEventSupport.js by @azendal. It's a
+simple implementation of the observer pattern.
+
+## Dependencies ##
+
+* [Middleclass][Middleclass]
+
+## Usage ##
+
+Step 1. Require it somewhere
+
+```lua
+CustomEvent = require('custom_event')
+CustomEventSupport = require('custom_event_support')
+```
+
+Step 2. Include it in a class
+
+```
+local MyClass = class('MyClass')
+MyClass:include(CustomEventSupport)
+```
+
+Step 3a. Bind events
+
+```lua
+-- Bind them to the class
+MyClass:bind('click', function (self, ev)
+  print("Hey, I caught the event")
+end)
+
+
+-- or bind them to an instance
+local my_instance = MyClass:new()
+my_instance:bind('click', function (self, ev)
+  print("Hey, I caught another event: "..tostring(ev.message))
+end)
+```
+
+Step 3b. Dispatch events
+
+```lua
+-- Dispatch them from the class. You can optionally pass data as a
+table.
+MyClass:dispatch('click')
+
+-- or dispatch them from an instance
+my_instance:dispatch('click', {message = "Instance event!"})
+```
+
+That's it. Enjoy :)
+
+[Middleclass] : http://github.com/kikito/middleclass "Middleclass"