turbo_reflex 0.0.26 → 0.0.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/turbo_reflex/base.rb +17 -1
- data/lib/turbo_reflex/engine.rb +5 -1
- data/lib/turbo_reflex/state_manager.rb +17 -13
- data/lib/turbo_reflex/version.rb +1 -1
- data/package.json +1 -1
- data/tags +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1ef38965d0ef18dbbc67316bed5aaffcb50da54e603528b0b72088378e4daff
|
4
|
+
data.tar.gz: d1938187e80bdb62e1f2ab46bb14f17fd130eafeb24592df905052d4c26897ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86a168a615001267eed78ffc6b1fc7ff6032d2ef7b4e4d730e2a0ed9f0b13976a5972def9eb831340618560c62021175386aa438d133a5824e10d1063a85896b
|
7
|
+
data.tar.gz: e6438f83d9584b47d04f0a152dbd1ff9c886828847b66995d6d72d5c5448f162650584b3f9cde9d3710e88d8e2651a240b2e3d2b894fdf0377c8afb9d420dacc
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
</h1>
|
9
9
|
<p align="center">
|
10
10
|
<a href="http://blog.codinghorror.com/the-best-code-is-no-code-at-all/">
|
11
|
-
<img alt="Lines of Code" src="https://img.shields.io/badge/loc-
|
11
|
+
<img alt="Lines of Code" src="https://img.shields.io/badge/loc-1249-47d299.svg" />
|
12
12
|
</a>
|
13
13
|
<a href="https://codeclimate.com/github/hopsoft/turbo_reflex/maintainability">
|
14
14
|
<img src="https://api.codeclimate.com/v1/badges/fe1162a742fe83a4fdfd/maintainability" />
|
data/lib/turbo_reflex/base.rb
CHANGED
@@ -67,7 +67,7 @@ class TurboReflex::Base
|
|
67
67
|
attr_reader :controller, :turbo_streams
|
68
68
|
alias_method :streams, :turbo_streams
|
69
69
|
|
70
|
-
delegate :dom_id,
|
70
|
+
delegate :dom_id, to: :"controller.view_context"
|
71
71
|
delegate(
|
72
72
|
:controller_action_prevented?,
|
73
73
|
:render_response,
|
@@ -86,6 +86,22 @@ class TurboReflex::Base
|
|
86
86
|
"##{dom_id(...)}"
|
87
87
|
end
|
88
88
|
|
89
|
+
# Same method signature as ActionView::Rendering#render (i.e. controller.view_context.render)
|
90
|
+
def render(options = {}, locals = {}, &block)
|
91
|
+
return controller.view_context.render(options, locals, &block) unless options.is_a?(Hash)
|
92
|
+
|
93
|
+
options = options.symbolize_keys
|
94
|
+
|
95
|
+
ivars = options[:assigns]&.each_with_object({}) do |(key, value), memo|
|
96
|
+
memo[key] = controller.instance_variable_get("@#{key}")
|
97
|
+
controller.instance_variable_set "@#{key}", value
|
98
|
+
end
|
99
|
+
|
100
|
+
controller.view_context.render(options.except(:assigns), locals, &block)
|
101
|
+
ensure
|
102
|
+
ivars&.each { |key, value| controller.instance_variable_set "@#{key}", value }
|
103
|
+
end
|
104
|
+
|
89
105
|
def morph(selector, html)
|
90
106
|
turbo_streams << turbo_stream.invoke("morph", args: [html], selector: selector)
|
91
107
|
end
|
data/lib/turbo_reflex/engine.rb
CHANGED
@@ -12,9 +12,13 @@ module TurboReflex
|
|
12
12
|
|
13
13
|
class Engine < ::Rails::Engine
|
14
14
|
config.turbo_reflex = ActiveSupport::OrderedOptions.new
|
15
|
-
config.turbo_reflex[:max_cookie_size] = ActionDispatch::Cookies::MAX_COOKIE_SIZE /
|
15
|
+
config.turbo_reflex[:max_cookie_size] = ActionDispatch::Cookies::MAX_COOKIE_SIZE / 3
|
16
16
|
config.turbo_reflex[:validate_client_token] = true
|
17
17
|
|
18
|
+
# must opt-in to state overrides
|
19
|
+
config.turbo_reflex[:apply_client_state_overrides] = false
|
20
|
+
config.turbo_reflex[:apply_server_state_overrides] = false
|
21
|
+
|
18
22
|
initializer "turbo_reflex.configuration" do
|
19
23
|
Mime::Type.register "text/vnd.turbo-reflex.html", :turbo_reflex
|
20
24
|
|
@@ -63,25 +63,29 @@ class TurboReflex::StateManager
|
|
63
63
|
header_state_hash = {}
|
64
64
|
|
65
65
|
# Apply server state overrides (i.e. state stored in databases like Redis, Postgres, etc...)
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
66
|
+
if TurboReflex.config.apply_server_state_overrides
|
67
|
+
begin
|
68
|
+
state_override_block = self.class.state_override_block(runner.controller)
|
69
|
+
if state_override_block
|
70
|
+
server_state_hash = runner.controller.instance_eval(&state_override_block).with_indifferent_access
|
71
|
+
server_state_hash.each { |key, val| self[key] = val }
|
72
|
+
end
|
73
|
+
rescue => error
|
74
|
+
Rails.logger.error "Failed to apply `state_override_block` configured in #{runner.controller.class.name} to TurboReflex::State! #{error.message}"
|
71
75
|
end
|
72
|
-
rescue => error
|
73
|
-
Rails.logger.error "Failed to apply `state_override_block` configured in #{runner.controller.class.name} to TurboReflex::State! #{error.message}"
|
74
76
|
end
|
75
77
|
|
76
|
-
#
|
78
|
+
# Apply client state overrides (i.e. optimistic state)
|
77
79
|
# NOTE: Client state HTTP headers are only sent if/when state has changed on the client (only the changes are sent).
|
78
80
|
# This prevents race conditions (state mismatch) caused when frame and XHR requests emit immediately
|
79
81
|
# before the <meta id="turbo-reflex"> has been updated with the latest state from the server.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
82
|
+
if TurboReflex.config.apply_client_state_overrides
|
83
|
+
begin
|
84
|
+
header_state_hash = TurboReflex::State.deserialize_base64(header).with_indifferent_access
|
85
|
+
header_state_hash.each { |key, val| self[key] = val }
|
86
|
+
rescue => error
|
87
|
+
Rails.logger.error "Failed to apply client state from HTTP headers to TurboReflex::State! #{error.message}"
|
88
|
+
end
|
85
89
|
end
|
86
90
|
|
87
91
|
@cookie_data = cookie_state_hash
|
data/lib/turbo_reflex/version.rb
CHANGED
data/package.json
CHANGED
data/tags
CHANGED
@@ -216745,7 +216745,7 @@ VDash node_modules/parse-srcset/tests/he.js /^ var decodeMap = {'Aacute':'\\xC1'
|
|
216745
216745
|
VDash node_modules/simple-html-tokenizer/dist/es6/index.js /^ Aacute: "Á", aacute: "á", Abreve: "Ă", abreve: "ă", ac: "∾", acd: "∿", acE: "∾̳",/;" p variable:namedCharRefs
|
216746
216746
|
VDash node_modules/simple-html-tokenizer/dist/simple-html-tokenizer.js /^ Aacute: "Á", aacute: "á", Abreve: "Ă", abreve: "ă", ac: "∾", acd: "∿", acE: "∾/;" p variable:anonymousFunction3825d8d70300.namedCharRefs
|
216747
216747
|
VDash node_modules/simple-html-tokenizer/dist/types/generated/html5-named-char-refs.d.ts /^ VDash: string;$/;" C
|
216748
|
-
VERSION lib/turbo_reflex/version.rb /^ VERSION = "0.0.
|
216748
|
+
VERSION lib/turbo_reflex/version.rb /^ VERSION = "0.0.27"$/;" C module:TurboReflex
|
216749
216749
|
VERSION node_modules/@angular/compiler/esm2015/src/output/source_map.js /^const VERSION = 3;$/;" C
|
216750
216750
|
VERSION node_modules/@angular/compiler/esm2015/src/version.js /^export const VERSION = new Version('8.2.14');$/;" C
|
216751
216751
|
VERSION node_modules/@angular/compiler/esm5/src/output/source_map.js /^var VERSION = 3;$/;" v
|
@@ -468723,7 +468723,7 @@ version node_modules/yaml/dist/index.js /^ version: '1.2'$/;" p variable:defaul
|
|
468723
468723
|
version node_modules/yaml/dist/test-events.js /^ version: '1.2'$/;" p variable:testEvents.anonymousObjecta2b129440205
|
468724
468724
|
version node_modules/yaml/package.json /^ "version": "1.8.3",$/;" s
|
468725
468725
|
version node_modules/yocto-queue/package.json /^ "version": "0.1.0",$/;" s
|
468726
|
-
version package.json /^ "version": "0.0.
|
468726
|
+
version package.json /^ "version": "0.0.26",$/;" s
|
468727
468727
|
versionIncluded node_modules/prettier-standard/src/vendor/node_modules/resolve/lib/core.js /^function versionIncluded(specifierValue) {$/;" f
|
468728
468728
|
versionIncluded node_modules/resolve/lib/core.js /^function versionIncluded(specifierValue) {$/;" f
|
468729
468729
|
versionInfo node_modules/graphql/version.d.ts /^export const versionInfo: {$/;" C
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turbo_reflex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Hopkins (hopsoft)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|