stimulus_reflex 1.0.0 → 1.0.1
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.
Potentially problematic release.
This version of stimulus_reflex might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +17 -16
- data/README.md +46 -17
- data/lib/stimulus_reflex/channel.rb +6 -4
- data/lib/stimulus_reflex/version.rb +1 -1
- metadata +8 -9
- data/bin/deps +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 938d4a641bd8ab544990da39e9f5ac03d9c624d6cd88d2d0a0855654d00d2009
|
4
|
+
data.tar.gz: 398a90e77696a6477d49c8e338493a59db1a52cb678a3a0bd6bb9f6f1ca24266
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e8f45b49f0635ad52d04550885e6485f324fc197b92a1664d5fae70fed0876788d79c74cd3f9b9189aa32e1b98c3ce720e40e387938b502b596d0edcbafdd97
|
7
|
+
data.tar.gz: ecc35de7b132a1b7e46b084b252b70fb73e24a5a0be783f4997b07fa9ebc4d483aeb162a0f426aac3d181718bf8f8d5b943436da096376f7c632f9ab8f82b522
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stimulus_reflex (1.0.
|
5
|
-
actioncable (>= 5.2.
|
6
|
-
actionpack (>= 5.2.
|
7
|
-
cable_ready (>= 4.0.
|
4
|
+
stimulus_reflex (1.0.1)
|
5
|
+
actioncable (>= 5.2.3)
|
6
|
+
actionpack (>= 5.2.3)
|
7
|
+
cable_ready (>= 4.0.1)
|
8
8
|
nokogiri
|
9
9
|
rack
|
10
10
|
|
@@ -35,14 +35,14 @@ GEM
|
|
35
35
|
tzinfo (~> 1.1)
|
36
36
|
ast (2.4.0)
|
37
37
|
builder (3.2.3)
|
38
|
-
cable_ready (4.0.
|
38
|
+
cable_ready (4.0.1)
|
39
39
|
activesupport (>= 5.0.0)
|
40
40
|
concurrent-ruby (1.1.5)
|
41
41
|
crass (1.0.4)
|
42
42
|
erubi (1.8.0)
|
43
43
|
i18n (1.6.0)
|
44
44
|
concurrent-ruby (~> 1.0)
|
45
|
-
jaro_winkler (1.5.
|
45
|
+
jaro_winkler (1.5.3)
|
46
46
|
loofah (2.2.3)
|
47
47
|
crass (~> 1.0.2)
|
48
48
|
nokogiri (>= 1.5.9)
|
@@ -54,7 +54,6 @@ GEM
|
|
54
54
|
parallel (1.17.0)
|
55
55
|
parser (2.6.3.0)
|
56
56
|
ast (~> 2.4.0)
|
57
|
-
psych (3.1.0)
|
58
57
|
rack (2.0.7)
|
59
58
|
rack-test (1.1.0)
|
60
59
|
rack (>= 1.0, < 3)
|
@@ -64,24 +63,26 @@ GEM
|
|
64
63
|
rails-html-sanitizer (1.2.0)
|
65
64
|
loofah (~> 2.2, >= 2.2.2)
|
66
65
|
rainbow (3.0.0)
|
67
|
-
rake (12.3.
|
68
|
-
rubocop (0.
|
66
|
+
rake (12.3.3)
|
67
|
+
rubocop (0.72.0)
|
69
68
|
jaro_winkler (~> 1.5.1)
|
70
69
|
parallel (~> 1.10)
|
71
|
-
parser (>= 2.
|
72
|
-
psych (>= 3.1.0)
|
70
|
+
parser (>= 2.6)
|
73
71
|
rainbow (>= 2.2.2, < 4.0)
|
74
72
|
ruby-progressbar (~> 1.7)
|
75
|
-
unicode-display_width (>= 1.4.0, < 1.
|
76
|
-
|
77
|
-
|
78
|
-
|
73
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
74
|
+
rubocop-performance (1.4.1)
|
75
|
+
rubocop (>= 0.71.0)
|
76
|
+
ruby-progressbar (1.10.1)
|
77
|
+
standard (0.1.2)
|
78
|
+
rubocop (~> 0.72.0)
|
79
|
+
rubocop-performance (~> 1.4.0)
|
79
80
|
standardrb (1.0.0)
|
80
81
|
standard
|
81
82
|
thread_safe (0.3.6)
|
82
83
|
tzinfo (1.2.5)
|
83
84
|
thread_safe (~> 0.1)
|
84
|
-
unicode-display_width (1.
|
85
|
+
unicode-display_width (1.6.0)
|
85
86
|
websocket-driver (0.7.1)
|
86
87
|
websocket-extensions (>= 0.1.0)
|
87
88
|
websocket-extensions (0.1.4)
|
data/README.md
CHANGED
@@ -1,23 +1,28 @@
|
|
1
|
-
[](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
|
2
2
|
[](https://codeclimate.com/github/hopsoft/stimulus_reflex/maintainability)
|
3
|
-
[](https://github.com/hopsoft/stimulus_reflex/blob/master/gem_graph.svg)
|
4
3
|
|
5
4
|
# StimulusReflex
|
6
5
|
|
7
|
-
|
6
|
+
### Reactive user interfaces with Rails and Stimulus
|
8
7
|
|
9
|
-
|
8
|
+
#### No need for a complex frontend framework
|
10
9
|
|
11
|
-
|
12
|
-
|
10
|
+
This project aims to support the building of [Single Page Applications (SPAs)](https://en.wikipedia.org/wiki/Single-page_application)
|
11
|
+
with standard Rails tooling. Think server rendered HTML, Stimulus, Turbolinks, etc...
|
13
12
|
|
14
|
-
|
15
|
-
|
13
|
+
Inspired by [Phoenix LiveView](https://youtu.be/Z2DU0qLfPIY?t=670). 🙌
|
14
|
+
|
15
|
+
## How it Works
|
16
|
+
|
17
|
+
1. Use [ActionCable](https://edgeguides.rubyonrails.org/action_cable_overview.html) to invoke a method on the server
|
18
|
+
1. Watch the page automatically render updates via fast [DOM diffing](https://github.com/patrick-steele-idem/morphdom)
|
16
19
|
1. That's it...
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
+
__Yes, it really is that simple.__
|
22
|
+
Just create a server rendered HTML page and send RPC calls to the server via web socket.
|
23
|
+
There are no hidden gotchas.
|
24
|
+
|
25
|
+

|
21
26
|
|
22
27
|
## Setup
|
23
28
|
|
@@ -33,7 +38,7 @@ yarn add stimulus_reflex
|
|
33
38
|
gem "stimulus_reflex"
|
34
39
|
```
|
35
40
|
|
36
|
-
## Usage
|
41
|
+
## Basic Usage
|
37
42
|
|
38
43
|
### app/views/pages/example.html.erb
|
39
44
|
|
@@ -77,15 +82,39 @@ end
|
|
77
82
|
|
78
83
|
The following happens after the `StimulusReflex::Reflex` method call finishes.
|
79
84
|
|
80
|
-
1. The page that triggered the reflex is re-rerendered.
|
85
|
+
1. The page that triggered the reflex is re-rerendered. _Instance variables created in the reflex are available to both the controller and view templates._
|
81
86
|
2. The re-rendered HTML is sent to the client over the ActionCable socket.
|
82
87
|
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._
|
83
88
|
|
89
|
+
## Advanced Usage
|
90
|
+
|
84
91
|
### ActionCable
|
85
92
|
|
86
|
-
StimulusReflex will use the
|
87
|
-
If these defaults do not exist, StimulusReflex will
|
93
|
+
StimulusReflex will use the ActionCable defaults of `window.App` and `App.cable` if they exist.
|
94
|
+
If these defaults do not exist, StimulusReflex will establish a new socket connection.
|
95
|
+
|
96
|
+
### ActionCable Rooms
|
97
|
+
|
98
|
+
You may find the need to restrict notifications to a specific room.
|
99
|
+
This can be accomplished by setting the `data-room` attribute on the StimulusController element.
|
100
|
+
|
101
|
+
```
|
102
|
+
<a href="#" data-controller="example" data-action="click->example#increment" data-room="12345">
|
103
|
+
```
|
104
|
+
|
105
|
+
### Render Delay
|
106
|
+
|
107
|
+
An attempt is made to reduce repaint/reflow jitter when users trigger lots of updates.
|
108
|
+
|
109
|
+
You can control how long to wait _(think debounce)_ prior to updating the page.
|
110
|
+
Simply set the `renderDelay` _(milliseconds)_ option when registering the controller.
|
88
111
|
|
89
|
-
|
112
|
+
```javascript
|
113
|
+
export default class extends Controller {
|
114
|
+
connect() {
|
115
|
+
StimulusReflex.register(this, {renderDelay: 200});
|
116
|
+
}
|
117
|
+
}
|
118
|
+
```
|
90
119
|
|
91
|
-
The
|
120
|
+
The default value is `25`.
|
@@ -9,10 +9,12 @@ class StimulusReflex::Channel < ActionCable::Channel::Base
|
|
9
9
|
include CableReady::Broadcaster
|
10
10
|
|
11
11
|
def stream_name
|
12
|
-
ids = connection.identifiers.map { |identifier|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
ids = connection.identifiers.map { |identifier| send(identifier).try(:id) }
|
13
|
+
[
|
14
|
+
params[:channel],
|
15
|
+
params[:room],
|
16
|
+
ids.select(&:present?).join(";"),
|
17
|
+
].select(&:present?).join(":")
|
16
18
|
end
|
17
19
|
|
18
20
|
def subscribed
|
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: 1.0.
|
4
|
+
version: 1.0.1
|
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-08-
|
12
|
+
date: 2019-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -45,42 +45,42 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: 5.2.
|
48
|
+
version: 5.2.3
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: 5.2.
|
55
|
+
version: 5.2.3
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: actionpack
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 5.2.
|
62
|
+
version: 5.2.3
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 5.2.
|
69
|
+
version: 5.2.3
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: cable_ready
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
|
-
version: 4.0.
|
76
|
+
version: 4.0.1
|
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: 4.0.
|
83
|
+
version: 4.0.1
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: bundler
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,7 +137,6 @@ files:
|
|
137
137
|
- README.md
|
138
138
|
- Rakefile
|
139
139
|
- bin/console
|
140
|
-
- bin/deps
|
141
140
|
- bin/setup
|
142
141
|
- bin/standardize
|
143
142
|
- lib/stimulus_reflex.rb
|
data/bin/deps
DELETED