motion 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7645381b6b2749a4a9ba90a15c93916636e1b9edfd7b3a6a1bf7d47429fedb3f
4
- data.tar.gz: 46c929b8aa2d1de8c714eb8b8db1db8524aec892576a13ad1582b7fa858565f7
3
+ metadata.gz: 54eb6afb0f21c0333d46c1a21602739146fa1e2a021d3ffda048c9763dc85e66
4
+ data.tar.gz: c3d9476c0e34869f5d4e46121316dee4f2c78d91b0a9b51d05c14a0b4d4e63ac
5
5
  SHA512:
6
- metadata.gz: b8c99a480f51e9d818f5d22de3efbf8923155943d1815188e19332c54b8f24b909bc371abc7282d3a9caac754cf1b0aee4bb3193dad75b7f1d86a9112ed13983
7
- data.tar.gz: a12e9213ba0ae38cbc5d839ae1408a5aab064be055896300f19a2296ebcd74b49922b96636bc52bd7b7aef62be9868ea47437544938f20facaad45534744bc4e
6
+ metadata.gz: b17d8159ba7eae3b144a6380385e68eb9a2b49b0733926d9e285bf60c8f0767646d30841ee90d62d4b3a359f5c5f9beb62d4793c6d48dff6f1887c9fd7367a70
7
+ data.tar.gz: 0c47ed993c63378f0d562e341a44539bda1578c34d42ae8449c1dfd9dedabf7481e9e5f272c0869416893533fe31b5901368ebcc2e53c0752db120afb0e84c50
@@ -5,6 +5,7 @@ require "motion/errors"
5
5
 
6
6
  module Motion
7
7
  autoload :ActionCableExtentions, "motion/action_cable_extentions"
8
+ autoload :Callback, "motion/callback"
8
9
  autoload :Channel, "motion/channel"
9
10
  autoload :Component, "motion/component"
10
11
  autoload :ComponentConnection, "motion/component_connection"
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "motion"
4
+
5
+ module Motion
6
+ class Callback
7
+ attr_reader :broadcast
8
+
9
+ NAMESPACE = "motion:callback"
10
+ private_constant :NAMESPACE
11
+
12
+ def self.broadcast_for(component, method)
13
+ [
14
+ NAMESPACE,
15
+ component.stable_instance_identifier_for_callbacks,
16
+ method
17
+ ].join(":")
18
+ end
19
+
20
+ def initialize(component, method)
21
+ @broadcast = self.class.broadcast_for(component, method)
22
+
23
+ component.stream_from(broadcast, method)
24
+ end
25
+
26
+ def ==(other)
27
+ other.is_a?(Callback) &&
28
+ other.broadcast == broadcast
29
+ end
30
+
31
+ def call(message = nil)
32
+ ActionCable.server.broadcast(broadcast, message)
33
+ end
34
+ end
35
+ end
@@ -65,15 +65,15 @@ module Motion
65
65
  private
66
66
 
67
67
  def synchronize
68
+ component_connection.if_render_required do |component|
69
+ transmit(renderer.render(component))
70
+ end
71
+
68
72
  streaming_from component_connection.broadcasts,
69
73
  to: :process_broadcast
70
74
 
71
75
  periodically_notify component_connection.periodic_timers,
72
76
  via: :process_periodic_timer
73
-
74
- component_connection.if_render_required do |component|
75
- transmit(renderer.render(component))
76
- end
77
77
  end
78
78
 
79
79
  def handle_error(error, context)
@@ -5,6 +5,7 @@ require "active_support/concern"
5
5
  require "motion"
6
6
 
7
7
  require "motion/component/broadcasts"
8
+ require "motion/component/callbacks"
8
9
  require "motion/component/lifecycle"
9
10
  require "motion/component/motions"
10
11
  require "motion/component/periodic_timers"
@@ -15,6 +16,7 @@ module Motion
15
16
  extend ActiveSupport::Concern
16
17
 
17
18
  include Broadcasts
19
+ include Callbacks
18
20
  include Lifecycle
19
21
  include Motions
20
22
  include PeriodicTimers
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+
5
+ require "motion"
6
+
7
+ module Motion
8
+ module Component
9
+ module Callbacks
10
+ def bind(method)
11
+ Callback.new(self, method)
12
+ end
13
+
14
+ def stable_instance_identifier_for_callbacks
15
+ @_stable_instance_identifier_for_callbacks ||= SecureRandom.uuid
16
+ end
17
+ end
18
+ end
19
+ end
@@ -11,6 +11,15 @@ module Motion
11
11
  RERENDER_MARKER_IVAR = :@__awaiting_forced_rerender__
12
12
  private_constant :RERENDER_MARKER_IVAR
13
13
 
14
+ # Some changes to Motion's state are specifically supported during render.
15
+ ALLOWED_NEW_IVARS_DURING_RENDER = %i[
16
+ @_broadcast_handlers
17
+ @_stable_instance_identifier_for_callbacks
18
+ @_motion_handlers
19
+ @_periodic_timers
20
+ ].freeze
21
+ private_constant :ALLOWED_NEW_IVARS_DURING_RENDER
22
+
14
23
  def rerender!
15
24
  instance_variable_set(RERENDER_MARKER_IVAR, true)
16
25
  end
@@ -55,8 +64,11 @@ module Motion
55
64
 
56
65
  yield
57
66
  ensure
58
- (instance_variables - existing_instance_variables)
59
- .each(&method(:remove_instance_variable))
67
+ (
68
+ instance_variables -
69
+ existing_instance_variables -
70
+ ALLOWED_NEW_IVARS_DURING_RENDER
71
+ ).each(&method(:remove_instance_variable))
60
72
  end
61
73
  end
62
74
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Motion
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: motion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alec Larsen
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-07-12 00:00:00.000000000 Z
12
+ date: 2020-07-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -59,9 +59,11 @@ files:
59
59
  - lib/motion/action_cable_extentions/declarative_streams.rb
60
60
  - lib/motion/action_cable_extentions/log_suppression.rb
61
61
  - lib/motion/action_cable_extentions/synchronization.rb
62
+ - lib/motion/callback.rb
62
63
  - lib/motion/channel.rb
63
64
  - lib/motion/component.rb
64
65
  - lib/motion/component/broadcasts.rb
66
+ - lib/motion/component/callbacks.rb
65
67
  - lib/motion/component/lifecycle.rb
66
68
  - lib/motion/component/motions.rb
67
69
  - lib/motion/component/periodic_timers.rb
@@ -86,7 +88,7 @@ metadata:
86
88
  source_code_uri: https://github.com/unabridged/motion
87
89
  post_install_message: |
88
90
  Friendly reminder: When updating the motion gem, don't forget to update the
89
- NPM package as well (`bin/yarn add '@unabridged/motion@0.3.0'`).
91
+ NPM package as well (`bin/yarn add '@unabridged/motion@0.4.0'`).
90
92
  rdoc_options: []
91
93
  require_paths:
92
94
  - lib