stimulus_reflex 0.3.3 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad73548d83220dad8507731aa3088ca52a1e981697980e3da8f261e82be59462
4
- data.tar.gz: 7ed23fca2f5ff587fc181361ffb002cc5fd9de7c70a1280928ed536ae1e4ef73
3
+ metadata.gz: 01c487c8dcbf81861bfb4a53e745ba41c5f5e9f33903b287b1a4dad85677fbcb
4
+ data.tar.gz: 1192b6eb87371604649f4f63589664fbd954fbef93b1bd9114e4b717d6b0b57c
5
5
  SHA512:
6
- metadata.gz: 0bbf90deed78b5ed255878eb80d47bd601f4e3b3eeb4cbdfaf0f5c6314c1b84a8da15a5e96639e1d6a148f14a48c02a95d19fd7c99fd02bee1767ad23e76dd55
7
- data.tar.gz: 6644e9ff393702cec504971d8d02d6c8dc7de24926a4365b496acd334bb23da75f8bb446b7a9b92672af483c8f5204b0fc44c3b7b9223ea26350775ec543fa08
6
+ metadata.gz: 3bd7af4f182254375a353839f561afa54927876065d3469bde34d3138c97ab14ebb50dc0587aaf1bc8db236df5e2c98ef71c6107e7def5a6582e13c84af0d6b8
7
+ data.tar.gz: 1cfd21e9a2268c2a799ff1a77dc34dd46464b13feef9857fe76fd3bab64c05b4e5b26c993b6aed6959329b44e167d01d334ab368d8688194c89a4c2d522ca633
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stimulus_reflex (0.3.3)
4
+ stimulus_reflex (1.0.0)
5
5
  actioncable (>= 5.2.1)
6
6
  actionpack (>= 5.2.1)
7
- cable_ready (>= 3.0.1)
7
+ cable_ready (>= 4.0.0)
8
8
  nokogiri
9
9
  rack
10
10
 
@@ -35,7 +35,7 @@ GEM
35
35
  tzinfo (~> 1.1)
36
36
  ast (2.4.0)
37
37
  builder (3.2.3)
38
- cable_ready (3.0.1)
38
+ cable_ready (4.0.0)
39
39
  activesupport (>= 5.0.0)
40
40
  concurrent-ruby (1.1.5)
41
41
  crass (1.0.4)
@@ -48,7 +48,7 @@ GEM
48
48
  nokogiri (>= 1.5.9)
49
49
  mini_portile2 (2.4.0)
50
50
  minitest (5.11.3)
51
- nio4r (2.3.1)
51
+ nio4r (2.4.0)
52
52
  nokogiri (1.10.3)
53
53
  mini_portile2 (~> 2.4.0)
54
54
  parallel (1.17.0)
@@ -61,7 +61,7 @@ GEM
61
61
  rails-dom-testing (2.0.3)
62
62
  activesupport (>= 4.2.0)
63
63
  nokogiri (>= 1.6)
64
- rails-html-sanitizer (1.0.4)
64
+ rails-html-sanitizer (1.2.0)
65
65
  loofah (~> 2.2, >= 2.2.2)
66
66
  rainbow (3.0.0)
67
67
  rake (12.3.2)
@@ -82,9 +82,9 @@ GEM
82
82
  tzinfo (1.2.5)
83
83
  thread_safe (~> 0.1)
84
84
  unicode-display_width (1.5.0)
85
- websocket-driver (0.7.0)
85
+ websocket-driver (0.7.1)
86
86
  websocket-extensions (>= 0.1.0)
87
- websocket-extensions (0.1.3)
87
+ websocket-extensions (0.1.4)
88
88
 
89
89
  PLATFORMS
90
90
  ruby
data/README.md CHANGED
@@ -1,22 +1,31 @@
1
- [![Lines of Code](http://img.shields.io/badge/lines_of_code-161-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
1
+ [![Lines of Code](http://img.shields.io/badge/lines_of_code-120-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
2
2
  [![Maintainability](https://api.codeclimate.com/v1/badges/2b24fdbd1ae37a24bedb/maintainability)](https://codeclimate.com/github/hopsoft/stimulus_reflex/maintainability)
3
3
  [![Ruby Dependency Graph](https://img.shields.io/badge/deps-ruby-informational.svg?style=flat)](https://github.com/hopsoft/stimulus_reflex/blob/master/gem_graph.svg)
4
- [![JavaScript Dependency Graph](https://img.shields.io/badge/deps-javascript-informational.svg?style=flat)](https://github.com/hopsoft/stimulus_reflex/blob/master/javascript_graph.txt)
5
4
 
6
5
  # StimulusReflex
7
6
 
8
7
  #### Build rich interactive UIs with standard Rails... no need for a complex frontend framework
9
8
 
9
+ This library provides functionality similar to [Phoenix LiveView](https://youtu.be/Z2DU0qLfPIY?t=670) for Rails applications.
10
+
10
11
  Add the benefits of single page apps (SPA) to server rendered Rails/Stimulus projects with a minimal investment of time, resources, and complexity.
11
12
  _The goal is to provide 80% of the benefits of SPAs with 20% of the typical effort._
12
13
 
13
- 1. Use [ActionCable](https://edgeguides.rubyonrails.org/action_cable_overview.html) to invoke a method on the server
14
- 1. Watch the page automatically render updates via fast [DOM diffing](https://github.com/patrick-steele-idem/morphdom)
15
- 1. That's it
14
+ 1. Use [ActionCable](https://edgeguides.rubyonrails.org/action_cable_overview.html) to invoke a method on the server.
15
+ 1. Watch the page automatically render updates via fast [DOM diffing](https://github.com/patrick-steele-idem/morphdom).
16
+ 1. That's it...
16
17
 
17
- > This library provides functionality similar to [Phoenix LiveView](https://youtu.be/Z2DU0qLfPIY?t=670) for Rails applications.
18
+ - Yes, it really is that simple. Just write your HTML page.
19
+ - If you hit refresh, that works, too.
20
+ - There's no hidden gotcha.
18
21
 
19
- ## Usage
22
+ ## Setup
23
+
24
+ ### JavaScript
25
+
26
+ ```
27
+ yarn add stimulus_reflex
28
+ ```
20
29
 
21
30
  ### Gemfile
22
31
 
@@ -24,55 +33,34 @@ _The goal is to provide 80% of the benefits of SPAs with 20% of the typical effo
24
33
  gem "stimulus_reflex"
25
34
  ```
26
35
 
27
- ### app/views/layouts/application.html.erb
36
+ ## Usage
37
+
38
+ ### app/views/pages/example.html.erb
28
39
 
29
40
  ```erb
30
- <html>
31
- <head></head>
32
- <body data-cable>
33
- <%= yield %>
41
+ <head></head>
42
+ <body>
43
+ <a href="#" data-controller="example" data-action="click->example#increment">
44
+ Increment <%= @count.to_i %>
45
+ </a>
34
46
  </body>
35
47
  </html>
36
48
  ```
37
49
 
38
- Pages must opt in to establish the ActionCable connection.
39
- This eliminates unauthorized connection attempts.
40
-
41
- SEE: https://gist.github.com/hopsoft/02dfdf4456b3ac52f4eaf242289bdd36
42
-
43
- ### app/assets/javascripts/cable.js
44
-
45
- ```javascript
46
- //= require action_cable
47
- //= require cable_ready
48
- //= require stimulus_reflex
49
- //= require_self
50
- //= require_tree ./channels
51
-
52
- (function() {
53
- document.addEventListener('DOMContentLoaded', function () {
54
- if (document.querySelector('body[data-cable]')) {
55
- // be defensive since stimulus_reflex also initializes this.App and App.cable
56
- this.App || (this.App = {});
57
- App.cable || (App.cable = ActionCable.createConsumer());
58
- }
59
- });
60
- }.call(this));
61
- ```
62
-
63
50
  ### app/javascript/controllers/example.js
64
51
 
65
52
  ```javascript
66
53
  import { Controller } from "stimulus"
54
+ import StimulusReflex from "stimulus_reflex"
67
55
 
68
56
  export default class extends Controller {
69
57
  connect() {
70
58
  StimulusReflex.register(this);
71
59
  }
72
60
 
73
- doStuff() {
61
+ increment() {
74
62
  // trigger a server side reflex and a re-render
75
- this.stimulate('ExampleReflex#do_stuff', arg1, arg2, ...);
63
+ this.stimulate('ExampleReflex#increment', 1);
76
64
  }
77
65
  }
78
66
  ```
@@ -81,72 +69,23 @@ export default class extends Controller {
81
69
 
82
70
  ```ruby
83
71
  class ExampleReflex < StimulusReflex::Reflex
84
- def do_stuff(arg1, arg2, ...)
85
- # stuff...
72
+ def increment(step = 1)
73
+ @count = @count.to_i += step
86
74
  end
87
75
  end
88
76
  ```
89
77
 
90
78
  The following happens after the `StimulusReflex::Reflex` method call finishes.
91
79
 
92
- 1. The page that triggered the reflex is re-rerendered
93
- 1. The re-rendered HTML is sent to the client over the ActionCable socket
94
- 1. JavaScript on the client updates the page with any changes via fast DOM diffing
95
-
96
- ### ActionCable Defaults Expected
97
-
98
- StimulusReflex will use or create `window.App` and `App.cable`
99
- and is typically loaded before the default ActionCable initialization code.
100
-
101
- ## Advanced Usage
80
+ 1. The page that triggered the reflex is re-rerendered. _Note that instance variables created in the reflex are available to both the controller and view templates._
81
+ 2. The re-rendered HTML is sent to the client over the ActionCable socket.
82
+ 3. The page is updated via fast DOM diffing courtesy of morphdom. _While future versions of StimulusReflex might support more granular updates, today the entire body is re-rendered and sent over the socket._
102
83
 
103
- ### Page Rerender
84
+ ### ActionCable
104
85
 
105
- The page is always rerendered after triggering a `StimulusReflex`.
106
- The client side JavaScript debounces this render via `setTimeout` to prevent a jarring user experience.
107
- The default delay of `200ms` can be overriddend with the following JavaScript.
108
-
109
- ```javascript
110
- StimulusReflex.renderDelay = 100;
111
- ```
112
-
113
- ## Instrumentation
114
-
115
- SEE: https://guides.rubyonrails.org/active_support_instrumentation.html
116
-
117
- ```ruby
118
- # wraps the stimulus reflex method invocation
119
- ActiveSupport::Notifications.subscribe "delegate_call.stimulus_reflex" do |*args|
120
- event = ActiveSupport::Notifications::Event.new(*args)
121
- Rails.logger.debug "#{event.name} #{event.duration} #{event.payload.inspect}"
122
- end
123
-
124
- # instruments the page rerender
125
- ActiveSupport::Notifications.subscribe "render_page.stimulus_reflex" do |*args|
126
- event = ActiveSupport::Notifications::Event.new(*args)
127
- Rails.logger.debug "#{event.name} #{event.duration} #{event.payload.inspect}"
128
- end
129
-
130
- # wraps the web socket broadcast
131
- ActiveSupport::Notifications.subscribe "broadcast.stimulus_reflex" do |*args|
132
- event = ActiveSupport::Notifications::Event.new(*args)
133
- Rails.logger.debug "#{event.name} #{event.duration} #{event.payload.inspect}"
134
- end
135
-
136
- # wraps the entire receive operation which includes everything above
137
- ActiveSupport::Notifications.subscribe "receive.stimulus_reflex" do |*args|
138
- event = ActiveSupport::Notifications::Event.new(*args)
139
- Rails.logger.debug "#{event.name} #{event.duration} #{event.payload.inspect}"
140
- end
141
- ```
86
+ StimulusReflex will use the Rails' ActionCable defaults `window.App` and `App.cable` if they exist.
87
+ If these defaults do not exist, StimulusReflex will attempt to establish a new socket connection.
142
88
 
143
89
  ## JavaScript Development
144
90
 
145
- The JavaScript source is located in `app/assets/javascripts/stimulus_reflex/src`
146
- & transpiles to `app/assets/javascripts/stimulus_reflex.js` via Webpack.
147
-
148
- ```sh
149
- # build the javascript
150
- ./bin/yarn
151
- ./bin/webpack
152
- ```
91
+ The JavaScript library is hosted at: https://github.com/hopsoft/stimulus_reflex_client
data/bin/deps CHANGED
@@ -1,5 +1,3 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
3
  bundle viz --version --format svg --without development test
4
- cd ./app/assets/javascripts/stimulus_reflex/src
5
- yarn list -s --prod > ../../../../../javascript_graph.txt
data/bin/standardize CHANGED
@@ -1,4 +1,3 @@
1
1
  #!/bin/bash
2
2
 
3
3
  bundle exec standardrb --fix
4
- prettier --no-config --single-quote --trailing-comma es5 --write app/assets/javascripts/stimulus_reflex/src/*.js
@@ -47,7 +47,7 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
47
47
  def delegate_call_to_reflex(reflex, method_name, arguments = [])
48
48
  instrument_payload = {reflex: reflex.class.name, method_name: method_name, arguments: arguments.inspect}
49
49
  ActiveSupport::Notifications.instrument "delegate_call.stimulus_reflex", instrument_payload do
50
- if reflex.method(method_name).arity > 0
50
+ if reflex.method(method_name).arity != 0
51
51
  reflex.send method_name, *arguments
52
52
  else
53
53
  reflex.send method_name
@@ -1,3 +1,3 @@
1
1
  module StimulusReflex
2
- VERSION = "0.3.3"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stimulus_reflex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-05-13 00:00:00.000000000 Z
12
+ date: 2019-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -73,14 +73,14 @@ dependencies:
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: 3.0.1
76
+ version: 4.0.0
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: 3.0.1
83
+ version: 4.0.0
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: bundler
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -136,14 +136,10 @@ files:
136
136
  - LICENSE.txt
137
137
  - README.md
138
138
  - Rakefile
139
- - app/assets/javascripts/stimulus_reflex.js
140
- - bin/cloc
141
139
  - bin/console
142
140
  - bin/deps
143
141
  - bin/setup
144
142
  - bin/standardize
145
- - bin/webpack
146
- - bin/yarn
147
143
  - lib/stimulus_reflex.rb
148
144
  - lib/stimulus_reflex/channel.rb
149
145
  - lib/stimulus_reflex/reflex.rb
@@ -1 +0,0 @@
1
- window.StimulusReflex=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";var r;n.r(t),n.d(t,"register",function(){return u});document.addEventListener("DOMContentLoaded",function(){document.querySelector("body[data-cable]")&&(window.App||(window.App={}),App.cable||(App.cable=ActionCable.createConsumer()),App.stimulusReflex||(App.stimulusReflex=App.cable.subscriptions.create("StimulusReflex::Channel",{received:function(e){e.cableReady&&(clearTimeout(r),r=setTimeout(function(){CableReady.perform(e.operations)},StimulusReflex.renderDelay||100))}})))});var o={stimulate:function(){if(!App.stimulusReflex)throw"ActionCable connection not established! Don't forget to opt-in with: body[data-cable]";clearTimeout(r);var e=Array.prototype.slice.call(arguments),t=e.shift();App.stimulusReflex.send({url:location.href,target:t,args:e})}},u=function(e){return Object.assign(e,o),e}}]);
data/bin/cloc DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- cloc lib app/assets/javascripts/stimulus_reflex/src/index.js
data/bin/webpack DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- cd ./app/assets/javascripts/stimulus_reflex/src
4
- ./node_modules/webpack/bin/webpack.js "$@"
data/bin/yarn DELETED
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env bash
2
-
3
- cd ./app/assets/javascripts/stimulus_reflex/src
4
- yarn "$@"