motion 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/motion/templates/motion.js +7 -7
- data/lib/motion.rb +37 -35
- data/lib/motion/component/broadcasts.rb +12 -9
- data/lib/motion/component/lifecycle.rb +1 -2
- data/lib/motion/component/motions.rb +12 -9
- data/lib/motion/component/periodic_timers.rb +12 -9
- data/lib/motion/component/rendering.rb +33 -28
- data/lib/motion/event.rb +4 -6
- data/lib/motion/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d25829b24f8c2781bcc44f9132061532d3c5b3466e60e69ab646407d27c32519
|
4
|
+
data.tar.gz: c3e69af9595e1fe7b659a6ed51a57c252d2028581aa4f154e4a150ee2a74b12c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1bb6c0022e3636d62d6ba054aeac9e16c353bc5d646aa83c460a0eaf1f0fc0774efd71b03d3eb47456a033a66521907fc3e23e29fc02c4d09124a03732e940c
|
7
|
+
data.tar.gz: aa336213b2487da46b868b8c89f74ff55ec745078ffdb1e75fdeafe7d7707870f8f140013d8d9218e68998f89911813f9e0437d75f9261ccc29ec957990b6b02
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { createClient } from '@unabridged/motion'
|
2
|
-
import consumer from './channels/consumer'
|
1
|
+
import { createClient } from '@unabridged/motion'
|
2
|
+
import consumer from './channels/consumer'
|
3
3
|
|
4
4
|
export default createClient({
|
5
5
|
|
@@ -11,7 +11,7 @@ export default createClient({
|
|
11
11
|
// Motion can log information about the lifecycle of components to the
|
12
12
|
// browser's console. It is recommended to turn this feature off outside of
|
13
13
|
// development.
|
14
|
-
logging: process.env
|
14
|
+
logging: process.env.RAILS_ENV === 'development'
|
15
15
|
|
16
16
|
// This function will be called for every motion, and the return value will be
|
17
17
|
// made available at `Motion::Event#extra_data`:
|
@@ -30,8 +30,8 @@ export default createClient({
|
|
30
30
|
// The data attributes used by Motion can be customized, but these values must
|
31
31
|
// also be updated in the Ruby initializer:
|
32
32
|
//
|
33
|
-
// keyAttribute:
|
34
|
-
// stateAttribute:
|
35
|
-
// motionAttribute:
|
33
|
+
// keyAttribute: 'data-motion-key',
|
34
|
+
// stateAttribute: 'data-motion-state',
|
35
|
+
// motionAttribute: 'data-motion',
|
36
36
|
|
37
|
-
})
|
37
|
+
})
|
data/lib/motion.rb
CHANGED
@@ -19,41 +19,43 @@ module Motion
|
|
19
19
|
autoload :Serializer, "motion/serializer"
|
20
20
|
autoload :TestHelpers, "motion/test_helpers"
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
22
|
+
class << self
|
23
|
+
def configure(&block)
|
24
|
+
raise AlreadyConfiguredError if @config
|
25
|
+
|
26
|
+
@config = Configuration.new(&block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def config
|
30
|
+
@config ||= Configuration.default
|
31
|
+
end
|
32
|
+
|
33
|
+
alias_method :configuration, :config
|
34
|
+
|
35
|
+
def serializer
|
36
|
+
@serializer ||= Serializer.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def markup_transformer
|
40
|
+
@markup_transformer ||= MarkupTransformer.new
|
41
|
+
end
|
42
|
+
|
43
|
+
def build_renderer_for(websocket_connection)
|
44
|
+
config.renderer_for_connection_proc.call(websocket_connection)
|
45
|
+
end
|
46
|
+
|
47
|
+
def notify_error(error, message)
|
48
|
+
config.error_notification_proc&.call(error, message)
|
49
|
+
end
|
50
|
+
|
51
|
+
# This method only exists for testing. Changing configuration while Motion
|
52
|
+
# is in use is not supported. It is only safe to call this method when no
|
53
|
+
# components are currently mounted.
|
54
|
+
def reset_internal_state_for_testing!(new_configuration = nil)
|
55
|
+
@config = new_configuration
|
56
|
+
@serializer = nil
|
57
|
+
@markup_transformer = nil
|
58
|
+
end
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/concern"
|
4
|
-
require "active_support/core_ext/class/attribute"
|
5
4
|
require "active_support/core_ext/object/to_param"
|
6
5
|
require "active_support/core_ext/hash/except"
|
7
6
|
|
@@ -12,6 +11,9 @@ module Motion
|
|
12
11
|
module Broadcasts
|
13
12
|
extend ActiveSupport::Concern
|
14
13
|
|
14
|
+
DEFAULT = {}.freeze
|
15
|
+
private_constant :DEFAULT
|
16
|
+
|
15
17
|
# Analogous to `module_function` (available on both class and instance)
|
16
18
|
module ModuleFunctions
|
17
19
|
def stream_from(broadcast, handler)
|
@@ -37,14 +39,6 @@ module Motion
|
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
|
-
included do
|
41
|
-
class_attribute :_broadcast_handlers,
|
42
|
-
instance_reader: false,
|
43
|
-
instance_writer: false,
|
44
|
-
instance_predicate: false,
|
45
|
-
default: {}.freeze
|
46
|
-
end
|
47
|
-
|
48
42
|
class_methods do
|
49
43
|
include ModuleFunctions
|
50
44
|
|
@@ -56,6 +50,15 @@ module Motion
|
|
56
50
|
serialize_broadcasting([name, model])
|
57
51
|
end
|
58
52
|
|
53
|
+
attr_writer :_broadcast_handlers
|
54
|
+
|
55
|
+
def _broadcast_handlers
|
56
|
+
return @_broadcast_handlers if defined?(@_broadcast_handlers)
|
57
|
+
return superclass._broadcast_handlers if superclass.respond_to?(:_broadcast_handlers)
|
58
|
+
|
59
|
+
DEFAULT
|
60
|
+
end
|
61
|
+
|
59
62
|
private
|
60
63
|
|
61
64
|
# This definition is copied from ActionCable::Channel::Broadcasting
|
@@ -105,8 +105,7 @@ module Motion
|
|
105
105
|
|
106
106
|
run_callbacks(:action, &block)
|
107
107
|
ensure
|
108
|
-
|
109
|
-
remove_instance_variable(:@_action_callback_context)
|
108
|
+
@_action_callback_context = nil
|
110
109
|
end
|
111
110
|
end
|
112
111
|
end
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/concern"
|
4
|
-
require "active_support/core_ext/class/attribute"
|
5
4
|
require "active_support/core_ext/hash/except"
|
6
5
|
|
7
6
|
require "motion"
|
@@ -11,6 +10,9 @@ module Motion
|
|
11
10
|
module Motions
|
12
11
|
extend ActiveSupport::Concern
|
13
12
|
|
13
|
+
DEFAULT = {}.freeze
|
14
|
+
private_constant :DEFAULT
|
15
|
+
|
14
16
|
# Analogous to `module_function` (available on both class and instance)
|
15
17
|
module ModuleFunctions
|
16
18
|
def map_motion(motion, handler = motion)
|
@@ -28,16 +30,17 @@ module Motion
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
|
-
included do
|
32
|
-
class_attribute :_motion_handlers,
|
33
|
-
instance_reader: false,
|
34
|
-
instance_writer: false,
|
35
|
-
instance_predicate: false,
|
36
|
-
default: {}.freeze
|
37
|
-
end
|
38
|
-
|
39
33
|
class_methods do
|
40
34
|
include ModuleFunctions
|
35
|
+
|
36
|
+
attr_writer :_motion_handlers
|
37
|
+
|
38
|
+
def _motion_handlers
|
39
|
+
return @_motion_handlers if defined?(@_motion_handlers)
|
40
|
+
return superclass._motion_handlers if superclass.respond_to?(:_motion_handlers)
|
41
|
+
|
42
|
+
DEFAULT
|
43
|
+
end
|
41
44
|
end
|
42
45
|
|
43
46
|
include ModuleFunctions
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/concern"
|
4
|
-
require "active_support/core_ext/class/attribute"
|
5
4
|
require "active_support/core_ext/hash/except"
|
6
5
|
|
7
6
|
require "motion"
|
@@ -11,6 +10,9 @@ module Motion
|
|
11
10
|
module PeriodicTimers
|
12
11
|
extend ActiveSupport::Concern
|
13
12
|
|
13
|
+
DEFAULT = {}.freeze
|
14
|
+
private_constant :DEFAULT
|
15
|
+
|
14
16
|
# Analogous to `module_function` (available on both class and instance)
|
15
17
|
module ModuleFunctions
|
16
18
|
def every(interval, handler, name: handler)
|
@@ -32,16 +34,17 @@ module Motion
|
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
35
|
-
included do
|
36
|
-
class_attribute :_periodic_timers,
|
37
|
-
instance_reader: false,
|
38
|
-
instance_writer: false,
|
39
|
-
instance_predicate: false,
|
40
|
-
default: {}.freeze
|
41
|
-
end
|
42
|
-
|
43
37
|
class_methods do
|
44
38
|
include ModuleFunctions
|
39
|
+
|
40
|
+
attr_writer :_periodic_timers
|
41
|
+
|
42
|
+
def _periodic_timers
|
43
|
+
return @_periodic_timers if defined?(@_periodic_timers)
|
44
|
+
return superclass._periodic_timers if superclass.respond_to?(:_periodic_timers)
|
45
|
+
|
46
|
+
DEFAULT
|
47
|
+
end
|
45
48
|
end
|
46
49
|
|
47
50
|
include ModuleFunctions
|
@@ -5,27 +5,34 @@ require "motion"
|
|
5
5
|
module Motion
|
6
6
|
module Component
|
7
7
|
module Rendering
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
8
|
+
STATE_EXCLUDED_IVARS = %i[
|
9
|
+
@_action_callback_context
|
10
|
+
@_awaiting_forced_rerender
|
11
|
+
@_routes
|
12
|
+
|
13
|
+
@view_context
|
14
|
+
@lookup_context
|
15
|
+
@view_renderer
|
16
|
+
@view_flow
|
17
|
+
@virtual_path
|
18
|
+
@variant
|
19
|
+
@current_template
|
20
|
+
@output_buffer
|
21
|
+
|
22
|
+
@helpers
|
23
|
+
@controller
|
24
|
+
@request
|
25
|
+
@tag_builder
|
20
26
|
].freeze
|
21
|
-
|
27
|
+
|
28
|
+
private_constant :STATE_EXCLUDED_IVARS
|
22
29
|
|
23
30
|
def rerender!
|
24
|
-
|
31
|
+
@_awaiting_forced_rerender = true
|
25
32
|
end
|
26
33
|
|
27
34
|
def awaiting_forced_rerender?
|
28
|
-
|
35
|
+
@_awaiting_forced_rerender
|
29
36
|
end
|
30
37
|
|
31
38
|
# * This can be overwritten.
|
@@ -43,7 +50,7 @@ module Motion
|
|
43
50
|
_run_action_callbacks(context: :render) {
|
44
51
|
_clear_awaiting_forced_rerender!
|
45
52
|
|
46
|
-
view_context.capture {
|
53
|
+
view_context.capture { super }
|
47
54
|
}
|
48
55
|
|
49
56
|
raise RenderAborted, self if html == false
|
@@ -54,21 +61,19 @@ module Motion
|
|
54
61
|
private
|
55
62
|
|
56
63
|
def _clear_awaiting_forced_rerender!
|
57
|
-
|
58
|
-
|
59
|
-
remove_instance_variable(RERENDER_MARKER_IVAR)
|
64
|
+
@_awaiting_forced_rerender = false
|
60
65
|
end
|
61
66
|
|
62
|
-
def
|
63
|
-
|
67
|
+
def marshal_dump
|
68
|
+
(instance_variables - STATE_EXCLUDED_IVARS)
|
69
|
+
.map { |ivar| [ivar, instance_variable_get(ivar)] }
|
70
|
+
.to_h
|
71
|
+
end
|
64
72
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
existing_instance_variables -
|
70
|
-
ALLOWED_NEW_IVARS_DURING_RENDER
|
71
|
-
).each(&method(:remove_instance_variable))
|
73
|
+
def marshal_load(instance_variables)
|
74
|
+
instance_variables.each do |ivar, value|
|
75
|
+
instance_variable_set(ivar, value)
|
76
|
+
end
|
72
77
|
end
|
73
78
|
end
|
74
79
|
end
|
data/lib/motion/event.rb
CHANGED
@@ -18,7 +18,7 @@ module Motion
|
|
18
18
|
raw["type"]
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
alias_method :name, :type
|
22
22
|
|
23
23
|
def details
|
24
24
|
raw.fetch("details", {})
|
@@ -34,14 +34,12 @@ module Motion
|
|
34
34
|
@target = Motion::Element.from_raw(raw["target"])
|
35
35
|
end
|
36
36
|
|
37
|
-
def
|
38
|
-
return @
|
37
|
+
def element
|
38
|
+
return @element if defined?(@element)
|
39
39
|
|
40
|
-
@
|
40
|
+
@element = Motion::Element.from_raw(raw["element"])
|
41
41
|
end
|
42
42
|
|
43
|
-
alias element current_target
|
44
|
-
|
45
43
|
def form_data
|
46
44
|
element&.form_data
|
47
45
|
end
|
data/lib/motion/version.rb
CHANGED
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.4.
|
4
|
+
version: 0.4.3
|
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-09-
|
12
|
+
date: 2020-09-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '5.
|
34
|
+
version: '5.1'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '5.
|
41
|
+
version: '5.1'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: lz4-ruby
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,7 +102,7 @@ metadata:
|
|
102
102
|
source_code_uri: https://github.com/unabridged/motion
|
103
103
|
post_install_message: |
|
104
104
|
Friendly reminder: When updating the motion gem, don't forget to update the
|
105
|
-
NPM package as well (`bin/yarn add '@unabridged/motion@0.4.
|
105
|
+
NPM package as well (`bin/yarn add '@unabridged/motion@0.4.3'`).
|
106
106
|
rdoc_options: []
|
107
107
|
require_paths:
|
108
108
|
- lib
|
@@ -110,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
110
|
requirements:
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version: 2.
|
113
|
+
version: 2.5.0
|
114
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
116
|
- - ">="
|