Class: Plushie::Subscription::Sub

Inherits:
Data
  • Object
show all
Defined in:
lib/plushie/subscription.rb

Overview

An immutable subscription specification.

Created via factory methods on Subscription rather than directly. The runtime uses #key to diff subscriptions between cycles, starting new ones and stopping removed ones automatically.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil) ⇒ Sub

Returns a new instance of Sub.



32
33
34
# File 'lib/plushie/subscription.rb', line 32

def initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil)
  super
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval

Returns:

  • (Object)

    the current value of interval



31
32
33
# File 'lib/plushie/subscription.rb', line 31

def interval
  @interval
end

#interval [Integer, nil] interval in milliseconds (only for :every)([Integer, nil]) ⇒ Object (readonly)

An immutable subscription specification.

Created via factory methods on Subscription rather than directly. The runtime uses #key to diff subscriptions between cycles, starting new ones and stopping removed ones automatically.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/plushie/subscription.rb', line 31

Sub = Data.define(:type, :tag, :interval, :max_rate, :window_id) do
  def initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil)
    super
  end

  # Returns a key that uniquely identifies this subscription.
  # Used by the runtime to diff subscription lists between cycles.
  # Timer subs include the interval so that changing the interval
  # creates a new subscription rather than updating the existing one.
  # Renderer subs are keyed by type and window_id.
  #
  # @return [Array] unique identity tuple for this subscription
  def key
    if type == :every
      [:every, interval, tag]
    else
      [type, window_id]
    end
  end

  # Derive the wire tag sent to the renderer. Window-scoped
  # subscriptions include the window_id so they don't collide
  # with global subscriptions of the same kind.
  #
  # @return [String]
  def wire_tag
    kind = type.to_s
    window_id ? "#{kind}:#{window_id}" : kind
  end

  # Set the maximum event rate (events per second).
  #
  # @param rate [Integer] max events per second
  # @return [Sub] new Sub with the rate applied
  def with_max_rate(rate)
    self.class.new(**to_h.merge(max_rate: rate))
  end
end

#max_rateObject (readonly)

Returns the value of attribute max_rate

Returns:

  • (Object)

    the current value of max_rate



31
32
33
# File 'lib/plushie/subscription.rb', line 31

def max_rate
  @max_rate
end

#max_rate [Integer, nil] maximum events per second (nil = unlimited)([Integer, nil](nil = unlimited)) ⇒ Object (readonly)

An immutable subscription specification.

Created via factory methods on Subscription rather than directly. The runtime uses #key to diff subscriptions between cycles, starting new ones and stopping removed ones automatically.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/plushie/subscription.rb', line 31

Sub = Data.define(:type, :tag, :interval, :max_rate, :window_id) do
  def initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil)
    super
  end

  # Returns a key that uniquely identifies this subscription.
  # Used by the runtime to diff subscription lists between cycles.
  # Timer subs include the interval so that changing the interval
  # creates a new subscription rather than updating the existing one.
  # Renderer subs are keyed by type and window_id.
  #
  # @return [Array] unique identity tuple for this subscription
  def key
    if type == :every
      [:every, interval, tag]
    else
      [type, window_id]
    end
  end

  # Derive the wire tag sent to the renderer. Window-scoped
  # subscriptions include the window_id so they don't collide
  # with global subscriptions of the same kind.
  #
  # @return [String]
  def wire_tag
    kind = type.to_s
    window_id ? "#{kind}:#{window_id}" : kind
  end

  # Set the maximum event rate (events per second).
  #
  # @param rate [Integer] max events per second
  # @return [Sub] new Sub with the rate applied
  def with_max_rate(rate)
    self.class.new(**to_h.merge(max_rate: rate))
  end
end

#tagObject (readonly)

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



31
32
33
# File 'lib/plushie/subscription.rb', line 31

def tag
  @tag
end

#tag [Symbol, nil] identifier for timer event correlation (timers only)([Symbol, nil]) ⇒ Object (readonly)

An immutable subscription specification.

Created via factory methods on Subscription rather than directly. The runtime uses #key to diff subscriptions between cycles, starting new ones and stopping removed ones automatically.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/plushie/subscription.rb', line 31

Sub = Data.define(:type, :tag, :interval, :max_rate, :window_id) do
  def initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil)
    super
  end

  # Returns a key that uniquely identifies this subscription.
  # Used by the runtime to diff subscription lists between cycles.
  # Timer subs include the interval so that changing the interval
  # creates a new subscription rather than updating the existing one.
  # Renderer subs are keyed by type and window_id.
  #
  # @return [Array] unique identity tuple for this subscription
  def key
    if type == :every
      [:every, interval, tag]
    else
      [type, window_id]
    end
  end

  # Derive the wire tag sent to the renderer. Window-scoped
  # subscriptions include the window_id so they don't collide
  # with global subscriptions of the same kind.
  #
  # @return [String]
  def wire_tag
    kind = type.to_s
    window_id ? "#{kind}:#{window_id}" : kind
  end

  # Set the maximum event rate (events per second).
  #
  # @param rate [Integer] max events per second
  # @return [Sub] new Sub with the rate applied
  def with_max_rate(rate)
    self.class.new(**to_h.merge(max_rate: rate))
  end
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



31
32
33
# File 'lib/plushie/subscription.rb', line 31

def type
  @type
end

#type [Symbol] subscription type (:every, :on_key_press, etc.)([Symbol](: every, :on_key_press, etc.)) ⇒ Object (readonly)

An immutable subscription specification.

Created via factory methods on Subscription rather than directly. The runtime uses #key to diff subscriptions between cycles, starting new ones and stopping removed ones automatically.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/plushie/subscription.rb', line 31

Sub = Data.define(:type, :tag, :interval, :max_rate, :window_id) do
  def initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil)
    super
  end

  # Returns a key that uniquely identifies this subscription.
  # Used by the runtime to diff subscription lists between cycles.
  # Timer subs include the interval so that changing the interval
  # creates a new subscription rather than updating the existing one.
  # Renderer subs are keyed by type and window_id.
  #
  # @return [Array] unique identity tuple for this subscription
  def key
    if type == :every
      [:every, interval, tag]
    else
      [type, window_id]
    end
  end

  # Derive the wire tag sent to the renderer. Window-scoped
  # subscriptions include the window_id so they don't collide
  # with global subscriptions of the same kind.
  #
  # @return [String]
  def wire_tag
    kind = type.to_s
    window_id ? "#{kind}:#{window_id}" : kind
  end

  # Set the maximum event rate (events per second).
  #
  # @param rate [Integer] max events per second
  # @return [Sub] new Sub with the rate applied
  def with_max_rate(rate)
    self.class.new(**to_h.merge(max_rate: rate))
  end
end

#window_idObject (readonly)

Returns the value of attribute window_id

Returns:

  • (Object)

    the current value of window_id



31
32
33
# File 'lib/plushie/subscription.rb', line 31

def window_id
  @window_id
end

#window_id [String, nil] window scope (nil = all windows)([String, nil](nil = all windows)) ⇒ Object (readonly)

An immutable subscription specification.

Created via factory methods on Subscription rather than directly. The runtime uses #key to diff subscriptions between cycles, starting new ones and stopping removed ones automatically.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/plushie/subscription.rb', line 31

Sub = Data.define(:type, :tag, :interval, :max_rate, :window_id) do
  def initialize(type:, tag: nil, interval: nil, max_rate: nil, window_id: nil)
    super
  end

  # Returns a key that uniquely identifies this subscription.
  # Used by the runtime to diff subscription lists between cycles.
  # Timer subs include the interval so that changing the interval
  # creates a new subscription rather than updating the existing one.
  # Renderer subs are keyed by type and window_id.
  #
  # @return [Array] unique identity tuple for this subscription
  def key
    if type == :every
      [:every, interval, tag]
    else
      [type, window_id]
    end
  end

  # Derive the wire tag sent to the renderer. Window-scoped
  # subscriptions include the window_id so they don't collide
  # with global subscriptions of the same kind.
  #
  # @return [String]
  def wire_tag
    kind = type.to_s
    window_id ? "#{kind}:#{window_id}" : kind
  end

  # Set the maximum event rate (events per second).
  #
  # @param rate [Integer] max events per second
  # @return [Sub] new Sub with the rate applied
  def with_max_rate(rate)
    self.class.new(**to_h.merge(max_rate: rate))
  end
end

Instance Method Details

#keyArray

Returns a key that uniquely identifies this subscription. Used by the runtime to diff subscription lists between cycles. Timer subs include the interval so that changing the interval creates a new subscription rather than updating the existing one. Renderer subs are keyed by type and window_id.

Returns:

  • (Array)

    unique identity tuple for this subscription



43
44
45
46
47
48
49
# File 'lib/plushie/subscription.rb', line 43

def key
  if type == :every
    [:every, interval, tag]
  else
    [type, window_id]
  end
end

#wire_tagString

Derive the wire tag sent to the renderer. Window-scoped subscriptions include the window_id so they don't collide with global subscriptions of the same kind.

Returns:

  • (String)


56
57
58
59
# File 'lib/plushie/subscription.rb', line 56

def wire_tag
  kind = type.to_s
  window_id ? "#{kind}:#{window_id}" : kind
end

#with_max_rate(rate) ⇒ Sub

Set the maximum event rate (events per second).

Parameters:

  • rate (Integer)

    max events per second

Returns:

  • (Sub)

    new Sub with the rate applied



65
66
67
# File 'lib/plushie/subscription.rb', line 65

def with_max_rate(rate)
  self.class.new(**to_h.merge(max_rate: rate))
end