Class: Reacto::Subscriptions::SimpleSubscription
- Inherits:
-
Object
- Object
- Reacto::Subscriptions::SimpleSubscription
show all
- Includes:
- Subscription
- Defined in:
- lib/reacto/subscriptions/simple_subscription.rb
Instance Method Summary
collapse
Constructor Details
#initialize(open: NO_ACTION, value: NO_ACTION, error: DEFAULT_ON_ERROR, close: NO_ACTION) ⇒ SimpleSubscription
Returns a new instance of SimpleSubscription.
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/reacto/subscriptions/simple_subscription.rb', line 9
def initialize(
open: NO_ACTION,
value: NO_ACTION,
error: DEFAULT_ON_ERROR,
close: NO_ACTION
)
@open = open
@value = value
@error = error
@close = close
@subscribed = true
@subscriptions = []
@resources = []
end
|
Instance Method Details
#add(subscription) ⇒ Object
36
37
38
39
40
|
# File 'lib/reacto/subscriptions/simple_subscription.rb', line 36
def add(subscription)
return unless subscribed?
@subscriptions << subscription
end
|
#add_resource(resource) ⇒ Object
42
43
44
45
46
|
# File 'lib/reacto/subscriptions/simple_subscription.rb', line 42
def add_resource(resource)
return unless subscribed?
@resources << resource
end
|
#on_close ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/reacto/subscriptions/simple_subscription.rb', line 70
def on_close
return unless subscribed?
@close.call
@subscriptions.each(&:on_close)
unsubscribe
end
|
#on_error(e) ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/reacto/subscriptions/simple_subscription.rb', line 62
def on_error(e)
return unless subscribed?
@error.call(e)
@subscriptions.each { |s| s.on_error(e) }
unsubscribe
end
|
#on_open ⇒ Object
48
49
50
51
52
53
|
# File 'lib/reacto/subscriptions/simple_subscription.rb', line 48
def on_open
return unless subscribed?
@open.call
@subscriptions.each(&:on_open)
end
|
#on_value(v) ⇒ Object
55
56
57
58
59
60
|
# File 'lib/reacto/subscriptions/simple_subscription.rb', line 55
def on_value(v)
return unless subscribed?
@value.call(v)
@subscriptions.each { |s| s.on_value(v) }
end
|
#subscribed? ⇒ Boolean
25
26
27
|
# File 'lib/reacto/subscriptions/simple_subscription.rb', line 25
def subscribed?
@subscribed
end
|
#unsubscribe ⇒ Object
29
30
31
32
33
34
|
# File 'lib/reacto/subscriptions/simple_subscription.rb', line 29
def unsubscribe
@subscriptions.each(&:unsubscribe)
@subscribed = false
@resources.each(&:cleanup)
@resources = []
end
|