superglue 2.0.0.alpha.1 → 2.0.0.alpha.8
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 +4 -4
- data/app/channels/superglue/streams/broadcasts.rb +19 -16
- data/app/channels/superglue/streams/stream_name.rb +3 -0
- data/app/channels/superglue/streams_channel.rb +3 -0
- data/app/controllers/concerns/superglue/request_id_tracking.rb +3 -0
- data/app/helpers/superglue/streams_helper.rb +21 -18
- data/app/jobs/superglue/streams/action_broadcast_job.rb +5 -2
- data/app/jobs/superglue/streams/broadcast_stream_job.rb +3 -0
- data/app/models/concerns/superglue/broadcastable.rb +41 -38
- data/app/models/superglue/debouncer.rb +3 -0
- data/app/models/superglue/thread_debouncer.rb +3 -0
- data/app/views/superglue/layouts/_stream_message.json.props +1 -1
- data/lib/generators/superglue/install/install_generator.rb +1 -1
- data/lib/generators/superglue/install/templates/application.json.props +2 -0
- data/lib/generators/superglue/install/templates/js/application.jsx +1 -1
- data/lib/generators/superglue/install/templates/js/application_visit.js +1 -1
- data/lib/generators/superglue/install/templates/js/flash.js +10 -6
- data/lib/generators/superglue/install/templates/js/store.js +3 -2
- data/lib/generators/superglue/install/templates/stream.json.props +5 -1
- data/lib/generators/superglue/install/templates/ts/application.tsx +10 -9
- data/lib/generators/superglue/install/templates/ts/application_visit.ts +1 -1
- data/lib/generators/superglue/install/templates/ts/flash.ts +12 -8
- data/lib/generators/superglue/install/templates/ts/store.ts +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3239bf29458613c97b65cba82454502a2f3aa7c7862b56fb6f7c35b93eaa52ae
|
4
|
+
data.tar.gz: c7a4f01902228e4509fcc53be51f5c242e4c4c8ee7d6fe8786220a920ce608a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 149bee1ac1801fef07d29e7cadecdb62a6c681e97b1711b0f33e9a196ea9cf8521803fdddf1dbeb1c8dfbd45224149dfe2451772846ba0fd22f5beacb6151148
|
7
|
+
data.tar.gz: 388e7ce6dbb46710b12011ea38bfd8367b9961e300524f3a86eea53bf9e29c581616eebb92683d1bb0d5672ebb426bade3168c8276b1bbf06a9ba942cff7c1bb
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# This file was ported from the amazing folks at turbo-rails
|
2
|
+
# You can find its MIT License here: https://github.com/hotwired/turbo-rails/blob/main/MIT-LICENSE
|
3
|
+
|
1
4
|
module Superglue::Streams::Broadcasts
|
2
5
|
def broadcast_save_to(*streamables, **opts)
|
3
6
|
broadcast_action_to(*streamables, action: :save, **opts)
|
@@ -22,19 +25,19 @@ module Superglue::Streams::Broadcasts
|
|
22
25
|
broadcast_stream_to(*streamables, content: content)
|
23
26
|
end
|
24
27
|
|
25
|
-
def broadcast_action_to(*streamables, action:,
|
28
|
+
def broadcast_action_to(*streamables, action:, target: nil, targets: nil, save_target: nil, options: {}, **rendering)
|
26
29
|
locals = rendering[:locals] || {}
|
27
|
-
|
30
|
+
targets = (target ? [target] : targets)
|
28
31
|
|
29
|
-
|
32
|
+
targets = targets.map do |item|
|
30
33
|
convert_to_superglue_fragment_id(item)
|
31
34
|
end
|
32
35
|
|
33
|
-
if
|
34
|
-
options[:saveAs] = convert_to_superglue_fragment_id(
|
36
|
+
if save_target
|
37
|
+
options[:saveAs] = convert_to_superglue_fragment_id(save_target)
|
35
38
|
end
|
36
39
|
|
37
|
-
locals[:
|
40
|
+
locals[:broadcast_target_keys] = targets
|
38
41
|
locals[:broadcast_action] = action
|
39
42
|
locals[:broadcast_options] = options
|
40
43
|
rendering[:locals] = locals
|
@@ -69,22 +72,22 @@ module Superglue::Streams::Broadcasts
|
|
69
72
|
end
|
70
73
|
end
|
71
74
|
|
72
|
-
def broadcast_action_later_to(*streamables, action:,
|
75
|
+
def broadcast_action_later_to(*streamables, action:, target: nil, targets: nil, save_target: nil, options: {}, **rendering)
|
73
76
|
streamables.flatten!
|
74
77
|
streamables.compact_blank!
|
75
78
|
|
76
79
|
return unless streamables.present?
|
77
80
|
|
78
|
-
|
81
|
+
targets = (target ? [target] : targets).map do |item|
|
79
82
|
convert_to_superglue_fragment_id(item)
|
80
83
|
end
|
81
84
|
|
82
|
-
if
|
83
|
-
options[:saveAs] = convert_to_superglue_fragment_id(
|
85
|
+
if save_target
|
86
|
+
options[:saveAs] = convert_to_superglue_fragment_id(save_target)
|
84
87
|
end
|
85
88
|
|
86
89
|
Superglue::Streams::ActionBroadcastJob.perform_later \
|
87
|
-
stream_name_from(streamables), action: action,
|
90
|
+
stream_name_from(streamables), action: action, targets: targets, options: options, **rendering
|
88
91
|
end
|
89
92
|
|
90
93
|
def broadcast_stream_to(*streamables, content:)
|
@@ -102,12 +105,12 @@ module Superglue::Streams::Broadcasts
|
|
102
105
|
|
103
106
|
private
|
104
107
|
|
105
|
-
def convert_to_superglue_fragment_id(
|
106
|
-
|
107
|
-
if
|
108
|
-
ActionView::RecordIdentifier.dom_id(*
|
108
|
+
def convert_to_superglue_fragment_id(target)
|
109
|
+
target_array = Array.wrap(target)
|
110
|
+
if target_array.any? { |value| value.respond_to?(:to_key) }
|
111
|
+
ActionView::RecordIdentifier.dom_id(*target_array)
|
109
112
|
else
|
110
|
-
|
113
|
+
target
|
111
114
|
end
|
112
115
|
end
|
113
116
|
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# This file was ported from the amazing folks at turbo-rails
|
2
|
+
# You can find its MIT License here: https://github.com/hotwired/turbo-rails/blob/main/MIT-LICENSE
|
3
|
+
|
1
4
|
module Superglue::Streams::StreamName
|
2
5
|
def verified_stream_name(signed_stream_name)
|
3
6
|
Superglue.signed_stream_verifier.verified signed_stream_name
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# This file was ported from the amazing folks at turbo-rails
|
2
|
+
# You can find its MIT License here: https://github.com/hotwired/turbo-rails/blob/main/MIT-LICENSE
|
3
|
+
|
1
4
|
class Superglue::StreamsChannel < ActionCable::Channel::Base
|
2
5
|
extend Superglue::Streams::StreamName
|
3
6
|
extend Superglue::Streams::Broadcasts
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# This file was ported from the amazing folks at turbo-rails
|
2
|
+
# You can find its MIT License here: https://github.com/hotwired/turbo-rails/blob/main/MIT-LICENSE
|
3
|
+
|
1
4
|
module Superglue::StreamsHelper
|
2
5
|
def stream_from_props(*streamables, **attributes)
|
3
6
|
raise ArgumentError, "streamables can't be blank" unless streamables.any?(&:present?)
|
@@ -10,40 +13,40 @@ module Superglue::StreamsHelper
|
|
10
13
|
def fragment_id(value)
|
11
14
|
if value.respond_to?(:to_key)
|
12
15
|
ActionView::RecordIdentifier.dom_id(value)
|
13
|
-
elsif value.respond_to?(:
|
14
|
-
value.
|
16
|
+
elsif value.respond_to?(:broadcast_target_default)
|
17
|
+
value.broadcast_target_default
|
15
18
|
else
|
16
19
|
value.to_s
|
17
20
|
end
|
18
21
|
end
|
19
22
|
|
20
|
-
def broadcast_prepend_props(model: nil,
|
21
|
-
if
|
22
|
-
options[:saveAs] ||= fragment_id(
|
23
|
+
def broadcast_prepend_props(model: nil, target: nil, save_target: nil, options: {}, **rendering)
|
24
|
+
if save_target
|
25
|
+
options[:saveAs] ||= fragment_id(save_target)
|
23
26
|
end
|
24
27
|
|
25
|
-
broadcast_action_props(action: "prepend", model:,
|
28
|
+
broadcast_action_props(action: "prepend", model:, target:, options:, **rendering)
|
26
29
|
end
|
27
30
|
|
28
|
-
def broadcast_append_props(model: nil,
|
29
|
-
if
|
30
|
-
options[:saveAs] ||= fragment_id(
|
31
|
+
def broadcast_append_props(model: nil, target: nil, save_target: nil, options: {}, **rendering)
|
32
|
+
if save_target
|
33
|
+
options[:saveAs] ||= fragment_id(save_target)
|
31
34
|
end
|
32
35
|
|
33
|
-
broadcast_action_props(action: "append", model:,
|
36
|
+
broadcast_action_props(action: "append", model:, target:, options:, **rendering)
|
34
37
|
end
|
35
38
|
|
36
|
-
def broadcast_save_props(model: nil,
|
37
|
-
if model && !
|
38
|
-
|
39
|
+
def broadcast_save_props(model: nil, target: nil, options: {}, **rendering)
|
40
|
+
if model && !target
|
41
|
+
target = fragment_id(model)
|
39
42
|
end
|
40
43
|
|
41
|
-
broadcast_action_props(action: "save", model:,
|
44
|
+
broadcast_action_props(action: "save", model:, target:, options:, **rendering)
|
42
45
|
end
|
43
46
|
|
44
|
-
def broadcast_action_props(action:, partial: nil, model: nil,
|
47
|
+
def broadcast_action_props(action:, partial: nil, model: nil, target: nil, options: {}, **rendering)
|
45
48
|
if model
|
46
|
-
|
49
|
+
target = model.broadcast_target_default if !target
|
47
50
|
|
48
51
|
if model.respond_to?(:to_partial_path)
|
49
52
|
rendering[:locals] = (rendering[:locals] || {}).reverse_merge(model.model_name.element.to_sym => model).compact
|
@@ -51,7 +54,7 @@ module Superglue::StreamsHelper
|
|
51
54
|
end
|
52
55
|
end
|
53
56
|
|
54
|
-
|
57
|
+
target = fragment_id(target)
|
55
58
|
|
56
59
|
if !partial
|
57
60
|
raise StandardError, "A partial is needed to render a stream"
|
@@ -60,7 +63,7 @@ module Superglue::StreamsHelper
|
|
60
63
|
json = instance_variable_get(:@__json)
|
61
64
|
|
62
65
|
json.child! do
|
63
|
-
json.fragmentIds [
|
66
|
+
json.fragmentIds [target]
|
64
67
|
json.handler action
|
65
68
|
json.options(options)
|
66
69
|
json.data(partial: [partial, rendering]) do
|
@@ -1,7 +1,10 @@
|
|
1
|
+
# This file was ported from the amazing folks at turbo-rails
|
2
|
+
# You can find its MIT License here: https://github.com/hotwired/turbo-rails/blob/main/MIT-LICENSE
|
3
|
+
|
1
4
|
class Superglue::Streams::ActionBroadcastJob < ActiveJob::Base
|
2
5
|
discard_on ActiveJob::DeserializationError
|
3
6
|
|
4
|
-
def perform(stream, action:,
|
5
|
-
Superglue::StreamsChannel.broadcast_action_to stream, action: action,
|
7
|
+
def perform(stream, action:, targets:, options: {}, **rendering)
|
8
|
+
Superglue::StreamsChannel.broadcast_action_to stream, action: action, targets: targets, options: options, **rendering
|
6
9
|
end
|
7
10
|
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# This file was ported from the amazing folks at turbo-rails
|
2
|
+
# You can find its MIT License here: https://github.com/hotwired/turbo-rails/blob/main/MIT-LICENSE
|
3
|
+
|
1
4
|
class Superglue::Streams::BroadcastStreamJob < ActiveJob::Base
|
2
5
|
discard_on ActiveJob::DeserializationError
|
3
6
|
|
@@ -1,3 +1,6 @@
|
|
1
|
+
# This file was ported from the amazing folks at turbo-rails
|
2
|
+
# You can find its MIT License here: https://github.com/hotwired/turbo-rails/blob/main/MIT-LICENSE
|
3
|
+
|
1
4
|
module Superglue::Broadcastable
|
2
5
|
extend ActiveSupport::Concern
|
3
6
|
|
@@ -7,13 +10,13 @@ module Superglue::Broadcastable
|
|
7
10
|
end
|
8
11
|
|
9
12
|
module ClassMethods
|
10
|
-
def broadcasts_to(stream, inserts_by: :append,
|
11
|
-
after_create_commit -> { broadcast_action_later_to(stream.try(:call, self) || send(stream), action: inserts_by,
|
13
|
+
def broadcasts_to(stream, inserts_by: :append, target: broadcast_target_default, save_target: nil, **rendering)
|
14
|
+
after_create_commit -> { broadcast_action_later_to(stream.try(:call, self) || send(stream), action: inserts_by, target: target.try(:call, self) || target, save_target: save_target&.try(:call, self), **rendering) }
|
12
15
|
after_update_commit -> { broadcast_save_later_to(stream.try(:call, self) || send(stream), **rendering) }
|
13
16
|
end
|
14
17
|
|
15
|
-
def broadcasts(stream = model_name.plural, inserts_by: :append,
|
16
|
-
after_create_commit -> { broadcast_action_later_to(stream, action: inserts_by,
|
18
|
+
def broadcasts(stream = model_name.plural, inserts_by: :append, target: broadcast_target_default, save_target: nil, **rendering)
|
19
|
+
after_create_commit -> { broadcast_action_later_to(stream, action: inserts_by, target: target.try(:call, self) || target, save_target: save_target&.try(:call, self), **rendering) }
|
17
20
|
after_update_commit -> { broadcast_save_later(**rendering) }
|
18
21
|
end
|
19
22
|
|
@@ -27,7 +30,7 @@ module Superglue::Broadcastable
|
|
27
30
|
after_destroy_commit -> { broadcast_refresh }
|
28
31
|
end
|
29
32
|
|
30
|
-
def
|
33
|
+
def broadcast_target_default
|
31
34
|
model_name.plural
|
32
35
|
end
|
33
36
|
|
@@ -43,30 +46,30 @@ module Superglue::Broadcastable
|
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
46
|
-
# add
|
49
|
+
# add target?
|
47
50
|
def broadcast_save_to(*streamables, **rendering)
|
48
|
-
Superglue::StreamsChannel.broadcast_save_to(*streamables, **
|
51
|
+
Superglue::StreamsChannel.broadcast_save_to(*streamables, **extract_options_and_add_target(rendering, target: self)) unless suppressed_superglue_broadcasts?
|
49
52
|
end
|
50
53
|
|
51
54
|
def broadcast_save(**rendering)
|
52
55
|
broadcast_save_to self, **rendering
|
53
56
|
end
|
54
57
|
|
55
|
-
# todo
|
56
|
-
def broadcast_append_to(*streamables,
|
57
|
-
Superglue::StreamsChannel.broadcast_append_to(*streamables,
|
58
|
+
# todo save_target: true
|
59
|
+
def broadcast_append_to(*streamables, target: broadcast_target_default, save_target: nil, **rendering)
|
60
|
+
Superglue::StreamsChannel.broadcast_append_to(*streamables, save_target: save_target, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
|
58
61
|
end
|
59
62
|
|
60
|
-
def broadcast_append(
|
61
|
-
broadcast_append_to self,
|
63
|
+
def broadcast_append(target: broadcast_target_default, save_target: nil, **rendering)
|
64
|
+
broadcast_append_to self, target: target, save_target: save_target, **rendering
|
62
65
|
end
|
63
66
|
|
64
|
-
def broadcast_prepend_to(*streamables,
|
65
|
-
Superglue::StreamsChannel.broadcast_prepend_to(*streamables,
|
67
|
+
def broadcast_prepend_to(*streamables, target: broadcast_target_default, save_target: nil, **rendering)
|
68
|
+
Superglue::StreamsChannel.broadcast_prepend_to(*streamables, save_target: save_target, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
|
66
69
|
end
|
67
70
|
|
68
|
-
def broadcast_prepend(
|
69
|
-
broadcast_prepend_to self,
|
71
|
+
def broadcast_prepend(target: broadcast_target_default, save_target: nil, **rendering)
|
72
|
+
broadcast_prepend_to self, target: target, save_target: save_target, **rendering
|
70
73
|
end
|
71
74
|
|
72
75
|
def broadcast_refresh_to(*streamables)
|
@@ -78,36 +81,36 @@ module Superglue::Broadcastable
|
|
78
81
|
end
|
79
82
|
|
80
83
|
# todo rename options to js_options
|
81
|
-
def broadcast_action_to(*streamables, action:,
|
82
|
-
Superglue::StreamsChannel.broadcast_action_to(*streamables, action: action, options: options, **
|
84
|
+
def broadcast_action_to(*streamables, action:, target: broadcast_target_default, options: {}, **rendering)
|
85
|
+
Superglue::StreamsChannel.broadcast_action_to(*streamables, action: action, options: options, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
|
83
86
|
end
|
84
87
|
|
85
|
-
def broadcast_action(action,
|
86
|
-
broadcast_action_to self, action: action,
|
88
|
+
def broadcast_action(action, target: broadcast_target_default, options: {}, **rest)
|
89
|
+
broadcast_action_to self, action: action, target: target, options: options, **rest
|
87
90
|
end
|
88
91
|
|
89
92
|
def broadcast_save_later_to(*streamables, **rendering)
|
90
|
-
Superglue::StreamsChannel.broadcast_save_later_to(*streamables, **
|
93
|
+
Superglue::StreamsChannel.broadcast_save_later_to(*streamables, **extract_options_and_add_target(rendering, target: self)) unless suppressed_superglue_broadcasts?
|
91
94
|
end
|
92
95
|
|
93
96
|
def broadcast_save_later(**rendering)
|
94
97
|
broadcast_save_later_to self, **rendering
|
95
98
|
end
|
96
99
|
|
97
|
-
def broadcast_append_later_to(*streamables,
|
98
|
-
Superglue::StreamsChannel.broadcast_append_later_to(*streamables,
|
100
|
+
def broadcast_append_later_to(*streamables, target: broadcast_target_default, save_target: nil, **rendering)
|
101
|
+
Superglue::StreamsChannel.broadcast_append_later_to(*streamables, save_target: save_target, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
|
99
102
|
end
|
100
103
|
|
101
|
-
def broadcast_append_later(
|
102
|
-
broadcast_append_later_to self,
|
104
|
+
def broadcast_append_later(target: broadcast_target_default, save_target: nil, **rendering)
|
105
|
+
broadcast_append_later_to self, target: target, save_target: save_target, **rendering
|
103
106
|
end
|
104
107
|
|
105
|
-
def broadcast_prepend_later_to(*streamables,
|
106
|
-
Superglue::StreamsChannel.broadcast_prepend_later_to(*streamables,
|
108
|
+
def broadcast_prepend_later_to(*streamables, target: broadcast_target_default, save_target: nil, **rendering)
|
109
|
+
Superglue::StreamsChannel.broadcast_prepend_later_to(*streamables, save_target: save_target, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
|
107
110
|
end
|
108
111
|
|
109
|
-
def broadcast_prepend_later(
|
110
|
-
broadcast_prepend_later_to self,
|
112
|
+
def broadcast_prepend_later(target: broadcast_target_default, save_target: nil, **rendering)
|
113
|
+
broadcast_prepend_later_to self, target: target, save_target: save_target, **rendering
|
111
114
|
end
|
112
115
|
|
113
116
|
def broadcast_refresh_later_to(*streamables)
|
@@ -118,23 +121,23 @@ module Superglue::Broadcastable
|
|
118
121
|
broadcast_refresh_later_to self
|
119
122
|
end
|
120
123
|
|
121
|
-
def broadcast_action_later_to(*streamables, action:,
|
122
|
-
Superglue::StreamsChannel.broadcast_action_later_to(*streamables, action: action, options: options, **
|
124
|
+
def broadcast_action_later_to(*streamables, action:, target: broadcast_target_default, options: {}, **rendering)
|
125
|
+
Superglue::StreamsChannel.broadcast_action_later_to(*streamables, action: action, options: options, **extract_options_and_add_target(rendering, target: target)) unless suppressed_superglue_broadcasts?
|
123
126
|
end
|
124
127
|
|
125
|
-
def broadcast_action_later(action:,
|
126
|
-
broadcast_action_later_to self, action: action,
|
128
|
+
def broadcast_action_later(action:, target: broadcast_target_default, options: {}, **rendering)
|
129
|
+
broadcast_action_later_to self, action: action, target: target, options: options, **rendering
|
127
130
|
end
|
128
131
|
|
129
|
-
def
|
130
|
-
self.class.
|
132
|
+
def broadcast_target_default
|
133
|
+
self.class.broadcast_target_default
|
131
134
|
end
|
132
|
-
|
135
|
+
|
133
136
|
private
|
134
137
|
|
135
|
-
def
|
138
|
+
def extract_options_and_add_target(rendering = {}, target: broadcast_target_default)
|
136
139
|
broadcast_rendering_with_defaults(rendering).tap do |options|
|
137
|
-
options[:
|
140
|
+
options[:target] = target if !options.key?(:target) && !options.key?(:targets)
|
138
141
|
end
|
139
142
|
end
|
140
143
|
|
@@ -40,7 +40,7 @@ module Superglue
|
|
40
40
|
insert_jsx_rendering_defaults
|
41
41
|
|
42
42
|
say "Installing Superglue and friends"
|
43
|
-
run "yarn add react react-dom @reduxjs/toolkit react-redux @thoughtbot/superglue@2.0.0-alpha.
|
43
|
+
run "yarn add react react-dom @reduxjs/toolkit react-redux @thoughtbot/superglue@2.0.0-alpha.8"
|
44
44
|
|
45
45
|
if use_typescript
|
46
46
|
run "yarn add -D @types/react-dom @types/react @types/node @thoughtbot/candy_wrapper"
|
@@ -5,7 +5,7 @@ import { buildVisitAndRemote } from "./application_visit"
|
|
5
5
|
import { pageIdentifierToPageComponent } from "./page_to_page_mapping"
|
6
6
|
import { store } from "./store"
|
7
7
|
|
8
|
-
if (typeof window !== "undefined") {
|
8
|
+
if (typeof window !== "undefined" && window.SUPERGLUE_INITIAL_PAGE_STATE) {
|
9
9
|
document.addEventListener("DOMContentLoaded", function() {
|
10
10
|
const appEl = document.getElementById("app")
|
11
11
|
const location = window.location
|
@@ -9,7 +9,7 @@ import { visit, remote } from "@thoughtbot/superglue/action_creators"
|
|
9
9
|
* bar. This file also adds support for data-sg-remote.
|
10
10
|
*/
|
11
11
|
export const buildVisitAndRemote = (ref, store) => {
|
12
|
-
const appRemote = (path, { dataset, ...options }) => {
|
12
|
+
const appRemote = (path, { dataset, ...options } = {}) => {
|
13
13
|
/**
|
14
14
|
* You can make use of `dataset` to add custom UJS options.
|
15
15
|
* If you are implementing a progress bar, you can selectively
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { createSlice } from "@reduxjs/toolkit"
|
2
|
-
import {
|
2
|
+
import { receiveResponse , beforeVisit } from "@thoughtbot/superglue"
|
3
3
|
|
4
4
|
const initialState = {}
|
5
5
|
|
@@ -30,12 +30,16 @@ export const flashSlice = createSlice({
|
|
30
30
|
builder.addCase(beforeVisit, (_state, _action) => {
|
31
31
|
return {}
|
32
32
|
})
|
33
|
-
builder.addCase(
|
34
|
-
const {
|
33
|
+
builder.addCase(receiveResponse , (state, action) => {
|
34
|
+
const { response } = action.payload
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
if(response.slices) {
|
37
|
+
return {
|
38
|
+
...state,
|
39
|
+
...response.slices.flash
|
40
|
+
}
|
41
|
+
} else {
|
42
|
+
return state
|
39
43
|
}
|
40
44
|
})
|
41
45
|
}
|
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
rootReducer
|
9
9
|
} from "@thoughtbot/superglue"
|
10
10
|
|
11
|
-
const { pages, superglue } = rootReducer
|
11
|
+
const { pages, superglue, fragments } = rootReducer
|
12
12
|
|
13
13
|
export const store = configureStore({
|
14
14
|
devTools: process.env.NODE_ENV !== "production",
|
@@ -21,7 +21,8 @@ export const store = configureStore({
|
|
21
21
|
reducer: {
|
22
22
|
superglue,
|
23
23
|
pages,
|
24
|
-
flash: flashSlice.reducer
|
24
|
+
flash: flashSlice.reducer,
|
25
|
+
fragments,
|
25
26
|
}
|
26
27
|
})
|
27
28
|
|
@@ -1,15 +1,17 @@
|
|
1
|
-
import React from
|
2
|
-
import { createRoot } from
|
3
|
-
import { Application,
|
4
|
-
import { buildVisitAndRemote } from
|
5
|
-
import { pageIdentifierToPageComponent } from
|
6
|
-
import { store } from
|
1
|
+
import React from "react";
|
2
|
+
import { createRoot } from "react-dom/client";
|
3
|
+
import { Application, SaveResponse } from "@thoughtbot/superglue";
|
4
|
+
import { buildVisitAndRemote } from "./application_visit";
|
5
|
+
import { pageIdentifierToPageComponent } from "./page_to_page_mapping";
|
6
|
+
import { store } from "./store";
|
7
7
|
|
8
8
|
declare global {
|
9
|
-
interface Window {
|
9
|
+
interface Window {
|
10
|
+
SUPERGLUE_INITIAL_PAGE_STATE: SaveResponse;
|
11
|
+
}
|
10
12
|
}
|
11
13
|
|
12
|
-
if (typeof window !== "undefined") {
|
14
|
+
if (typeof window !== "undefined" && window.SUPERGLUE_INITIAL_PAGE_STATE) {
|
13
15
|
document.addEventListener("DOMContentLoaded", function () {
|
14
16
|
const appEl = document.getElementById("app");
|
15
17
|
const location = window.location;
|
@@ -37,4 +39,3 @@ if (typeof window !== "undefined") {
|
|
37
39
|
}
|
38
40
|
});
|
39
41
|
}
|
40
|
-
|
@@ -18,7 +18,7 @@ export const buildVisitAndRemote: BuildVisitAndRemote = (
|
|
18
18
|
ref,
|
19
19
|
store: SuperglueStore
|
20
20
|
) => {
|
21
|
-
const appRemote: ApplicationRemote = (path, { dataset, ...options }) => {
|
21
|
+
const appRemote: ApplicationRemote = (path, { dataset, ...options } = {}) => {
|
22
22
|
/**
|
23
23
|
* You can make use of `dataset` to add custom UJS options.
|
24
24
|
* If you are implementing a progress bar, you can selectively
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { createSlice } from "@reduxjs/toolkit";
|
2
|
-
import {
|
2
|
+
import { receiveResponse, beforeVisit } from "@thoughtbot/superglue";
|
3
3
|
|
4
|
-
type FlashState = Record<string, any
|
4
|
+
type FlashState = Record<string, any>;
|
5
5
|
|
6
6
|
const initialState: FlashState = {};
|
7
7
|
|
@@ -32,13 +32,17 @@ export const flashSlice = createSlice({
|
|
32
32
|
builder.addCase(beforeVisit, (_state, _action) => {
|
33
33
|
return {};
|
34
34
|
});
|
35
|
-
builder.addCase(
|
36
|
-
const {
|
35
|
+
builder.addCase(receiveResponse, (state, action) => {
|
36
|
+
const { response } = action.payload;
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
if (response.slices) {
|
39
|
+
return {
|
40
|
+
...state,
|
41
|
+
...(response.slices.flash as FlashState),
|
42
|
+
};
|
43
|
+
} else {
|
44
|
+
return state;
|
45
|
+
}
|
42
46
|
});
|
43
47
|
},
|
44
48
|
});
|
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
rootReducer,
|
9
9
|
} from "@thoughtbot/superglue";
|
10
10
|
|
11
|
-
const { pages, superglue } = rootReducer;
|
11
|
+
const { pages, superglue, fragments } = rootReducer;
|
12
12
|
|
13
13
|
export const store = configureStore({
|
14
14
|
devTools: process.env.NODE_ENV !== "production",
|
@@ -22,6 +22,7 @@ export const store = configureStore({
|
|
22
22
|
superglue,
|
23
23
|
pages,
|
24
24
|
flash: flashSlice.reducer,
|
25
|
+
fragments,
|
25
26
|
},
|
26
27
|
});
|
27
28
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superglue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.alpha.
|
4
|
+
version: 2.0.0.alpha.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johny Ho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|