stimulus_reflex 3.5.0.pre8 → 3.5.0.pre10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of stimulus_reflex might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -1218
- data/Gemfile +0 -1
- data/Gemfile.lock +145 -193
- data/README.md +48 -20
- data/Rakefile +0 -8
- data/app/assets/javascripts/stimulus_reflex.js +1174 -0
- data/app/assets/javascripts/stimulus_reflex.min.js +2 -0
- data/app/assets/javascripts/stimulus_reflex.min.js.map +1 -0
- data/app/assets/javascripts/stimulus_reflex.umd.js +1064 -0
- data/app/assets/javascripts/stimulus_reflex.umd.min.js +1065 -0
- data/app/assets/javascripts/stimulus_reflex.umd.min.js.map +1 -0
- data/app/channels/stimulus_reflex/channel.rb +28 -7
- data/bin/console +0 -2
- data/bin/standardize +2 -1
- data/lib/generators/stimulus_reflex/stimulus_reflex_generator.rb +72 -7
- data/lib/generators/stimulus_reflex/templates/app/controllers/examples_controller.rb.tt +9 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/channels/consumer.js.tt +6 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/channels/index.js.esbuild.tt +4 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/channels/index.js.importmap.tt +2 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/channels/index.js.shakapacker.tt +5 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/channels/index.js.vite.tt +1 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/channels/index.js.webpacker.tt +5 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/cable_ready.js.tt +4 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/index.js.tt +2 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/mrujs.js.tt +9 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/stimulus_reflex.js.tt +5 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt +114 -74
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application.js.tt +11 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application_controller.js.tt +49 -35
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/index.js.esbuild.tt +7 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/index.js.importmap.tt +5 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/index.js.shakapacker.tt +5 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/index.js.vite.tt +5 -0
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/index.js.webpacker.tt +5 -0
- data/lib/generators/stimulus_reflex/templates/app/reflexes/%file_name%_reflex.rb.tt +38 -7
- data/lib/generators/stimulus_reflex/templates/app/reflexes/application_reflex.rb.tt +10 -2
- data/lib/generators/stimulus_reflex/templates/app/views/examples/show.html.erb.tt +207 -0
- data/lib/generators/stimulus_reflex/templates/config/initializers/cable_ready.rb +22 -0
- data/lib/generators/stimulus_reflex/templates/config/initializers/stimulus_reflex.rb +18 -13
- data/lib/generators/stimulus_reflex/templates/esbuild.config.mjs.tt +94 -0
- data/lib/install/action_cable.rb +155 -0
- data/lib/install/broadcaster.rb +90 -0
- data/lib/install/bundle.rb +56 -0
- data/lib/install/compression.rb +41 -0
- data/lib/install/config.rb +87 -0
- data/lib/install/development.rb +110 -0
- data/lib/install/esbuild.rb +114 -0
- data/lib/install/example.rb +22 -0
- data/lib/install/importmap.rb +133 -0
- data/lib/install/initializers.rb +25 -0
- data/lib/install/mrujs.rb +133 -0
- data/lib/install/npm_packages.rb +25 -0
- data/lib/install/reflexes.rb +25 -0
- data/lib/install/shakapacker.rb +64 -0
- data/lib/install/spring.rb +54 -0
- data/lib/install/updatable.rb +34 -0
- data/lib/install/vite.rb +64 -0
- data/lib/install/webpacker.rb +90 -0
- data/lib/install/yarn.rb +55 -0
- data/lib/stimulus_reflex/broadcasters/broadcaster.rb +15 -8
- data/lib/stimulus_reflex/broadcasters/page_broadcaster.rb +7 -8
- data/lib/stimulus_reflex/broadcasters/selector_broadcaster.rb +10 -10
- data/lib/stimulus_reflex/broadcasters/update.rb +3 -0
- data/lib/stimulus_reflex/cable_readiness.rb +29 -0
- data/lib/stimulus_reflex/cable_ready_channels.rb +5 -5
- data/lib/stimulus_reflex/callbacks.rb +17 -1
- data/lib/stimulus_reflex/concern_enhancer.rb +6 -4
- data/lib/stimulus_reflex/configuration.rb +12 -2
- data/lib/stimulus_reflex/dataset.rb +11 -1
- data/lib/stimulus_reflex/engine.rb +40 -0
- data/lib/stimulus_reflex/html/document.rb +59 -0
- data/lib/stimulus_reflex/html/document_fragment.rb +13 -0
- data/lib/stimulus_reflex/importmap.rb +7 -0
- data/lib/stimulus_reflex/installer.rb +274 -0
- data/lib/stimulus_reflex/open_struct_fix.rb +31 -0
- data/lib/stimulus_reflex/reflex.rb +32 -25
- data/lib/stimulus_reflex/reflex_data.rb +18 -2
- data/lib/stimulus_reflex/reflex_factory.rb +6 -3
- data/lib/stimulus_reflex/request_parameters.rb +2 -0
- data/lib/stimulus_reflex/utils/logger.rb +12 -0
- data/lib/stimulus_reflex/utils/sanity_checker.rb +8 -106
- data/lib/stimulus_reflex/version.rb +1 -1
- data/lib/stimulus_reflex.rb +4 -6
- data/lib/tasks/stimulus_reflex/stimulus_reflex.rake +252 -0
- data/package.json +73 -0
- data/rollup.config.mjs +86 -0
- data/stimulus_reflex.gemspec +60 -0
- data/web-test-runner.config.mjs +12 -0
- data/yarn.lock +5098 -0
- metadata +191 -78
- data/LATEST +0 -1
- data/lib/generators/USAGE +0 -14
- data/lib/generators/stimulus_reflex/initializer_generator.rb +0 -14
- data/lib/tasks/stimulus_reflex/install.rake +0 -116
- data/test/broadcasters/broadcaster_test.rb +0 -11
- data/test/broadcasters/broadcaster_test_case.rb +0 -39
- data/test/broadcasters/nothing_broadcaster_test.rb +0 -30
- data/test/broadcasters/page_broadcaster_test.rb +0 -77
- data/test/broadcasters/selector_broadcaster_test.rb +0 -167
- data/test/callbacks_test.rb +0 -652
- data/test/concern_enhancer_test.rb +0 -54
- data/test/element_test.rb +0 -254
- data/test/generators/stimulus_reflex_generator_test.rb +0 -58
- data/test/reflex_test.rb +0 -43
- data/test/test_helper.rb +0 -71
- data/test/tmp/app/reflexes/application_reflex.rb +0 -19
- data/test/tmp/app/reflexes/demo_reflex.rb +0 -35
@@ -1,101 +1,141 @@
|
|
1
1
|
import ApplicationController from './application_controller'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
* If you intend to use this controller as a regular stimulus controller as well,
|
12
|
-
* make sure any Stimulus lifecycle methods overridden in ApplicationController call super.
|
13
|
-
*
|
14
|
-
* Important:
|
15
|
-
* By default, StimulusReflex overrides the -connect- method so make sure you
|
16
|
-
* call super if you intend to do anything else when this controller connects.
|
17
|
-
*/
|
3
|
+
<%- if class_name == "Example" -%>
|
4
|
+
//
|
5
|
+
// This is the Stimulus controller for the Example Reflex.
|
6
|
+
//
|
7
|
+
// It corresponds to the server-side Reflex class located at /app/reflexes/example.rb
|
8
|
+
//
|
9
|
+
// Learn more at: https://docs.stimulusreflex.com/guide/reflexes
|
10
|
+
//
|
18
11
|
|
12
|
+
<%- end -%>
|
13
|
+
export default class extends ApplicationController {
|
19
14
|
connect () {
|
15
|
+
<%- if class_name == "Example" -%>
|
16
|
+
//
|
17
|
+
// StimulusReflex overrides the Stimulus `connect` method. Make sure to call
|
18
|
+
// `super.connect()` so that any code in your superclass `connect` is run.
|
19
|
+
//
|
20
|
+
<%- end -%>
|
20
21
|
super.connect()
|
21
|
-
// add your code here, if applicable
|
22
22
|
}
|
23
|
+
<%- if class_name == "Example" -%>
|
23
24
|
|
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
|
-
<% if actions.empty? -%>
|
51
|
-
// Assuming you create a "<%= class_name %>#dance" action in your Reflex class
|
52
|
-
// you'll be able to use the following lifecycle methods:
|
53
|
-
|
54
|
-
// beforeDance(element, reflex, noop, reflexId) {
|
55
|
-
// element.innerText = 'Putting dance shoes on...'
|
25
|
+
// With StimulusReflex active in your project, it will continuously scan your DOM for
|
26
|
+
// `data-reflex` attributes on your elements, even if they are dynamically created.
|
27
|
+
//
|
28
|
+
// <a href="#" data-reflex="click->Example#dance">Dance!</a>
|
29
|
+
//
|
30
|
+
// We call this a "declared" Reflex, because it doesn't require any JS to run.
|
31
|
+
//
|
32
|
+
// When your user clicks this link, a Reflex is launched and it calls the `dance` method
|
33
|
+
// on your Example Reflex class. You don't have to do anything else!
|
34
|
+
//
|
35
|
+
// This Stimulus controller doesn't even need to exist for StimulusReflex to work its magic.
|
36
|
+
// https://docs.stimulusreflex.com/guide/reflexes#declaring-a-reflex-in-html-with-data-attributes
|
37
|
+
//
|
38
|
+
// However...
|
39
|
+
//
|
40
|
+
// If we do create an `example` Stimulus controller that extends `ApplicationController`,
|
41
|
+
// we can unlock several additional capabilities, including creating Reflexes with code.
|
42
|
+
//
|
43
|
+
// <a href="#" data-controller="example" data-action="example#dance">Dance!</a>
|
44
|
+
//
|
45
|
+
// StimulusReflex gives our controller a new method, `stimulate`:
|
46
|
+
//
|
47
|
+
// dance() {
|
48
|
+
// this.stimulate('Example#dance')
|
56
49
|
// }
|
50
|
+
//
|
51
|
+
// The `stimulate` method is very flexible, and it gives you the opportunity to pass
|
52
|
+
// parameter options that will be passed to the `dance` method on the server.
|
53
|
+
// https://docs.stimulusreflex.com/guide/reflexes#calling-a-reflex-in-a-stimulus-controller
|
54
|
+
//
|
55
|
+
// Reflex lifecycle methods
|
56
|
+
//
|
57
|
+
// For every method defined in your Reflex class, a matching set of optional
|
58
|
+
// lifecycle callback methods become available in this javascript controller.
|
59
|
+
// https://docs.stimulusreflex.com/guide/lifecycle#client-side-reflex-callbacks
|
60
|
+
//
|
61
|
+
// <a href="#" data-reflex="click->Example#dance" data-controller="example">Dance!</a>
|
62
|
+
//
|
63
|
+
// StimulusReflex will check for the presence of several methods:
|
64
|
+
//
|
65
|
+
// afterReflex(element, reflex, noop, id) {
|
66
|
+
// // fires after every Example Reflex action
|
67
|
+
// }
|
68
|
+
//
|
69
|
+
// afterDance(element, reflex, noop, id) {
|
70
|
+
// // fires after Example Reflexes calling the dance action
|
71
|
+
// }
|
72
|
+
//
|
73
|
+
// Arguments:
|
74
|
+
//
|
75
|
+
// element - the element that triggered the reflex
|
76
|
+
// may be different than the Stimulus controller's this.element
|
77
|
+
//
|
78
|
+
// reflex - the name of the reflex e.g. "Example#dance"
|
79
|
+
//
|
80
|
+
// error/noop - the error message (for reflexError), otherwise null
|
81
|
+
//
|
82
|
+
// id - a UUID4 or developer-provided unique identifier for each Reflex
|
83
|
+
//
|
84
|
+
// Access to the client-side Reflex objects created by this controller
|
85
|
+
//
|
86
|
+
// Every Reflex you create is represented by an object in the global Reflexes collection.
|
87
|
+
// You can access the Example Reflexes created by this controller via the `reflexes` proxy.
|
88
|
+
//
|
89
|
+
// this.reflexes.last
|
90
|
+
// this.reflexes.all
|
91
|
+
// this.reflexes.all[id]
|
92
|
+
// this.reflexes.error
|
93
|
+
//
|
94
|
+
// The proxy allows you to access the most recent Reflex, an array of all Reflexes, a specific
|
95
|
+
// Reflex specified by its `id` and an array of all Reflexes in a given lifecycle stage.
|
96
|
+
//
|
97
|
+
// If you explore the Reflex object, you'll see all relevant details,
|
98
|
+
// including the `data` that is being delivered to the server.
|
99
|
+
//
|
100
|
+
// Pretty cool, right?
|
101
|
+
//
|
102
|
+
<%- end -%>
|
103
|
+
<%- actions.each do |action| -%>
|
57
104
|
|
58
|
-
//
|
59
|
-
//
|
105
|
+
// <%= "before_#{action}".camelize(:lower) %>(element, reflex, noop, id) {
|
106
|
+
// console.log("before <%= action %>", element, reflex, id)
|
60
107
|
// }
|
61
108
|
|
62
|
-
//
|
63
|
-
// console.
|
64
|
-
// element.innerText = "\nCouldn\'t dance!"
|
109
|
+
// <%= "#{action}_queued".camelize(:lower) %>(element, reflex, noop, id) {
|
110
|
+
// console.log("<%= action %> enqueued for delivery upon connection", element, reflex, id)
|
65
111
|
// }
|
66
112
|
|
67
|
-
//
|
68
|
-
//
|
113
|
+
// <%= "#{action}_delivered".camelize(:lower) %>(element, reflex, noop, id) {
|
114
|
+
// console.log("<%= action %> delivered to the server", element, reflex, id)
|
69
115
|
// }
|
70
116
|
|
71
|
-
//
|
72
|
-
//
|
73
|
-
// }
|
74
|
-
<% end -%>
|
75
|
-
<% actions.each do |action| -%>
|
76
|
-
// <%= "before_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
|
77
|
-
// console.log("before <%= action %>", element, reflex, reflexId)
|
117
|
+
// <%= "#{action}_success".camelize(:lower) %>(element, reflex, noop, id) {
|
118
|
+
// console.log("<%= action %> successfully executed", element, reflex, id)
|
78
119
|
// }
|
79
120
|
|
80
|
-
// <%= "#{action}
|
81
|
-
// console.
|
121
|
+
// <%= "#{action}_error".camelize(:lower) %>(element, reflex, error, id) {
|
122
|
+
// console.error("<%= action %> server-side error", element, reflex, error, id)
|
82
123
|
// }
|
83
124
|
|
84
|
-
// <%= "#{action}
|
85
|
-
// console.
|
125
|
+
// <%= "#{action}_halted".camelize(:lower) %>(element, reflex, noop, id) {
|
126
|
+
// console.warn("<%= action %> halted before execution", element, reflex, id)
|
86
127
|
// }
|
87
128
|
|
88
|
-
// <%= "#{action}
|
89
|
-
// console.warn("<%= action %>
|
129
|
+
// <%= "#{action}_forbidden".camelize(:lower) %>(element, reflex, noop, id) {
|
130
|
+
// console.warn("<%= action %> forbidden from executing", element, reflex, id)
|
90
131
|
// }
|
91
132
|
|
92
|
-
// <%= "after_#{action}".camelize(:lower) %>(element, reflex, noop,
|
93
|
-
// console.log("
|
133
|
+
// <%= "after_#{action}".camelize(:lower) %>(element, reflex, noop, id) {
|
134
|
+
// console.log("<%= action %> has been executed by the server", element, reflex, id)
|
94
135
|
// }
|
95
136
|
|
96
|
-
// <%= "finalize_#{action}".camelize(:lower) %>(element, reflex, noop,
|
97
|
-
// console.log("
|
137
|
+
// <%= "finalize_#{action}".camelize(:lower) %>(element, reflex, noop, id) {
|
138
|
+
// console.log("<%= action %> changes have been applied", element, reflex, id)
|
98
139
|
// }
|
99
|
-
|
100
|
-
<% end -%>
|
140
|
+
<%- end -%>
|
101
141
|
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Application } from "@hotwired/stimulus"
|
2
|
+
import consumer from "../channels/consumer"
|
3
|
+
|
4
|
+
const application = Application.start()
|
5
|
+
|
6
|
+
// Configure Stimulus development experience
|
7
|
+
application.debug = false
|
8
|
+
application.consumer = consumer
|
9
|
+
window.Stimulus = application
|
10
|
+
|
11
|
+
export { application }
|
@@ -1,60 +1,74 @@
|
|
1
|
-
import { Controller } from 'stimulus'
|
1
|
+
import { Controller } from '@hotwired/stimulus'
|
2
2
|
import StimulusReflex from 'stimulus_reflex'
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
4
|
+
// This is the Stimulus ApplicationController.
|
5
|
+
// All StimulusReflex controllers should inherit from this class.
|
6
|
+
//
|
7
|
+
// Example:
|
8
|
+
//
|
9
|
+
// import ApplicationController from './application_controller'
|
10
|
+
//
|
11
|
+
// export default class extends ApplicationController { ... }
|
12
|
+
//
|
13
|
+
// Learn more at: https://docs.stimulusreflex.com
|
14
|
+
//
|
15
|
+
|
15
16
|
export default class extends Controller {
|
16
17
|
connect () {
|
17
18
|
StimulusReflex.register(this)
|
18
19
|
}
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
beforeReflex (element, reflex, noop,
|
21
|
+
// Application-wide lifecycle methods
|
22
|
+
//
|
23
|
+
// Use these methods to handle lifecycle callbacks for all controllers.
|
24
|
+
// Using lifecycle methods is optional, so feel free to delete these if you don't need them.
|
25
|
+
//
|
26
|
+
// Arguments:
|
27
|
+
//
|
28
|
+
// element - the element that triggered the reflex
|
29
|
+
// may be different than the Stimulus controller's this.element
|
30
|
+
//
|
31
|
+
// reflex - the name of the reflex e.g. "Example#demo"
|
32
|
+
//
|
33
|
+
// error/noop - the error message (for reflexError), otherwise null
|
34
|
+
//
|
35
|
+
// id - a UUID4 or developer-provided unique identifier for each Reflex
|
36
|
+
//
|
37
|
+
|
38
|
+
beforeReflex (element, reflex, noop, id) {
|
38
39
|
// document.body.classList.add('wait')
|
39
40
|
}
|
40
41
|
|
41
|
-
|
42
|
+
reflexQueued (element, reflex, noop, id) {
|
43
|
+
// Reflex will be delivered to server upon reconnection
|
44
|
+
}
|
45
|
+
|
46
|
+
reflexDelivered (element, reflex, noop, id) {
|
47
|
+
// Reflex has been delivered to the server
|
48
|
+
}
|
49
|
+
|
50
|
+
reflexSuccess (element, reflex, noop, id) {
|
42
51
|
// show success message
|
43
52
|
}
|
44
53
|
|
45
|
-
reflexError (element, reflex, error,
|
54
|
+
reflexError (element, reflex, error, id) {
|
46
55
|
// show error message
|
47
56
|
}
|
48
57
|
|
49
|
-
|
58
|
+
reflexForbidden (element, reflex, noop, id) {
|
59
|
+
// Reflex action did not have permission to run
|
60
|
+
// window.location = '/'
|
61
|
+
}
|
62
|
+
|
63
|
+
reflexHalted (element, reflex, noop, id) {
|
50
64
|
// handle aborted Reflex action
|
51
65
|
}
|
52
66
|
|
53
|
-
afterReflex (element, reflex, noop,
|
67
|
+
afterReflex (element, reflex, noop, id) {
|
54
68
|
// document.body.classList.remove('wait')
|
55
69
|
}
|
56
70
|
|
57
|
-
finalizeReflex (element, reflex, noop,
|
71
|
+
finalizeReflex (element, reflex, noop, id) {
|
58
72
|
// all operations have completed, animation etc is now safe
|
59
73
|
}
|
60
74
|
}
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class <%= class_name %>Reflex < ApplicationReflex
|
4
|
+
<%- if class_name == "Example" -%>
|
4
5
|
# Add Reflex methods in this file.
|
5
6
|
#
|
6
7
|
# All Reflex instances include CableReady::Broadcaster and expose the following properties:
|
@@ -16,26 +17,56 @@ class <%= class_name %>Reflex < ApplicationReflex
|
|
16
17
|
# - signed - use a signed Global ID to map dataset attribute to a model eg. element.signed[:foo]
|
17
18
|
# - unsigned - use an unsigned Global ID to map dataset attribute to a model eg. element.unsigned[:foo]
|
18
19
|
# - cable_ready - a special cable_ready that can broadcast to the current visitor (no brackets needed)
|
19
|
-
# -
|
20
|
+
# - id - a UUIDv4 that uniquely identifies each Reflex
|
20
21
|
# - tab_id - a UUIDv4 that uniquely identifies the browser tab
|
21
22
|
#
|
22
23
|
# Example:
|
23
24
|
#
|
24
25
|
# before_reflex do
|
25
26
|
# # throw :abort # this will prevent the Reflex from continuing
|
26
|
-
# # learn more about callbacks at https://docs.stimulusreflex.com/
|
27
|
+
# # learn more about callbacks at https://docs.stimulusreflex.com/guide/lifecycle
|
27
28
|
# end
|
28
29
|
#
|
29
30
|
# def example(argument=true)
|
30
|
-
# # Your logic here...
|
31
|
+
# # Your logic here! Update models, launch jobs, poll Redis...
|
32
|
+
#
|
33
|
+
# # By default, Reflexes call the controller action for the current page and render the view.
|
31
34
|
# # Any declared instance variables will be made available to the Rails controller and view.
|
35
|
+
#
|
36
|
+
# # You can also use the `morph` method to mark a Reflex as Selector or Nothing.
|
37
|
+
# # https://docs.stimulusreflex.com/guide/morph-modes#introducing-morphs
|
32
38
|
# end
|
33
39
|
#
|
34
|
-
# Learn more at: https://docs.stimulusreflex.com/
|
40
|
+
# Learn more at: https://docs.stimulusreflex.com/guide/reflex-classes
|
41
|
+
|
42
|
+
<%- end -%>
|
43
|
+
<%- if class_name == "Example" -%>
|
44
|
+
def increment
|
45
|
+
count = session[:count] || 0
|
46
|
+
session[:count] = count + 1
|
47
|
+
|
48
|
+
morph "#time", Time.now
|
49
|
+
morph "#count", session[:count]
|
50
|
+
|
51
|
+
cable_ready.set_value(selector: "progress", value: session[:count])
|
35
52
|
|
36
|
-
|
53
|
+
if session[:count] == 5
|
54
|
+
cable_ready.text_content(selector: "#reload", text: "Try reloading your browser window. The count is persisted in the session!")
|
55
|
+
end
|
56
|
+
|
57
|
+
if session[:count] >= 10
|
58
|
+
cable_ready.dispatch_event(name: "fireworks")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def reset
|
63
|
+
session[:count] = 0
|
64
|
+
end
|
65
|
+
<%- else -%>
|
66
|
+
<%- actions.each do |action| -%>
|
37
67
|
def <%= action %>
|
38
68
|
end
|
39
|
-
<%= "\n" unless action == actions.last -%>
|
40
|
-
|
69
|
+
<%= "\n" unless action == actions.last -%>
|
70
|
+
<%- end -%>
|
71
|
+
<%- end -%>
|
41
72
|
end
|
@@ -3,11 +3,19 @@
|
|
3
3
|
class ApplicationReflex < StimulusReflex::Reflex
|
4
4
|
# Put application-wide Reflex behavior and callbacks in this file.
|
5
5
|
#
|
6
|
-
# Learn more at: https://docs.stimulusreflex.com/
|
6
|
+
# Learn more at: https://docs.stimulusreflex.com/guide/reflex-classes
|
7
7
|
#
|
8
8
|
# If your ActionCable connection is: `identified_by :current_user`
|
9
9
|
# delegate :current_user, to: :connection
|
10
10
|
#
|
11
|
+
# current_user delegation alloqs you to use the Current pattern, too:
|
12
|
+
# before_reflex do
|
13
|
+
# Current.user = current_user
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# To access view helpers inside Reflexes:
|
17
|
+
# delegate :helpers, to: :ApplicationController
|
18
|
+
#
|
11
19
|
# If you need to localize your Reflexes, you can set the I18n locale here:
|
12
20
|
#
|
13
21
|
# before_reflex do
|
@@ -15,5 +23,5 @@ class ApplicationReflex < StimulusReflex::Reflex
|
|
15
23
|
# end
|
16
24
|
#
|
17
25
|
# For code examples, considerations and caveats, see:
|
18
|
-
# https://docs.stimulusreflex.com/
|
26
|
+
# https://docs.stimulusreflex.com/guide/patterns#internationalization
|
19
27
|
end
|