stimulus_reflex 3.4.0.pre5 → 3.4.0.pre6

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.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -2
  3. data/Gemfile.lock +5 -5
  4. data/README.md +2 -5
  5. data/Rakefile +5 -5
  6. data/bin/console +1 -0
  7. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt +14 -2
  8. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application_controller.js.tt +10 -2
  9. data/lib/generators/stimulus_reflex/templates/app/reflexes/%file_name%_reflex.rb.tt +18 -9
  10. data/lib/generators/stimulus_reflex/templates/app/reflexes/application_reflex.rb.tt +2 -2
  11. data/lib/stimulus_reflex.rb +1 -0
  12. data/lib/stimulus_reflex/broadcasters/broadcaster.rb +2 -4
  13. data/lib/stimulus_reflex/broadcasters/page_broadcaster.rb +1 -1
  14. data/lib/stimulus_reflex/broadcasters/selector_broadcaster.rb +2 -2
  15. data/lib/stimulus_reflex/cable_ready_channels.rb +18 -0
  16. data/lib/stimulus_reflex/reflex.rb +2 -2
  17. data/lib/stimulus_reflex/sanity_checker.rb +11 -4
  18. data/lib/stimulus_reflex/version.rb +1 -1
  19. data/package.json +2 -2
  20. data/stimulus_reflex.gemspec +1 -1
  21. data/tags +82 -41
  22. data/test/broadcasters/broadcaster_test.rb +2 -7
  23. data/test/broadcasters/broadcaster_test_case.rb +13 -0
  24. data/test/broadcasters/nothing_broadcaster_test.rb +26 -27
  25. data/test/broadcasters/page_broadcaster_test.rb +55 -51
  26. data/test/broadcasters/selector_broadcaster_test.rb +55 -83
  27. data/test/test_helper.rb +37 -2
  28. data/test/tmp/app/reflexes/application_reflex.rb +2 -2
  29. data/test/tmp/app/reflexes/demo_reflex.rb +34 -0
  30. data/yarn.lock +4 -4
  31. metadata +9 -6
  32. data/test/tmp/app/reflexes/posts_reflex.rb +0 -24
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1744cbfb7c9c5508487beb3d0087c77b6cc532386ef503709aa0c0097b4f56e
4
- data.tar.gz: 99ce8b8d1ad3190d5cd90e49182b39ec959a39f3accb4784f2d0cccbfb7e6fe4
3
+ metadata.gz: 7c1b21d72db7dc3cae4b0a6225af2a17af6505e43b46d10a4db1ff1505566d1f
4
+ data.tar.gz: 0a0d7acc4ebaf2b9f717e0cf01f0cdcb2999694627f960cea27db10693b5480e
5
5
  SHA512:
6
- metadata.gz: faccf3117f5cb17303725bab3ba659a77314e44908a1b5d1d5184e171b2635c44a10a42f7e19cbfefa6231a6488d1364b6b463a04e3438e1b92aff237545d515
7
- data.tar.gz: 126a3dc45916880d97b6ab1971dfb2a433b1d8e1c27b3c7a1c32a5d0b55ee0ae7c50bfdb9b10901525520b0ae1e975a083125a26305147e62252464a872b15db
6
+ metadata.gz: 92b7b673a36cea3d4bbbf3b491524a6f1819d5a7d477b0609bd605f236a24a4dc6a8c1ec9af336399a1179376c3e5257dd8266933607e45d183bb63220ddf1b8
7
+ data.tar.gz: baada4b0985537e8aed1717f383cde05c94bcd502e047d6a58bbbb50580a691960f1ff792c8cefbc07a0940c1541f0e1eea985be9193d345db92d99c0560a054
@@ -2,7 +2,23 @@
2
2
 
3
3
  ## [Unreleased](https://github.com/hopsoft/stimulus_reflex/tree/HEAD)
4
4
 
5
- [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre4...HEAD)
5
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre5...HEAD)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - Update templates for new stage etc [\#390](https://github.com/hopsoft/stimulus_reflex/pull/390) ([leastbad](https://github.com/leastbad))
10
+ - reflexError and received refactor [\#389](https://github.com/hopsoft/stimulus_reflex/pull/389) ([leastbad](https://github.com/leastbad))
11
+ - add jQuery support to SR library events [\#388](https://github.com/hopsoft/stimulus_reflex/pull/388) ([leastbad](https://github.com/leastbad))
12
+ - dont exit in sanity checker on `stimulus\_reflex:install` [\#387](https://github.com/hopsoft/stimulus_reflex/pull/387) ([marcoroth](https://github.com/marcoroth))
13
+ - Allow `success` and `after` lifecycle methods on replaced elements [\#386](https://github.com/hopsoft/stimulus_reflex/pull/386) ([marcoroth](https://github.com/marcoroth))
14
+ - split SR operations from data.operations [\#385](https://github.com/hopsoft/stimulus_reflex/pull/385) ([leastbad](https://github.com/leastbad))
15
+ - don't show findElement warnings unless debugging [\#384](https://github.com/hopsoft/stimulus_reflex/pull/384) ([leastbad](https://github.com/leastbad))
16
+ - Setup a proxy object that wraps CableReady::Channels [\#382](https://github.com/hopsoft/stimulus_reflex/pull/382) ([hopsoft](https://github.com/hopsoft))
17
+ - non-SR cable\_ready operation pass-through [\#381](https://github.com/hopsoft/stimulus_reflex/pull/381) ([leastbad](https://github.com/leastbad))
18
+
19
+ ## [v3.4.0.pre5](https://github.com/hopsoft/stimulus_reflex/tree/v3.4.0.pre5) (2020-11-25)
20
+
21
+ [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.4.0.pre4...v3.4.0.pre5)
6
22
 
7
23
  **Closed issues:**
8
24
 
@@ -254,7 +270,6 @@
254
270
  **Implemented enhancements:**
255
271
 
256
272
  - Returns more helpful error message if Reflex doesn't exist [\#254](https://github.com/hopsoft/stimulus_reflex/pull/254) ([leastbad](https://github.com/leastbad))
257
- - Update install.rake to handle Typescript [\#241](https://github.com/hopsoft/stimulus_reflex/pull/241) ([iv-mexx](https://github.com/iv-mexx))
258
273
  - Morph Modes: page, selector and nothing [\#211](https://github.com/hopsoft/stimulus_reflex/pull/211) ([leastbad](https://github.com/leastbad))
259
274
 
260
275
  **Fixed bugs:**
@@ -295,6 +310,10 @@
295
310
 
296
311
  [Full Changelog](https://github.com/hopsoft/stimulus_reflex/compare/v3.2.2...v3.2.3)
297
312
 
313
+ **Implemented enhancements:**
314
+
315
+ - Update install.rake to handle Typescript [\#241](https://github.com/hopsoft/stimulus_reflex/pull/241) ([iv-mexx](https://github.com/iv-mexx))
316
+
298
317
  **Fixed bugs:**
299
318
 
300
319
  - Add more smarts to \_\_perform [\#235](https://github.com/hopsoft/stimulus_reflex/pull/235) ([hopsoft](https://github.com/hopsoft))
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stimulus_reflex (3.4.0.pre5)
5
- cable_ready (>= 4.3.0)
4
+ stimulus_reflex (3.4.0.pre6)
5
+ cable_ready (>= 4.4)
6
6
  nokogiri
7
7
  rack
8
8
  rails (>= 5.2)
@@ -68,7 +68,7 @@ GEM
68
68
  zeitwerk (~> 2.2, >= 2.2.2)
69
69
  ast (2.4.1)
70
70
  builder (3.2.4)
71
- cable_ready (4.4.0)
71
+ cable_ready (4.4.1)
72
72
  rails (>= 5.2)
73
73
  coderay (1.1.3)
74
74
  concurrent-ruby (1.1.7)
@@ -78,7 +78,7 @@ GEM
78
78
  activesupport (>= 4.2.0)
79
79
  i18n (1.8.5)
80
80
  concurrent-ruby (~> 1.0)
81
- loofah (2.7.0)
81
+ loofah (2.8.0)
82
82
  crass (~> 1.0.2)
83
83
  nokogiri (>= 1.5.9)
84
84
  mail (2.7.1)
@@ -170,7 +170,7 @@ GEM
170
170
  websocket-driver (0.7.3)
171
171
  websocket-extensions (>= 0.1.0)
172
172
  websocket-extensions (0.1.5)
173
- zeitwerk (2.4.1)
173
+ zeitwerk (2.4.2)
174
174
 
175
175
  PLATFORMS
176
176
  ruby
data/README.md CHANGED
@@ -11,7 +11,7 @@
11
11
  <img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-brightgreen.svg" target="_blank" />
12
12
  </a>
13
13
  <a href="http://blog.codinghorror.com/the-best-code-is-no-code-at-all/" target="_blank">
14
- <img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-1506-brightgreen.svg?style=flat" />
14
+ <img alt="Lines of Code" src="https://img.shields.io/badge/lines_of_code-1599-brightgreen.svg?style=flat" />
15
15
  </a>
16
16
  <a href="https://docs.stimulusreflex.com/" target="_blank">
17
17
  <img alt="Documentation" src="https://img.shields.io/badge/documentation-yes-brightgreen.svg" />
@@ -30,9 +30,6 @@
30
30
  <a href="https://www.codacy.com/manual/hopsoft/stimulus_reflex/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=hopsoft/stimulus_reflex&amp;utm_campaign=Badge_Grade" target="_blank">
31
31
  <img alt="Code Quality" src="https://app.codacy.com/project/badge/Grade/d1d72a7060f5467b8696884351cf477f"/>
32
32
  </a>
33
- <a href="https://codeclimate.com/github/hopsoft/stimulus_reflex/maintainability" target="_blank">
34
- <img alt="Maintainability" src="https://api.codeclimate.com/v1/badges/2b24fdbd1ae37a24bedb/maintainability" />
35
- </a>
36
33
  <a target="_blank" rel="noopener noreferrer" href="https://github.com/hopsoft/stimulus_reflex/workflows/Prettier-Standard/badge.svg">
37
34
  <img src="https://github.com/hopsoft/stimulus_reflex/workflows/Prettier-Standard/badge.svg" alt="Prettier-Standard" style="max-width:100%;">
38
35
  </a>
@@ -77,7 +74,7 @@ This project strives to live up to the vision outlined in [The Rails Doctrine](h
77
74
 
78
75
  ## 👩‍👩‍👧 Discord Community
79
76
 
80
- Please join over 700 of us on [Discord](https://discord.gg/XveN625) for support getting started, as well as active discussions around Rails, StimulusJS and CableReady.
77
+ Please join over 800 of us on [Discord](https://discord.gg/XveN625) for support getting started, as well as active discussions around Rails, StimulusJS and CableReady.
81
78
 
82
79
  ![](https://img.shields.io/discord/629472241427415060)
83
80
 
data/Rakefile CHANGED
@@ -3,13 +3,13 @@
3
3
  require "bundler/gem_tasks"
4
4
  require "rails/test_unit/runner"
5
5
 
6
- task default: [:test]
7
-
8
- task :test do |task|
9
- return 1 unless system("yarn run test")
10
- Rails::TestUnit::Runner.run
6
+ task :test_javascript do |task|
7
+ system "yarn run test"
11
8
  end
12
9
 
13
10
  task :test_ruby do |task|
14
11
  Rails::TestUnit::Runner.run
15
12
  end
13
+
14
+ task test: [:test_javascript, :test_ruby]
15
+ task default: [:test]
@@ -4,4 +4,5 @@ require "bundler/setup"
4
4
  require "stimulus_reflex"
5
5
  require "pry"
6
6
 
7
+ StimulusReflex.configuration.parent_channel = "ActionCable::Channel::Base"
7
8
  Pry.start
@@ -56,12 +56,20 @@ export default class extends ApplicationController {
56
56
  // }
57
57
 
58
58
  // danceSuccess(element, reflex, noop, reflexId) {
59
- // element.innerText = 'Danced like no one was watching! Was someone watching?'
59
+ // element.innerText = '\nDanced like no one was watching! Was someone watching?'
60
60
  // }
61
61
 
62
62
  // danceError(element, reflex, error, reflexId) {
63
63
  // console.error('danceError', error);
64
- // element.innerText = "Couldn't dance!"
64
+ // element.innerText = "\nCouldn\'t dance!"
65
+ // }
66
+
67
+ // afterDance(element, reflex, noop, reflexId) {
68
+ // element.innerText = '\nWhatever that was, it\'s over now.'
69
+ // }
70
+
71
+ // finalizeDance(element, reflex, noop, reflexId) {
72
+ // element.innerText = '\nNow, the cleanup can begin!'
65
73
  // }
66
74
  <% end -%>
67
75
  <% actions.each do |action| -%>
@@ -84,6 +92,10 @@ export default class extends ApplicationController {
84
92
  // <%= "after_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
85
93
  // console.log("after <%= action %>", element, reflex, reflexId)
86
94
  // }
95
+
96
+ // <%= "finalize_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
97
+ // console.log("finalize <%= action %>", element, reflex, reflexId)
98
+ // }
87
99
  <%= "\n" unless action == actions.last -%>
88
100
  <% end -%>
89
101
  }
@@ -39,14 +39,22 @@ export default class extends Controller {
39
39
  }
40
40
 
41
41
  reflexSuccess (element, reflex, noop, reflexId) {
42
- // show success message etc...
42
+ // show success message
43
43
  }
44
44
 
45
45
  reflexError (element, reflex, error, reflexId) {
46
- // show error message etc...
46
+ // show error message
47
+ }
48
+
49
+ reflexHalted (element, reflex, error, reflexId) {
50
+ // handle aborted Reflex action
47
51
  }
48
52
 
49
53
  afterReflex (element, reflex, noop, reflexId) {
50
54
  // document.body.classList.remove('wait')
51
55
  }
56
+
57
+ finalizeReflex (element, reflex, noop, reflexId) {
58
+ // all operations have completed, animation etc is now safe
59
+ }
52
60
  }
@@ -3,24 +3,33 @@
3
3
  class <%= class_name %>Reflex < ApplicationReflex
4
4
  # Add Reflex methods in this file.
5
5
  #
6
- # All Reflex instances expose the following properties:
6
+ # All Reflex instances include CableReady::Broadcaster and expose the following properties:
7
7
  #
8
- # - connection - the ActionCable connection
9
- # - channel - the ActionCable channel
10
- # - request - an ActionDispatch::Request proxy for the socket connection
11
- # - session - the ActionDispatch::Session store for the current visitor
12
- # - url - the URL of the page that triggered the reflex
13
- # - element - a Hash like object that represents the HTML element that triggered the reflex
14
- # - params - parameters from the element's closest form (if any)
8
+ # - connection - the ActionCable connection
9
+ # - channel - the ActionCable channel
10
+ # - request - an ActionDispatch::Request proxy for the socket connection
11
+ # - session - the ActionDispatch::Session store for the current visitor
12
+ # - flash - the ActionDispatch::Flash::FlashHash for the current request
13
+ # - url - the URL of the page that triggered the reflex
14
+ # - params - parameters from the element's closest form (if any)
15
+ # - element - a Hash like object that represents the HTML element that triggered the reflex
16
+ # - signed - use a signed Global ID to map dataset attribute to a model eg. element.signed[:foo]
17
+ # - unsigned - use an unsigned Global ID to map dataset attribute to a model eg. element.unsigned[:foo]
18
+ # - cable_ready - a special cable_ready that can broadcast to the current visitor (no brackets needed)
15
19
  #
16
20
  # Example:
17
21
  #
22
+ # before_reflex do
23
+ # # throw :abort # this will prevent the Reflex from continuing
24
+ # # learn more about callbacks at https://docs.stimulusreflex.com/lifecycle
25
+ # end
26
+ #
18
27
  # def example(argument=true)
19
28
  # # Your logic here...
20
29
  # # Any declared instance variables will be made available to the Rails controller and view.
21
30
  # end
22
31
  #
23
- # Learn more at: https://docs.stimulusreflex.com
32
+ # Learn more at: https://docs.stimulusreflex.com/reflexes#reflex-classes
24
33
 
25
34
  <% actions.each do |action| -%>
26
35
  def <%= action %>
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ApplicationReflex < StimulusReflex::Reflex
4
- # Put application wide Reflex behavior in this file.
4
+ # Put application-wide Reflex behavior and callbacks in this file.
5
5
  #
6
6
  # Example:
7
7
  #
8
8
  # # If your ActionCable connection is: `identified_by :current_user`
9
9
  # delegate :current_user, to: :connection
10
10
  #
11
- # Learn more at: https://docs.stimulusreflex.com
11
+ # Learn more at: https://docs.stimulusreflex.com/reflexes#reflex-classes
12
12
  end
@@ -9,6 +9,7 @@ require "action_cable"
9
9
  require "nokogiri"
10
10
  require "cable_ready"
11
11
  require "stimulus_reflex/version"
12
+ require "stimulus_reflex/cable_ready_channels"
12
13
  require "stimulus_reflex/configuration"
13
14
  require "stimulus_reflex/reflex"
14
15
  require "stimulus_reflex/element"
@@ -2,10 +2,8 @@
2
2
 
3
3
  module StimulusReflex
4
4
  class Broadcaster
5
- include CableReady::Broadcaster
6
-
7
5
  attr_reader :reflex, :logger, :operations
8
- delegate :permanent_attribute_name, :stream_name, to: :reflex
6
+ delegate :cable_ready, :permanent_attribute_name, to: :reflex
9
7
 
10
8
  def initialize(reflex)
11
9
  @reflex = reflex
@@ -28,7 +26,7 @@ module StimulusReflex
28
26
  def broadcast_message(subject:, body: nil, data: {}, error: nil)
29
27
  logger.error "\e[31m#{body}\e[0m" if subject == "error"
30
28
  operations << ["document", :dispatch_event]
31
- cable_ready[stream_name].dispatch_event(
29
+ cable_ready.dispatch_event(
32
30
  name: "stimulus-reflex:server-message",
33
31
  detail: {
34
32
  reflexId: data["reflexId"],
@@ -13,7 +13,7 @@ module StimulusReflex
13
13
  selectors.each do |selector|
14
14
  operations << [selector, :morph]
15
15
  html = document.css(selector).inner_html
16
- cable_ready[stream_name].morph(
16
+ cable_ready.morph(
17
17
  selector: selector,
18
18
  html: html,
19
19
  children_only: true,
@@ -12,7 +12,7 @@ module StimulusReflex
12
12
  match = fragment.at_css(selector)
13
13
  if match.present?
14
14
  operations << [selector, :morph]
15
- cable_ready[stream_name].morph(
15
+ cable_ready.morph(
16
16
  selector: selector,
17
17
  html: match.inner_html,
18
18
  children_only: true,
@@ -23,7 +23,7 @@ module StimulusReflex
23
23
  )
24
24
  else
25
25
  operations << [selector, :inner_html]
26
- cable_ready[stream_name].inner_html(
26
+ cable_ready.inner_html(
27
27
  selector: selector,
28
28
  html: fragment.to_html,
29
29
  stimulus_reflex: data.merge({
@@ -0,0 +1,18 @@
1
+ module StimulusReflex
2
+ class CableReadyChannels
3
+ def initialize(stream_name)
4
+ @cable_ready_channels = CableReady::Channels.instance
5
+ @stimulus_reflex_channel = @cable_ready_channels[stream_name]
6
+ end
7
+
8
+ def method_missing(name, *args)
9
+ return @stimulus_reflex_channel.send(name, *args) if @stimulus_reflex_channel.respond_to?(name)
10
+ @cable_ready_channels.send(name, *args)
11
+ end
12
+
13
+ def respond_to_missing?(name, include_all)
14
+ @stimulus_reflex_channel.respond_to?(name, include_all) ||
15
+ @cable_ready_channels.respond_to?(name, include_all)
16
+ end
17
+ end
18
+ end
@@ -5,7 +5,6 @@ ClientAttributes = Struct.new(:reflex_id, :reflex_controller, :xpath, :c_xpath,
5
5
  class StimulusReflex::Reflex
6
6
  include ActiveSupport::Rescuable
7
7
  include ActiveSupport::Callbacks
8
- include CableReady::Broadcaster
9
8
 
10
9
  define_callbacks :process, skip_after_callbacks_if_terminated: true
11
10
 
@@ -45,7 +44,7 @@ class StimulusReflex::Reflex
45
44
  end
46
45
  end
47
46
 
48
- attr_reader :channel, :url, :element, :selectors, :method_name, :broadcaster, :client_attributes, :logger
47
+ attr_reader :cable_ready, :channel, :url, :element, :selectors, :method_name, :broadcaster, :client_attributes, :logger
49
48
 
50
49
  alias_method :action_name, :method_name # for compatibility with controller libraries like Pundit that expect an action name
51
50
 
@@ -64,6 +63,7 @@ class StimulusReflex::Reflex
64
63
  @broadcaster = StimulusReflex::PageBroadcaster.new(self)
65
64
  @logger = StimulusReflex::Logger.new(self)
66
65
  @client_attributes = ClientAttributes.new(client_attributes)
66
+ @cable_ready = StimulusReflex::CableReadyChannels.new(stream_name)
67
67
  self.params
68
68
  end
69
69
 
@@ -6,6 +6,7 @@ class StimulusReflex::SanityChecker
6
6
  class << self
7
7
  def check!
8
8
  return if StimulusReflex.config.on_failed_sanity_checks == :ignore
9
+ return if called_by_installer?
9
10
  return if called_by_generate_config?
10
11
 
11
12
  instance = new
@@ -15,6 +16,12 @@ class StimulusReflex::SanityChecker
15
16
 
16
17
  private
17
18
 
19
+ def called_by_installer?
20
+ Rake.application.top_level_tasks.include? "stimulus_reflex:install"
21
+ rescue
22
+ false
23
+ end
24
+
18
25
  def called_by_generate_config?
19
26
  ARGV.include? "stimulus_reflex:config"
20
27
  end
@@ -120,13 +127,13 @@ class StimulusReflex::SanityChecker
120
127
  puts <<~INFO
121
128
  If you know what you are doing and you want to start the application anyway,
122
129
  you can create a StimulusReflex initializer with the command:
123
-
130
+
124
131
  bundle exec rails generate stimulus_reflex:config
125
-
132
+
126
133
  Then open your initializer at
127
-
134
+
128
135
  <RAILS_ROOT>/config/initializers/stimulus_reflex.rb
129
-
136
+
130
137
  and then add the following directive:
131
138
 
132
139
  StimulusReflex.configure do |config|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StimulusReflex
4
- VERSION = "3.4.0.pre5"
4
+ VERSION = "3.4.0.pre6"
5
5
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stimulus_reflex",
3
- "version": "3.4.0-pre4",
3
+ "version": "3.4.0-pre5",
4
4
  "description": "Build reactive applications with the Rails tooling you already know and love.",
5
5
  "keywords": [
6
6
  "ruby",
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@rails/actioncable": ">= 6.0",
44
- "cable_ready": ">= 4.3.0"
44
+ "cable_ready": ">= 4.4"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@babel/core": "^7.6.2",
@@ -30,7 +30,7 @@ Gem::Specification.new do |gem|
30
30
  gem.add_dependency "nokogiri"
31
31
  gem.add_dependency "rails", ">= 5.2"
32
32
  gem.add_dependency "redis"
33
- gem.add_dependency "cable_ready", ">= 4.3.0"
33
+ gem.add_dependency "cable_ready", ">= 4.4"
34
34
 
35
35
  gem.add_development_dependency "bundler", "~> 2.0"
36
36
  gem.add_development_dependency "pry-nav"
data/tags CHANGED
@@ -6,93 +6,134 @@
6
6
  !_TAG_PROGRAM_VERSION 5.8 //
7
7
  ApplicationReflex test/tmp/app/reflexes/application_reflex.rb /^class ApplicationReflex < StimulusReflex::Reflex$/;" c
8
8
  Broadcaster lib/stimulus_reflex/broadcasters/broadcaster.rb /^ class Broadcaster$/;" c class:StimulusReflex
9
- CompareXML lib/stimulus_reflex/compare_xml.rb /^module CompareXML$/;" m
9
+ CableReadyChannels lib/stimulus_reflex/cable_ready_channels.rb /^ class CableReadyChannels$/;" c class:StimulusReflex
10
+ Colorize lib/stimulus_reflex/utils/colorize.rb /^ module Colorize$/;" m class:StimulusReflex.Utils
11
+ ConfigGenerator lib/generators/stimulus_reflex/config_generator.rb /^ class ConfigGenerator < Rails::Generators::Base$/;" c class:StimulusReflex
12
+ Configuration lib/stimulus_reflex/configuration.rb /^ class Configuration$/;" c
10
13
  Engine lib/stimulus_reflex.rb /^ class Engine < Rails::Engine$/;" c class:StimulusReflex
14
+ Logger lib/stimulus_reflex/logger.rb /^ class Logger$/;" c class:StimulusReflex
11
15
  NothingBroadcaster lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb /^ class NothingBroadcaster < Broadcaster$/;" c class:StimulusReflex
12
16
  PageBroadcaster lib/stimulus_reflex/broadcasters/page_broadcaster.rb /^ class PageBroadcaster < Broadcaster$/;" c class:StimulusReflex
17
+ PostsReflex test/tmp/app/reflexes/posts_reflex.rb /^class PostsReflex < ApplicationReflex$/;" c
13
18
  SelectorBroadcaster lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^ class SelectorBroadcaster < Broadcaster$/;" c class:StimulusReflex
19
+ StimulusReflex app/channels/stimulus_reflex/channel.rb /^class StimulusReflex::Channel < StimulusReflex.configuration.parent_channel.constantize$/;" c
20
+ StimulusReflex lib/generators/stimulus_reflex/config_generator.rb /^module StimulusReflex$/;" m
14
21
  StimulusReflex lib/stimulus_reflex.rb /^module StimulusReflex$/;" m
15
22
  StimulusReflex lib/stimulus_reflex/broadcasters/broadcaster.rb /^module StimulusReflex$/;" m
16
23
  StimulusReflex lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb /^module StimulusReflex$/;" m
17
24
  StimulusReflex lib/stimulus_reflex/broadcasters/page_broadcaster.rb /^module StimulusReflex$/;" m
18
25
  StimulusReflex lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^module StimulusReflex$/;" m
19
- StimulusReflex lib/stimulus_reflex/channel.rb /^class StimulusReflex::Channel < ActionCable::Channel::Base$/;" c
26
+ StimulusReflex lib/stimulus_reflex/cable_ready_channels.rb /^module StimulusReflex$/;" m
27
+ StimulusReflex lib/stimulus_reflex/configuration.rb /^module StimulusReflex$/;" m
20
28
  StimulusReflex lib/stimulus_reflex/element.rb /^class StimulusReflex::Element < OpenStruct$/;" c
29
+ StimulusReflex lib/stimulus_reflex/logger.rb /^module StimulusReflex$/;" m
21
30
  StimulusReflex lib/stimulus_reflex/reflex.rb /^class StimulusReflex::Reflex$/;" c
31
+ StimulusReflex lib/stimulus_reflex/sanity_checker.rb /^class StimulusReflex::SanityChecker$/;" c
32
+ StimulusReflex lib/stimulus_reflex/utils/colorize.rb /^module StimulusReflex$/;" m
22
33
  StimulusReflex lib/stimulus_reflex/version.rb /^module StimulusReflex$/;" m
23
- StimulusReflexGenerator lib/generators/stimulus_reflex_generator.rb /^class StimulusReflexGenerator < Rails::Generators::NamedBase$/;" c
34
+ StimulusReflex test/broadcasters/broadcaster_test.rb /^class StimulusReflex::BroadcasterTest < ActiveSupport::TestCase$/;" c
35
+ StimulusReflex test/broadcasters/nothing_broadcaster_test.rb /^class StimulusReflex::NothingBroadcasterTest < ActiveSupport::TestCase$/;" c
36
+ StimulusReflex test/broadcasters/page_broadcaster_test.rb /^class StimulusReflex::PageBroadcasterTest < ActiveSupport::TestCase$/;" c
37
+ StimulusReflex test/broadcasters/selector_broadcaster_test.rb /^class StimulusReflex::SelectorBroadcasterTest < ActiveSupport::TestCase$/;" c
38
+ StimulusReflexGenerator lib/generators/stimulus_reflex/stimulus_reflex_generator.rb /^class StimulusReflexGenerator < Rails::Generators::NamedBase$/;" c
24
39
  StimulusReflexGeneratorTest test/generators/stimulus_reflex_generator_test.rb /^class StimulusReflexGeneratorTest < Rails::Generators::TestCase$/;" c
25
- UserReflex test/tmp/app/reflexes/user_reflex.rb /^class UserReflex < ApplicationReflex$/;" c
26
- addDifference lib/stimulus_reflex/compare_xml.rb /^ def addDifference(node1, node2, diff1, diff2, opts, differences)$/;" f class:CompareXML
40
+ Utils lib/stimulus_reflex/utils/colorize.rb /^ module Utils$/;" m class:StimulusReflex
27
41
  add_callback lib/stimulus_reflex/reflex.rb /^ def add_callback(kind, *args, &block)$/;" f class:StimulusReflex
28
42
  after_reflex lib/stimulus_reflex/reflex.rb /^ def after_reflex(*args, &block)$/;" f class:StimulusReflex
43
+ append_morph lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^ def append_morph(selectors, html)$/;" f class:StimulusReflex.SelectorBroadcaster
29
44
  around_reflex lib/stimulus_reflex/reflex.rb /^ def around_reflex(*args, &block)$/;" f class:StimulusReflex
30
- attrContentExcluded? lib/stimulus_reflex/compare_xml.rb /^ def attrContentExcluded?(a1, a2, opts)$/;" f class:CompareXML
31
- attrNameExcluded? lib/stimulus_reflex/compare_xml.rb /^ def attrNameExcluded?(a1, a2, opts)$/;" f class:CompareXML
32
- attrsExcluded? lib/stimulus_reflex/compare_xml.rb /^ def attrsExcluded?(a1, a2, opts)$/;" f class:CompareXML
33
45
  before_reflex lib/stimulus_reflex/reflex.rb /^ def before_reflex(*args, &block)$/;" f class:StimulusReflex
34
46
  broadcast lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def broadcast(*args)$/;" f class:StimulusReflex.Broadcaster
35
47
  broadcast lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb /^ def broadcast(_, data)$/;" f class:StimulusReflex.NothingBroadcaster
36
48
  broadcast lib/stimulus_reflex/broadcasters/page_broadcaster.rb /^ def broadcast(selectors, data)$/;" f class:StimulusReflex.PageBroadcaster
37
49
  broadcast lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^ def broadcast(_, data = {})$/;" f class:StimulusReflex.SelectorBroadcaster
38
- broadcast_message lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def broadcast_message(subject:, body: nil, data: {})$/;" f class:StimulusReflex.Broadcaster
39
- collapse lib/stimulus_reflex/compare_xml.rb /^ def collapse(text)$/;" f class:CompareXML
40
- commit_session lib/stimulus_reflex/channel.rb /^ def commit_session(reflex)$/;" f class:StimulusReflex
41
- compareAttributeSets lib/stimulus_reflex/compare_xml.rb /^ def compareAttributeSets(n1, n2, a1_set, a2_set, opts, differences)$/;" f class:CompareXML
42
- compareAttributes lib/stimulus_reflex/compare_xml.rb /^ def compareAttributes(n1, n2, a1, a2, opts, differences, status = EQUIVALENT)$/;" f class:CompareXML
43
- compareChildren lib/stimulus_reflex/compare_xml.rb /^ def compareChildren(n1_set, n2_set, opts, differences, diffchildren = false, status = EQUIVALENT)$/;" f class:CompareXML
44
- compareCommentNodes lib/stimulus_reflex/compare_xml.rb /^ def compareCommentNodes(n1, n2, opts, differences, status = EQUIVALENT)$/;" f class:CompareXML
45
- compareDocumentNodes lib/stimulus_reflex/compare_xml.rb /^ def compareDocumentNodes(n1, n2, opts, differences, childopts = {}, diffchildren = false, status = EQUIVALENT)$/;" f class:CompareXML
46
- compareElementNodes lib/stimulus_reflex/compare_xml.rb /^ def compareElementNodes(n1, n2, opts, differences, childopts = {}, diffchildren = false, status = EQUIVALENT)$/;" f class:CompareXML
47
- compareNodes lib/stimulus_reflex/compare_xml.rb /^ def compareNodes(n1, n2, opts, differences, childopts = {}, diffchildren = false, status = EQUIVALENT)$/;" f class:CompareXML
48
- compareSortedAttributeSets lib/stimulus_reflex/compare_xml.rb /^ def compareSortedAttributeSets(n1, n2, a1_set, a2_set, opts, differences, status = EQUIVALENT)$/;" f class:CompareXML
49
- compareTextNodes lib/stimulus_reflex/compare_xml.rb /^ def compareTextNodes(n1, n2, opts, differences, status = EQUIVALENT)$/;" f class:CompareXML
50
- compareUnsortedAttributeSets lib/stimulus_reflex/compare_xml.rb /^ def compareUnsortedAttributeSets(n1, n2, a1_set, a2_set, opts, differences, status = EQUIVALENT)$/;" f class:CompareXML
50
+ broadcast_message lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def broadcast_message(subject:, body: nil, data: {}, error: nil)$/;" f class:StimulusReflex.Broadcaster
51
+ caching_enabled? lib/stimulus_reflex/sanity_checker.rb /^ def caching_enabled?$/;" f
52
+ called_by_generate_config? lib/stimulus_reflex/sanity_checker.rb /^ def called_by_generate_config?$/;" f class:StimulusReflex
53
+ check! lib/stimulus_reflex/sanity_checker.rb /^ def check!$/;" f class:StimulusReflex
54
+ check_caching_enabled lib/stimulus_reflex/sanity_checker.rb /^ def check_caching_enabled$/;" f
55
+ check_javascript_package_version lib/stimulus_reflex/sanity_checker.rb /^ def check_javascript_package_version$/;" f
56
+ commit_session app/channels/stimulus_reflex/channel.rb /^ def commit_session(reflex)$/;" f class:StimulusReflex
57
+ config_logging lib/stimulus_reflex/logger.rb /^ def config_logging$/;" f class:StimulusReflex.Logger
58
+ configuration lib/stimulus_reflex/configuration.rb /^ def configuration$/;" f class:StimulusReflex
59
+ configure lib/stimulus_reflex/configuration.rb /^ def configure$/;" f class:StimulusReflex
60
+ connection_id lib/stimulus_reflex/logger.rb /^ def connection_id$/;" f class:StimulusReflex.Logger
61
+ connection_id_full lib/stimulus_reflex/logger.rb /^ def connection_id_full$/;" f class:StimulusReflex.Logger
51
62
  controller lib/stimulus_reflex/reflex.rb /^ def controller$/;" f
52
- copy_application_files lib/generators/stimulus_reflex_generator.rb /^ def copy_application_files$/;" f class:StimulusReflexGenerator
63
+ copy_application_files lib/generators/stimulus_reflex/stimulus_reflex_generator.rb /^ def copy_application_files$/;" f class:StimulusReflexGenerator
64
+ copy_config_file lib/generators/stimulus_reflex/config_generator.rb /^ def copy_config_file$/;" f class:StimulusReflex.ConfigGenerator
53
65
  dataset lib/stimulus_reflex/element.rb /^ def dataset$/;" f class:StimulusReflex
54
66
  default_reflex lib/stimulus_reflex/reflex.rb /^ def default_reflex$/;" f
55
- delegate_call_to_reflex lib/stimulus_reflex/channel.rb /^ def delegate_call_to_reflex(reflex, method_name, arguments = [])$/;" f class:StimulusReflex
56
- do_more_stuff test/tmp/app/reflexes/user_reflex.rb /^ def do_more_stuff$/;" f class:UserReflex
57
- do_stuff test/tmp/app/reflexes/user_reflex.rb /^ def do_stuff$/;" f class:UserReflex
58
- enqueue_message lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def enqueue_message(subject:, body: nil, data: {})$/;" f class:StimulusReflex.Broadcaster
59
- equivalent? lib/stimulus_reflex/compare_xml.rb /^ def equivalent?(n1, n2, opts = {}, childopts = {}, diffchildren = false)$/;" f class:CompareXML
60
- error javascript/log.js /^function error (response) {$/;" f
61
- exception_message_with_backtrace lib/stimulus_reflex/channel.rb /^ def exception_message_with_backtrace(exception)$/;" f class:StimulusReflex
62
- execute lib/generators/stimulus_reflex_generator.rb /^ def execute$/;" f class:StimulusReflexGenerator
67
+ delegate_call_to_reflex app/channels/stimulus_reflex/channel.rb /^ def delegate_call_to_reflex(reflex, method_name, arguments = [])$/;" f class:StimulusReflex
68
+ exception_message_with_backtrace app/channels/stimulus_reflex/channel.rb /^ def exception_message_with_backtrace(exception)$/;" f class:StimulusReflex
69
+ execute lib/generators/stimulus_reflex/stimulus_reflex_generator.rb /^ def execute$/;" f class:StimulusReflexGenerator
70
+ exit_with_info lib/stimulus_reflex/sanity_checker.rb /^ def exit_with_info$/;" f
63
71
  export.reflexAttribute javascript/schema.js /^ reflexAttribute: 'data-reflex',$/;" p
64
72
  export.reflexDatasetAttribute javascript/schema.js /^ reflexDatasetAttribute: 'data-reflex-dataset'$/;" p
65
73
  export.reflexPermanentAttribute javascript/schema.js /^ reflexPermanentAttribute: 'data-reflex-permanent',$/;" p
66
74
  export.reflexRootAttribute javascript/schema.js /^ reflexRootAttribute: 'data-reflex-root',$/;" p
67
75
  findConsumer javascript/consumer.js /^function findConsumer (object, depth = 0) {$/;" f
68
- function.success javascript/log.js /^function success (response, options = { halted: false }) {$/;" f
76
+ find_javascript_package_version lib/stimulus_reflex/sanity_checker.rb /^ def find_javascript_package_version$/;" f
77
+ fix_environment! app/channels/stimulus_reflex/channel.rb /^ def fix_environment!$/;" f class:StimulusReflex
78
+ function.error javascript/log.js /^function error (event) {$/;" f
79
+ gem_version lib/stimulus_reflex/sanity_checker.rb /^ def gem_version$/;" f
69
80
  halted? lib/stimulus_reflex/reflex.rb /^ def halted?$/;" f
70
81
  initialize lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def initialize(reflex)$/;" f class:StimulusReflex.Broadcaster
82
+ initialize lib/stimulus_reflex/cable_ready_channels.rb /^ def initialize(stream_name)$/;" f class:StimulusReflex.CableReadyChannels
83
+ initialize lib/stimulus_reflex/configuration.rb /^ def initialize$/;" f class:Configuration
71
84
  initialize lib/stimulus_reflex/element.rb /^ def initialize(data = {})$/;" f class:StimulusReflex
72
- initialize lib/stimulus_reflex/reflex.rb /^ def initialize(channel, url: nil, element: nil, selectors: [], method_name: nil, permanent_attribute_name: nil, params: {})$/;" f
73
- is_reflex? lib/stimulus_reflex/channel.rb /^ def is_reflex?(reflex_class)$/;" f class:StimulusReflex
85
+ initialize lib/stimulus_reflex/logger.rb /^ def initialize(reflex)$/;" f class:StimulusReflex.Logger
86
+ initialize lib/stimulus_reflex/reflex.rb /^ def initialize(channel, url: nil, element: nil, selectors: [], method_name: nil, params: {}, client_attributes: {})$/;" f
87
+ initializer_path lib/stimulus_reflex/sanity_checker.rb /^ def initializer_path$/;" f
88
+ is_reflex? app/channels/stimulus_reflex/channel.rb /^ def is_reflex?(reflex_class)$/;" f class:StimulusReflex
89
+ javascript_package_version lib/stimulus_reflex/sanity_checker.rb /^ def javascript_package_version$/;" f
90
+ javascript_version_matches? lib/stimulus_reflex/sanity_checker.rb /^ def javascript_version_matches?$/;" f
91
+ method_missing lib/stimulus_reflex/cable_ready_channels.rb /^ def method_missing(name, *args)$/;" f class:StimulusReflex.CableReadyChannels
92
+ method_missing lib/stimulus_reflex/logger.rb /^ def method_missing method$/;" f class:StimulusReflex.Logger
93
+ mode lib/stimulus_reflex/logger.rb /^ def mode$/;" f class:StimulusReflex.Logger
74
94
  morph lib/stimulus_reflex/reflex.rb /^ def morph(selectors, html = "")$/;" f
75
95
  morphs lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^ def morphs$/;" f class:StimulusReflex.SelectorBroadcaster
76
- nodeExcluded? lib/stimulus_reflex/compare_xml.rb /^ def nodeExcluded?(n, opts)$/;" f class:CompareXML
77
96
  normalize_callback_option! lib/stimulus_reflex/reflex.rb /^ def normalize_callback_option!(options, from, to)$/;" f class:StimulusReflex
78
97
  normalize_callback_options! lib/stimulus_reflex/reflex.rb /^ def normalize_callback_options!(options)$/;" f class:StimulusReflex
98
+ not_null_store? lib/stimulus_reflex/sanity_checker.rb /^ def not_null_store?$/;" f
79
99
  nothing? lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def nothing?$/;" f class:StimulusReflex.Broadcaster
80
100
  nothing? lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb /^ def nothing?$/;" f class:StimulusReflex.NothingBroadcaster
81
- object_with_indifferent_access lib/stimulus_reflex/channel.rb /^ def object_with_indifferent_access(object)$/;" f class:StimulusReflex
101
+ object_with_indifferent_access app/channels/stimulus_reflex/channel.rb /^ def object_with_indifferent_access(object)$/;" f class:StimulusReflex
102
+ operation lib/stimulus_reflex/logger.rb /^ def operation$/;" f class:StimulusReflex.Logger
103
+ operation_counter lib/stimulus_reflex/logger.rb /^ def operation_counter$/;" f class:StimulusReflex.Logger
104
+ package_json_path lib/stimulus_reflex/sanity_checker.rb /^ def package_json_path$/;" f
82
105
  page? lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def page?$/;" f class:StimulusReflex.Broadcaster
83
106
  page? lib/stimulus_reflex/broadcasters/page_broadcaster.rb /^ def page?$/;" f class:StimulusReflex.PageBroadcaster
84
- page_cache lib/stimulus_reflex/channel.rb /^ def page_cache$/;" f class:StimulusReflex
85
107
  params lib/stimulus_reflex/reflex.rb /^ def params$/;" f
108
+ print lib/stimulus_reflex/logger.rb /^ def print$/;" f class:StimulusReflex.Logger
109
+ private_instance_methods lib/stimulus_reflex/logger.rb /^ def private_instance_methods$/;" f class:StimulusReflex.Logger
86
110
  process lib/stimulus_reflex/reflex.rb /^ def process(name, *args)$/;" f
87
- receive lib/stimulus_reflex/channel.rb /^ def receive(data)$/;" f class:StimulusReflex
111
+ receive app/channels/stimulus_reflex/channel.rb /^ def receive(data)$/;" f class:StimulusReflex
112
+ reflex_id lib/stimulus_reflex/logger.rb /^ def reflex_id$/;" f class:StimulusReflex.Logger
113
+ reflex_id_full lib/stimulus_reflex/logger.rb /^ def reflex_id_full$/;" f class:StimulusReflex.Logger
114
+ reflex_info lib/stimulus_reflex/logger.rb /^ def reflex_info$/;" f class:StimulusReflex.Logger
115
+ request javascript/log.js /^function request (reflexId, target, args, controller, element) {$/;" f
88
116
  request lib/stimulus_reflex/reflex.rb /^ def request$/;" f
117
+ request.success javascript/log.js /^function success (event) {$/;" f
118
+ respond_to_missing? lib/stimulus_reflex/cable_ready_channels.rb /^ def respond_to_missing?(name, include_all)$/;" f class:StimulusReflex.CableReadyChannels
119
+ respond_to_missing? lib/stimulus_reflex/logger.rb /^ def respond_to_missing? method$/;" f class:StimulusReflex.Logger
120
+ search_file lib/stimulus_reflex/sanity_checker.rb /^ def search_file(path, regex:)$/;" f
121
+ selector lib/stimulus_reflex/logger.rb /^ def selector$/;" f class:StimulusReflex.Logger
89
122
  selector? lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def selector?$/;" f class:StimulusReflex.Broadcaster
90
123
  selector? lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^ def selector?$/;" f class:StimulusReflex.SelectorBroadcaster
91
- stream_name lib/stimulus_reflex/channel.rb /^ def stream_name$/;" f class:StimulusReflex
92
- subscribed lib/stimulus_reflex/channel.rb /^ def subscribed$/;" f class:StimulusReflex
124
+ session_id lib/stimulus_reflex/logger.rb /^ def session_id$/;" f class:StimulusReflex.Logger
125
+ session_id_full lib/stimulus_reflex/logger.rb /^ def session_id_full$/;" f class:StimulusReflex.Logger
126
+ signed lib/stimulus_reflex/element.rb /^ def signed$/;" f class:StimulusReflex
127
+ stream_name app/channels/stimulus_reflex/channel.rb /^ def stream_name$/;" f class:StimulusReflex
128
+ subscribed app/channels/stimulus_reflex/channel.rb /^ def subscribed$/;" f class:StimulusReflex
129
+ timestamp lib/stimulus_reflex/logger.rb /^ def timestamp$/;" f class:StimulusReflex.Logger
130
+ to_s lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def to_s$/;" f class:StimulusReflex.Broadcaster
131
+ to_s lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb /^ def to_s$/;" f class:StimulusReflex.NothingBroadcaster
132
+ to_s lib/stimulus_reflex/broadcasters/page_broadcaster.rb /^ def to_s$/;" f class:StimulusReflex.PageBroadcaster
133
+ to_s lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^ def to_s$/;" f class:StimulusReflex.SelectorBroadcaster
93
134
  to_sym lib/stimulus_reflex/broadcasters/broadcaster.rb /^ def to_sym$/;" f class:StimulusReflex.Broadcaster
94
135
  to_sym lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb /^ def to_sym$/;" f class:StimulusReflex.NothingBroadcaster
95
136
  to_sym lib/stimulus_reflex/broadcasters/page_broadcaster.rb /^ def to_sym$/;" f class:StimulusReflex.PageBroadcaster
96
137
  to_sym lib/stimulus_reflex/broadcasters/selector_broadcaster.rb /^ def to_sym$/;" f class:StimulusReflex.SelectorBroadcaster
97
- update test/tmp/app/reflexes/user_reflex.rb /^ def update$/;" f class:UserReflex
98
- url_params lib/stimulus_reflex/reflex.rb /^ def url_params$/;" f
138
+ unsigned lib/stimulus_reflex/element.rb /^ def unsigned$/;" f class:StimulusReflex
139
+ warn_and_exit lib/stimulus_reflex/sanity_checker.rb /^ def warn_and_exit(text)$/;" f
@@ -1,11 +1,6 @@
1
- require_relative "../test_helper"
2
-
3
- class StimulusReflex::BroadcasterTest < ActiveSupport::TestCase
4
- setup do
5
- @reflex = Minitest::Mock.new
6
- @reflex.expect :stream_name, "TestStream"
7
- end
1
+ require_relative "broadcaster_test_case"
8
2
 
3
+ class StimulusReflex::BroadcasterTest < StimulusReflex::BroadcasterTestCase
9
4
  test "raises a NotImplementedError if called directly" do
10
5
  broadcaster = StimulusReflex::Broadcaster.new(@reflex)
11
6
 
@@ -0,0 +1,13 @@
1
+ require_relative "../test_helper"
2
+
3
+ class StimulusReflex::BroadcasterTestCase < ActionCable::Channel::TestCase
4
+ tests StimulusReflex::Channel
5
+
6
+ setup do
7
+ stub_connection(session_id: SecureRandom.uuid)
8
+ def connection.env
9
+ @env ||= {}
10
+ end
11
+ @reflex = StimulusReflex::Reflex.new(subscribe, url: "https://test.stimulusreflex.com")
12
+ end
13
+ end
@@ -1,34 +1,33 @@
1
- require_relative "../test_helper"
2
-
3
- class StimulusReflex::NothingBroadcasterTest < ActiveSupport::TestCase
4
- setup do
5
- @reflex = Minitest::Mock.new
6
- @reflex.expect :stream_name, "TestStream"
7
- end
1
+ require_relative "broadcaster_test_case"
8
2
 
3
+ class StimulusReflex::NothingBroadcasterTest < StimulusReflex::BroadcasterTestCase
9
4
  test "broadcasts a server message when called" do
10
5
  broadcaster = StimulusReflex::NothingBroadcaster.new(@reflex)
11
6
 
12
- cable_ready_channels = Minitest::Mock.new
13
- cable_ready_channel = Minitest::Mock.new
14
- CableReady::Channels.stub :instance, cable_ready_channels do
15
- cable_ready_channel.expect(:dispatch_event, nil, [{name: "stimulus-reflex:server-message",
16
- detail: {
17
- reflexId: nil,
18
- stimulus_reflex: {
19
- some: :data,
20
- morph: :nothing,
21
- server_message: {
22
- subject: "nothing", body: nil
23
- }
24
- }
25
- }}])
26
- cable_ready_channels.expect(:[], cable_ready_channel, ["TestStream"])
27
- cable_ready_channels.expect(:broadcast, nil)
28
- broadcaster.broadcast(nil, {some: :data})
29
- end
7
+ expected = {
8
+ "cableReady" => true,
9
+ "operations" => {
10
+ "dispatchEvent" => [
11
+ {
12
+ "name" => "stimulus-reflex:server-message",
13
+ "detail" => {
14
+ "reflexId" => nil,
15
+ "stimulusReflex" => {
16
+ "some" => :data,
17
+ "morph" => :nothing,
18
+ "serverMessage" => {
19
+ "subject" => "nothing",
20
+ "body" => nil
21
+ }
22
+ }
23
+ }
24
+ }
25
+ ]
26
+ }
27
+ }
30
28
 
31
- assert_mock cable_ready_channels
32
- assert_mock cable_ready_channel
29
+ assert_broadcast_on @reflex.stream_name, expected do
30
+ broadcaster.broadcast nil, some: :data
31
+ end
33
32
  end
34
33
  end
@@ -1,69 +1,73 @@
1
- require_relative "../test_helper"
2
-
3
- class StimulusReflex::PageBroadcasterTest < ActiveSupport::TestCase
4
- setup do
5
- @reflex = Minitest::Mock.new
6
- @reflex.expect :params, {action: "show"}
7
- @reflex.expect :stream_name, "TestStream"
8
- @reflex.expect :permanent_attribute_name, "some-attribute"
9
- end
1
+ require_relative "broadcaster_test_case"
10
2
 
3
+ class StimulusReflex::PageBroadcasterTest < StimulusReflex::BroadcasterTestCase
11
4
  test "returns if the response html is empty" do
12
- controller = Minitest::Mock.new
13
- controller.expect(:process, nil, ["show"])
14
- @reflex.expect :controller, controller
15
- @reflex.expect :controller, controller
5
+ broadcaster = StimulusReflex::PageBroadcaster.new(@reflex)
6
+ broadcaster.broadcast(["#foo"], {some: :data})
7
+ # TODO: figure out how to refute_broadcast_on
8
+ end
16
9
 
17
- # stub the controller response with a struct responding to :body
18
- controller.expect(:response, Struct.new(:body).new(nil))
10
+ test "performs a page morph on body" do
11
+ class << @reflex.controller.response
12
+ def body
13
+ "<html><head></head><body>New Content</body></html>"
14
+ end
15
+ end
19
16
 
20
17
  broadcaster = StimulusReflex::PageBroadcaster.new(@reflex)
21
18
 
22
- cable_ready_channels = Minitest::Mock.new
23
- cable_ready_channels.expect(:broadcast, nil)
24
-
25
- broadcaster.broadcast(["#foo"], {some: :data})
19
+ expected = {
20
+ "cableReady" => true,
21
+ "operations" => {
22
+ "morph" => [
23
+ {
24
+ "selector" => "body",
25
+ "html" => "New Content",
26
+ "childrenOnly" => true,
27
+ "permanentAttributeName" => nil,
28
+ "stimulusReflex" => {
29
+ "some" => :data,
30
+ "morph" => :page
31
+ }
32
+ }
33
+ ]
34
+ }
35
+ }
26
36
 
27
- assert_raises { cable_ready_channels.verify }
37
+ assert_broadcast_on @reflex.stream_name, expected do
38
+ broadcaster.broadcast(["body"], {some: :data})
39
+ end
28
40
  end
29
41
 
30
42
  test "performs a page morph given an array of reflex root selectors" do
31
- controller = Minitest::Mock.new
32
- controller.expect(:process, nil, ["show"])
33
- @reflex.expect :controller, controller
34
- @reflex.expect :controller, controller
35
-
36
- # stub the controller response with a struct responding to :body
37
- controller.expect(:response, Struct.new(:body).new("<html></html>"))
43
+ class << @reflex.controller.response
44
+ def body
45
+ "<html><head></head><body><div id=\"foo\">New Content</div></body></html>"
46
+ end
47
+ end
38
48
 
39
49
  broadcaster = StimulusReflex::PageBroadcaster.new(@reflex)
40
50
 
41
- cable_ready_channels = Minitest::Mock.new
42
- cable_ready_channel = Minitest::Mock.new
43
- document = Minitest::Mock.new
44
- Nokogiri::HTML.stub :parse, document do
45
- document.expect(:css, "something that is present", ["#foo"])
46
- document.expect(:css, Struct.new(:inner_html).new("<span>bar</span>"), ["#foo"])
47
-
48
- CableReady::Channels.stub :instance, cable_ready_channels do
49
- cable_ready_channel.expect(:morph, nil, [{
50
- selector: "#foo",
51
- html: "<span>bar</span>",
52
- children_only: true,
53
- permanent_attribute_name: "some-attribute",
54
- stimulus_reflex: {
55
- some: :data,
56
- morph: :page
51
+ expected = {
52
+ "cableReady" => true,
53
+ "operations" => {
54
+ "morph" => [
55
+ {
56
+ "selector" => "#foo",
57
+ "html" => "New Content",
58
+ "childrenOnly" => true,
59
+ "permanentAttributeName" => nil,
60
+ "stimulusReflex" => {
61
+ "some" => :data,
62
+ "morph" => :page
63
+ }
57
64
  }
58
- }])
59
- cable_ready_channels.expect(:[], cable_ready_channel, ["TestStream"])
60
- cable_ready_channels.expect(:broadcast, nil)
65
+ ]
66
+ }
67
+ }
61
68
 
62
- broadcaster.broadcast(["#foo"], {some: :data})
63
- end
69
+ assert_broadcast_on @reflex.stream_name, expected do
70
+ broadcaster.broadcast(["#foo"], {some: :data})
64
71
  end
65
-
66
- assert_mock cable_ready_channels
67
- assert_mock cable_ready_channel
68
72
  end
69
73
  end
@@ -1,83 +1,55 @@
1
- require_relative "../test_helper"
2
-
3
- class StimulusReflex::SelectorBroadcasterTest < ActiveSupport::TestCase
4
- setup do
5
- @reflex = Minitest::Mock.new
6
- @reflex.expect :stream_name, "TestStream"
7
- @reflex.expect :permanent_attribute_name, "some-attribute"
8
- end
9
-
10
- test "morphs the contents of an element if the selector(s) are present in both original and morphed html fragments" do
11
- broadcaster = StimulusReflex::SelectorBroadcaster.new(@reflex)
12
-
13
- cable_ready_channels = Minitest::Mock.new
14
- cable_ready_channel = Minitest::Mock.new
15
- fragment = Minitest::Mock.new
16
- match = Minitest::Mock.new
17
- Nokogiri::HTML.stub :fragment, fragment do
18
- fragment.expect(:at_css, match, ["#foo"])
19
- match.expect(:present?, true)
20
-
21
- # we need to mock `!`, because `blank?` returns
22
- # respond_to?(:empty?) ? !!empty? : !self
23
- match.expect(:!, false)
24
- match.expect(:inner_html, "<span>bar</span>")
25
- CableReady::Channels.stub :instance, cable_ready_channels do
26
- broadcaster.append_morph("#foo", "<div id=\"foo\"><span>bar</span></div>")
27
- cable_ready_channel.expect(:morph, nil, [{
28
- selector: "#foo",
29
- html: "<span>bar</span>",
30
- children_only: true,
31
- permanent_attribute_name: "some-attribute",
32
- stimulus_reflex: {
33
- some: :data,
34
- morph: :selector
35
- }
36
- }])
37
- cable_ready_channels.expect(:[], cable_ready_channel, ["TestStream"])
38
- cable_ready_channels.expect(:broadcast, nil)
39
-
40
- broadcaster.broadcast(nil, {some: :data})
41
- end
42
- end
43
-
44
- assert_mock cable_ready_channels
45
- assert_mock cable_ready_channel
46
- end
47
-
48
- test "replaces the contents of an element and ignores permanent-attributes if the selector(s) aren't present in the replacing html fragment" do
49
- broadcaster = StimulusReflex::SelectorBroadcaster.new(@reflex)
50
-
51
- cable_ready_channels = Minitest::Mock.new
52
- cable_ready_channel = Minitest::Mock.new
53
- fragment = Minitest::Mock.new
54
- match = Minitest::Mock.new
55
- Nokogiri::HTML.stub :fragment, fragment do
56
- fragment.expect(:at_css, match, ["#foo"])
57
- fragment.expect(:to_html, "<div id=\"baz\"><span>bar</span></div>")
58
- match.expect(:present?, false)
59
-
60
- # we need to mock `!`, because `blank?` returns
61
- # respond_to?(:empty?) ? !!empty? : !self
62
- match.expect(:!, true)
63
- CableReady::Channels.stub :instance, cable_ready_channels do
64
- broadcaster.append_morph("#foo", "<div id=\"baz\"><span>bar</span></div>")
65
- cable_ready_channel.expect(:inner_html, nil, [{
66
- selector: "#foo",
67
- html: "<div id=\"baz\"><span>bar</span></div>",
68
- stimulus_reflex: {
69
- some: :data,
70
- morph: :selector
71
- }
72
- }])
73
- cable_ready_channels.expect(:[], cable_ready_channel, ["TestStream"])
74
- cable_ready_channels.expect(:broadcast, nil)
75
-
76
- broadcaster.broadcast(nil, {some: :data})
77
- end
78
- end
79
-
80
- assert_mock cable_ready_channels
81
- assert_mock cable_ready_channel
82
- end
83
- end
1
+ # require_relative "broadcaster_test_case"
2
+
3
+ # class StimulusReflex::SelectorBroadcasterTest < StimulusReflex::BroadcasterTestCase
4
+ # test "morphs the contents of an element if the selector(s) are present in both original and morphed html fragments" do
5
+ # broadcaster = StimulusReflex::SelectorBroadcaster.new(@reflex)
6
+ # broadcaster.append_morph("#foo", "<div id=\"foo\"><span>bar</span></div>")
7
+
8
+ # expected = {
9
+ # "cableReady" => true,
10
+ # "operations" => {
11
+ # "morph" => [
12
+ # {
13
+ # "selector" => "#foo",
14
+ # "html" => "<span>bar</span>",
15
+ # "childrenOnly" => true,
16
+ # "permanentAttributeName" => nil,
17
+ # "stimulusReflex" => {
18
+ # "some" => :data,
19
+ # "morph" => :selector
20
+ # }
21
+ # }
22
+ # ]
23
+ # }
24
+ # }
25
+
26
+ # assert_broadcast_on @reflex.stream_name, expected do
27
+ # broadcaster.broadcast nil, some: :data
28
+ # end
29
+ # end
30
+
31
+ # test "replaces the contents of an element and ignores permanent-attributes if the selector(s) aren't present in the replacing html fragment" do
32
+ # broadcaster = StimulusReflex::SelectorBroadcaster.new(@reflex)
33
+ # broadcaster.append_morph("#foo", "<div id=\"baz\"><span>bar</span></div>")
34
+
35
+ # expected = {
36
+ # "cableReady" => true,
37
+ # "operations" => {
38
+ # "innerHtml" => [
39
+ # {
40
+ # "selector" => "#foo",
41
+ # "html" => "<div id=\"baz\"><span>bar</span></div>",
42
+ # "stimulusReflex" => {
43
+ # "some" => :data,
44
+ # "morph" => :selector
45
+ # }
46
+ # }
47
+ # ]
48
+ # }
49
+ # }
50
+
51
+ # assert_broadcast_on @reflex.stream_name, expected do
52
+ # broadcaster.broadcast nil, some: :data
53
+ # end
54
+ # end
55
+ # end
@@ -1,6 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "minitest/mock"
4
-
5
3
  ENV["RAILS_ENV"] ||= "test"
4
+
5
+ require "minitest/mock"
6
+ require "rails"
7
+ require "action_controller"
8
+ require "pry"
6
9
  require_relative "../lib/stimulus_reflex"
10
+
11
+ class TestApp < Rails::Application
12
+ routes.draw { root to: "test#index" }
13
+ end
14
+
15
+ class ApplicationController < ActionController::Base; end
16
+
17
+ class TestController < ApplicationController
18
+ include Rails.application.routes.url_helpers
19
+
20
+ def index
21
+ head :ok
22
+ end
23
+ end
24
+
25
+ class SessionMock
26
+ def load!
27
+ nil
28
+ end
29
+ end
30
+
31
+ class ActionDispatch::Request
32
+ def session
33
+ @session ||= SessionMock.new
34
+ end
35
+ end
36
+
37
+ StimulusReflex.configuration.parent_channel = "ActionCable::Channel::Base"
38
+ ActionCable::Server::Base.config.cable = {adapter: "test"}
39
+ ActionCable::Server::Base.config.logger = Logger.new(nil)
40
+
41
+ require_relative "../app/channels/stimulus_reflex/channel"
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class ApplicationReflex < StimulusReflex::Reflex
4
- # Put application wide Reflex behavior in this file.
4
+ # Put application-wide Reflex behavior and callbacks in this file.
5
5
  #
6
6
  # Example:
7
7
  #
8
8
  # # If your ActionCable connection is: `identified_by :current_user`
9
9
  # delegate :current_user, to: :connection
10
10
  #
11
- # Learn more at: https://docs.stimulusreflex.com
11
+ # Learn more at: https://docs.stimulusreflex.com/reflexes#reflex-classes
12
12
  end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DemoReflex < ApplicationReflex
4
+ # Add Reflex methods in this file.
5
+ #
6
+ # All Reflex instances include CableReady::Broadcaster and expose the following properties:
7
+ #
8
+ # - connection - the ActionCable connection
9
+ # - channel - the ActionCable channel
10
+ # - request - an ActionDispatch::Request proxy for the socket connection
11
+ # - session - the ActionDispatch::Session store for the current visitor
12
+ # - flash - the ActionDispatch::Flash::FlashHash for the current request
13
+ # - url - the URL of the page that triggered the reflex
14
+ # - params - parameters from the element's closest form (if any)
15
+ # - element - a Hash like object that represents the HTML element that triggered the reflex
16
+ # - signed - use a signed Global ID to map dataset attribute to a model eg. element.signed[:foo]
17
+ # - unsigned - use an unsigned Global ID to map dataset attribute to a model eg. element.unsigned[:foo]
18
+ # - cable_ready - a special cable_ready that can broadcast to the current visitor (no brackets needed)
19
+ #
20
+ # Example:
21
+ #
22
+ # before_reflex do
23
+ # # throw :abort # this will prevent the Reflex from continuing
24
+ # # learn more about callbacks at https://docs.stimulusreflex.com/lifecycle
25
+ # end
26
+ #
27
+ # def example(argument=true)
28
+ # # Your logic here...
29
+ # # Any declared instance variables will be made available to the Rails controller and view.
30
+ # end
31
+ #
32
+ # Learn more at: https://docs.stimulusreflex.com/reflexes#reflex-classes
33
+
34
+ end
data/yarn.lock CHANGED
@@ -1255,10 +1255,10 @@ buffer-from@^1.0.0:
1255
1255
  resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.1.tgz#32713bc028f75c02fdb710d7c7bcec1f2c6070ef"
1256
1256
  integrity sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==
1257
1257
 
1258
- "cable_ready@>= 4.3.0":
1259
- version "4.4.0"
1260
- resolved "https://registry.yarnpkg.com/cable_ready/-/cable_ready-4.4.0.tgz#6291d01fcfe306592724be355facfac22c9834d8"
1261
- integrity sha512-0KcCu3cuapDx6mo5UnJz8ZSTIMG9qNc+E3AgfF1qozPYCCbtjz+fQZ1rW0C/pUTXvRMNOfvzUjQ0aHU5IaGgVQ==
1258
+ "cable_ready@>= 4.4":
1259
+ version "4.4.1"
1260
+ resolved "https://registry.yarnpkg.com/cable_ready/-/cable_ready-4.4.1.tgz#b97564fb9347b2ad9ad21519956f1a5e5fa3690d"
1261
+ integrity sha512-dB8W2JVQMuSW3YYyl321mZOrkdCt+10KVAeL+51/o6dC5H/QTWSZPj//POYEFynVL8hShYU9joC5Qrw0B5lxLw==
1262
1262
  dependencies:
1263
1263
  morphdom "^2.6.1"
1264
1264
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stimulus_reflex
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0.pre5
4
+ version: 3.4.0.pre6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-25 00:00:00.000000000 Z
11
+ date: 2020-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 4.3.0
75
+ version: '4.4'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 4.3.0
82
+ version: '4.4'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -183,6 +183,7 @@ files:
183
183
  - lib/stimulus_reflex/broadcasters/nothing_broadcaster.rb
184
184
  - lib/stimulus_reflex/broadcasters/page_broadcaster.rb
185
185
  - lib/stimulus_reflex/broadcasters/selector_broadcaster.rb
186
+ - lib/stimulus_reflex/cable_ready_channels.rb
186
187
  - lib/stimulus_reflex/configuration.rb
187
188
  - lib/stimulus_reflex/element.rb
188
189
  - lib/stimulus_reflex/logger.rb
@@ -195,13 +196,14 @@ files:
195
196
  - stimulus_reflex.gemspec
196
197
  - tags
197
198
  - test/broadcasters/broadcaster_test.rb
199
+ - test/broadcasters/broadcaster_test_case.rb
198
200
  - test/broadcasters/nothing_broadcaster_test.rb
199
201
  - test/broadcasters/page_broadcaster_test.rb
200
202
  - test/broadcasters/selector_broadcaster_test.rb
201
203
  - test/generators/stimulus_reflex_generator_test.rb
202
204
  - test/test_helper.rb
203
205
  - test/tmp/app/reflexes/application_reflex.rb
204
- - test/tmp/app/reflexes/posts_reflex.rb
206
+ - test/tmp/app/reflexes/demo_reflex.rb
205
207
  - yarn.lock
206
208
  homepage: https://github.com/hopsoft/stimulus_reflex
207
209
  licenses:
@@ -238,9 +240,10 @@ summary: Build reactive applications with the Rails tooling you already know and
238
240
  test_files:
239
241
  - test/test_helper.rb
240
242
  - test/generators/stimulus_reflex_generator_test.rb
243
+ - test/tmp/app/reflexes/demo_reflex.rb
241
244
  - test/tmp/app/reflexes/application_reflex.rb
242
- - test/tmp/app/reflexes/posts_reflex.rb
243
245
  - test/broadcasters/broadcaster_test.rb
244
246
  - test/broadcasters/selector_broadcaster_test.rb
245
247
  - test/broadcasters/page_broadcaster_test.rb
248
+ - test/broadcasters/broadcaster_test_case.rb
246
249
  - test/broadcasters/nothing_broadcaster_test.rb
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class PostsReflex < ApplicationReflex
4
- # Add Reflex methods in this file.
5
- #
6
- # All Reflex instances expose the following properties:
7
- #
8
- # - connection - the ActionCable connection
9
- # - channel - the ActionCable channel
10
- # - request - an ActionDispatch::Request proxy for the socket connection
11
- # - session - the ActionDispatch::Session store for the current visitor
12
- # - url - the URL of the page that triggered the reflex
13
- # - element - a Hash like object that represents the HTML element that triggered the reflex
14
- # - params - parameters from the element's closest form (if any)
15
- #
16
- # Example:
17
- #
18
- # def example(argument=true)
19
- # # Your logic here...
20
- # # Any declared instance variables will be made available to the Rails controller and view.
21
- # end
22
- #
23
- # Learn more at: https://docs.stimulusreflex.com
24
- end