README.md in flirt-0.0.3 vs README.md in flirt-0.0.4
- old
+ new
@@ -27,52 +27,52 @@
```
## Usage
-To publish/broadcast an event:
+To publish an event:
-```ruby
-event_data = { fruit: "apple" }
-Flirt.broadcast :picked, event_data
-```
-
-Or:
```ruby
Flirt.publish :picked, event_data
```
-
-(These two versions are aliases)
To subscribe:
```ruby
class MyListener
def initialize
Flirt.subscribe self, :picked, with: :picked_callback
- # or the alias
- Flirt.listen self, :picked, with: :picked_callback
end
def picked_callback(event_data)
puts "The #{event_data[:fruit]} has been picked"
end
end
```
-Sytactic sugar for subscription has been provided in the form of a module:
+To unsubscribe:
```ruby
+ Flirt.unsubscribe self, :picked, with: :picked_callback
+end
+```
+
+
+Syntactic sugar for subscription and unsubscription has been provided in the form of a module:
+
+```ruby
class MyListener
include Flirt::Listener
def initialize
subscribe_to :picked, with: :picked_callback
- # or the alias
- listen_to :picked, with: :picked_callback
end
+
+ def before_destroy
+ unsubscribe_from :picked, with: :picked_callback
+ end
def picked_callback(event_data)
puts "The #{event_data[:fruit]} has been picked"
end
end
@@ -83,19 +83,19 @@
```ruby
class MyListener
extend Flirt::Listener
subscribe_to :picked, with: :picked_callback
- # or the alias
- listen_to :picked, with: :picked_callback
def self.picked_callback(event_data)
puts "The #{event_data[:fruit]} has been picked"
end
end
```
+```unsubscribe_from``` can technically be used in the class context, but probably doesn't have as much use.
+
Flirt defaults to 'enabled'. Switch Flirt off:
```ruby
Flirt.disable
```
@@ -119,10 +119,10 @@
```
Enabled status affects broadcast/publish, listeners can still be added and will be
remembered. No listeners will be removed.
-Clear all listeners
+Clear all listeners:
```ruby
Flirt.clear
```