turbo_reflex 0.0.21 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14ea470bd66a4d392babd0d00d219091b5a778f9723383cc0746ea1ce58a3cc0
4
- data.tar.gz: 14cbf3b9d078897ac2e4d00810a9988d5e5781339a2271e9565d26b2a5fffe31
3
+ metadata.gz: 94a743b2b5affa9a74da2b18ada148e17e1cb24538027716742c4c037d23a646
4
+ data.tar.gz: cd14a193d0e77cad794ee96bcfedded9aac76a491327157ddec8f79983c0b065
5
5
  SHA512:
6
- metadata.gz: 2483370dcdd02c59cfcdadfd84826f7c87ae64151d8fbc8a226df8b0055812c860b8347bdecdb5ad745b0a395e564159300278f05a5fbb102deff3bc5821b82e
7
- data.tar.gz: b9bf3a744c88330bf715abdb16da828712183fd005366c7ebb730e2dd170e0e68cb06c913f9589a2955ffc0233de5643ce46d6647c17482e234aef8d33378cf8
6
+ metadata.gz: 9e36653da2dfa283fb45f78a4f124f043fdf3f68d20514d6c5902a300d4eeab136c4ae69ccf591e6cf7e51fc2de95c29d2c86b078876798e1b9e83d87f29c62b
7
+ data.tar.gz: f82d726508e0dc8494d6ee7fa101478bd57095348c77d65318b6e8c387a8d870d380f2e88af3b2e691d709a81ae9fa045b4a7c04aa4187904ae4275e992006da
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- turbo_reflex (0.0.21)
4
+ turbo_reflex (0.0.23)
5
5
  rails (>= 6.1)
6
6
  turbo-rails (>= 1.1)
7
7
  turbo_ready (>= 0.1)
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-1187-47d299.svg" />
11
+ <img alt="Lines of Code" src="https://img.shields.io/badge/loc-1209-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" />
@@ -20,6 +20,11 @@ class TurboReflex::ProvisionalState
20
20
  state_manager[key] = value
21
21
  end
22
22
 
23
+ def clear
24
+ keys.each { |key| state_manager[key] = nil }
25
+ keys.clear
26
+ end
27
+
23
28
  private
24
29
 
25
30
  attr_reader :state_manager
@@ -213,9 +213,9 @@ class TurboReflex::Runner
213
213
 
214
214
  def response_type
215
215
  body = (response_body.try(:join) || response_body.to_s).strip
216
- return :body if body.match?(/<\/\s*body.*>/i)
217
- return :frame if body.match?(/<\/\s*turbo-frame.*>/i)
218
- return :stream if body.match?(/<\/\s*turbo-stream.*>/i)
216
+ return :body if body.match?(/<\/\s*body/i)
217
+ return :frame if body.match?(/<\/\s*turbo-frame/i)
218
+ return :stream if body.match?(/<\/\s*turbo-stream/i)
219
219
  :unknown
220
220
  end
221
221
 
@@ -267,17 +267,18 @@ class TurboReflex::Runner
267
267
  sanitized_content = content_sanitizer.sanitize(content).html_safe
268
268
  return if sanitized_content.blank?
269
269
 
270
- # TODO: setup negative lookahead instead of using match
271
- case response_type
270
+ html = case response_type
272
271
  when :body
273
- match = response.body.match(/<\/\s*body.*>/i).to_s
274
- response.body.sub!(match, match.prepend(sanitized_content))
272
+ match = response.body.match(/<\/\s*body/i).to_s
273
+ response.body.sub match, [sanitized_content, match].join
275
274
  when :frame
276
- match = response.body.match(/<\/\s*turbo-frame.*>/i).to_s
277
- response.body.sub!(match, match.prepend(sanitized_content))
275
+ match = response.body.match(/<\/\s*turbo-frame/i).to_s
276
+ response.body.sub match, [sanitized_content, match].join
278
277
  else
279
- response_body << sanitized_content
278
+ [response.body, sanitized_content].join
280
279
  end
280
+
281
+ response.body = html
281
282
  rescue => error
282
283
  Rails.logger.error "TurboReflex::Runner failed to append to the response! #{error.message}"
283
284
  end
@@ -34,8 +34,8 @@ class TurboReflex::State
34
34
  end
35
35
 
36
36
  def initialize(ordinal_payload = nil)
37
- @internal_keys = []
38
37
  @internal_data = {}.with_indifferent_access
38
+ @internal_keys = []
39
39
 
40
40
  deserialize(ordinal_payload).each do |(key, value)|
41
41
  write key, value
@@ -64,6 +64,12 @@ class TurboReflex::State
64
64
  value
65
65
  end
66
66
 
67
+ def delete(*keys)
68
+ key = key_for(*keys)
69
+ internal_keys.delete key
70
+ internal_data.delete key
71
+ end
72
+
67
73
  def payload
68
74
  serialize_base64 internal_data
69
75
  end
@@ -72,6 +78,11 @@ class TurboReflex::State
72
78
  serialize internal_list
73
79
  end
74
80
 
81
+ def clear
82
+ internal_keys.clear
83
+ internal_data.clear
84
+ end
85
+
75
86
  def shrink!
76
87
  @internal_data = shrink(internal_data).with_indifferent_access
77
88
  @internal_keys = internal_keys & internal_data.keys
@@ -99,7 +99,7 @@ class TurboReflex::StateManager
99
99
  @state ||= TurboReflex::State.new
100
100
  end
101
101
 
102
- delegate :cache_key, :payload, to: :state
102
+ delegate :cache_key, to: :state
103
103
 
104
104
  def [](*keys, default: nil)
105
105
  state.read(*keys, default: default)
@@ -107,7 +107,7 @@ class TurboReflex::StateManager
107
107
 
108
108
  def []=(*keys, value)
109
109
  state_will_change! if value != self[*keys]
110
- state.write(*keys, value)
110
+ value.nil? ? state.delete(*keys) : state.write(*keys, value)
111
111
  end
112
112
 
113
113
  def provisional_state
@@ -116,12 +116,27 @@ class TurboReflex::StateManager
116
116
 
117
117
  alias_method :now, :provisional_state
118
118
 
119
- def write_cookie
120
- return unless changed?
121
- clear_provisional_state!
119
+ def clear
120
+ provisional_state.clear
121
+ state.clear
122
+ end
123
+
124
+ def payload
125
+ provisional_state.clear
126
+ state.shrink!
127
+ state.payload
128
+ end
129
+
130
+ def ordinal_payload
131
+ provisional_state.clear
122
132
  state.shrink!
123
133
  state.prune! max_bytesize: TurboReflex::StateManager.cookie_max_bytesize
124
- cookies.signed["turbo_reflex.state"] = {value: state.ordinal_payload, path: "/", expires: 1.day.from_now}
134
+ state.ordinal_payload
135
+ end
136
+
137
+ def write_cookie
138
+ return unless changed?
139
+ cookies.signed["turbo_reflex.state"] = {value: ordinal_payload, path: "/", expires: 1.day.from_now}
125
140
  changes_applied
126
141
  rescue => error
127
142
  Rails.logger.error "Failed to write the TurboReflex::State cookie! #{error.message}"
@@ -145,9 +160,4 @@ class TurboReflex::StateManager
145
160
  def cookie
146
161
  cookies.signed["turbo_reflex.state"]
147
162
  end
148
-
149
- def clear_provisional_state!
150
- provisional_state.keys.each { |key| state.write key, nil }
151
- @provisional_state = nil
152
- end
153
163
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TurboReflex
4
- VERSION = "0.0.21"
4
+ VERSION = "0.0.23"
5
5
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turbo_reflex",
3
- "version": "0.0.20",
3
+ "version": "0.0.22",
4
4
  "description": "Reflexes for Turbo Frames that help you build robust reactive applications",
5
5
  "main": "app/javascript/index.js",
6
6
  "repository": "https://github.com/hopsoft/turbo_reflex",
data/tags CHANGED
@@ -216620,7 +216620,7 @@ VDash node_modules/parse-srcset/tests/he.js /^ var decodeMap = {'Aacute':'\\xC1'
216620
216620
  VDash node_modules/simple-html-tokenizer/dist/es6/index.js /^ Aacute: "Á", aacute: "á", Abreve: "Ă", abreve: "ă", ac: "∾", acd: "∿", acE: "∾̳",/;" p variable:namedCharRefs
216621
216621
  VDash node_modules/simple-html-tokenizer/dist/simple-html-tokenizer.js /^ Aacute: "Á", aacute: "á", Abreve: "Ă", abreve: "ă", ac: "∾", acd: "∿", acE: "∾/;" p variable:anonymousFunction3825d8d70300.namedCharRefs
216622
216622
  VDash node_modules/simple-html-tokenizer/dist/types/generated/html5-named-char-refs.d.ts /^ VDash: string;$/;" C
216623
- VERSION lib/turbo_reflex/version.rb /^ VERSION = "0.0.21"$/;" C module:TurboReflex
216623
+ VERSION lib/turbo_reflex/version.rb /^ VERSION = "0.0.23"$/;" C module:TurboReflex
216624
216624
  VERSION node_modules/@angular/compiler/esm2015/src/output/source_map.js /^const VERSION = 3;$/;" C
216625
216625
  VERSION node_modules/@angular/compiler/esm2015/src/version.js /^export const VERSION = new Version('8.2.14');$/;" C
216626
216626
  VERSION node_modules/@angular/compiler/esm5/src/output/source_map.js /^var VERSION = 3;$/;" v
@@ -292615,6 +292615,9 @@ cleanupModifierEffects node_modules/@popperjs/core/dist/umd/popper.js /^ fu
292615
292615
  cleanupModifierEffects node_modules/@popperjs/core/lib/createPopper.js /^ function cleanupModifierEffects() {$/;" f function:popperGenerator.createPopper
292616
292616
  cleanupModifierEffects node_modules/flowbite/dist/flowbite.js /^ function cleanupModifierEffects() {$/;" f function:popperGenerator.createPopper
292617
292617
  cleanupSubscription node_modules/prettier-standard/src/vendor/node_modules/core-js-pure/modules/esnext.observable.js /^var cleanupSubscription = function (subscriptionState) {$/;" f
292618
+ clear lib/turbo_reflex/provisional_state.rb /^ def clear$/;" f class:ProvisionalState
292619
+ clear lib/turbo_reflex/state.rb /^ def clear$/;" f class:State
292620
+ clear lib/turbo_reflex/state_manager.rb /^ def clear$/;" f class:StateManager
292618
292621
  clear node_modules/@eslint/eslintrc/lib/config-array/config-array.js /^ clear: { configurable: true, value: void 0 },$/;" p variable:anonymousObject030c97c70305
292619
292622
  clear node_modules/@glimmer/interfaces/dist/types/lib/list.d.ts /^ clear(): void;$/;" m interface:LinkedList
292620
292623
  clear node_modules/@glimmer/util/dist/amd/es5/glimmer-util.js /^ LinkedList.prototype.clear = function clear() {$/;" m class:LinkedList
@@ -292886,7 +292889,6 @@ clearTimeout node_modules/prettier-standard/src/vendor/node_modules/globals/glob
292886
292889
  clearTimeout node_modules/prettier-standard/src/vendor/node_modules/globals/globals.json /^ "clearTimeout": false,$/;" b object:shared-node-browser
292887
292890
  clearTimeout node_modules/prettier-standard/src/vendor/node_modules/globals/globals.json /^ "clearTimeout": false,$/;" b object:worker
292888
292891
  clearValue node_modules/prettier-standard/src/vendor/node_modules/@babel/traverse/lib/scope/binding.js /^ clearValue() {$/;" m class:Binding
292889
- clear_provisional_state! lib/turbo_reflex/state_manager.rb /^ def clear_provisional_state!$/;" f class:StateManager
292890
292892
  clear_write_only node_modules/uglify-js/lib/compress.js /^ function clear_write_only(assign) {$/;" f function:collapse
292891
292893
  clear_write_only node_modules/uglify-js/lib/compress.js /^ function clear_write_only(node) {$/;" f function:anonymousFunction8b3d0ad81e500.trim_destructured
292892
292894
  cleartext node_modules/@types/node/tls.d.ts /^ cleartext: TLSSocket;$/;" p interface:SecurePair
@@ -309814,6 +309816,7 @@ delegateType node_modules/@angular/compiler/src/render3/r3_factory.d.ts /^ de
309814
309816
  delegateType node_modules/@angular/compiler/src/render3/r3_factory.d.ts /^ delegateType: R3FactoryDelegateType.Factory;$/;" p interface:R3DelegatedFactoryMetadata
309815
309817
  delegateYield node_modules/@babel/runtime/helpers/esm/regeneratorRuntime.js /^ delegateYield: function delegateYield(iterable, resultName, nextLoc) {$/;" f
309816
309818
  delegateYield node_modules/@babel/runtime/helpers/regeneratorRuntime.js /^ delegateYield: function delegateYield(iterable, resultName, nextLoc) {$/;" f
309819
+ delete lib/turbo_reflex/state.rb /^ def delete(*keys)$/;" f class:State
309817
309820
  delete node_modules/@eslint/eslintrc/lib/config-array/config-array.js /^ delete: { configurable: true, value: void 0 },$/;" p variable:anonymousObject030c97c70305
309818
309821
  delete node_modules/@glimmer/util/dist/amd/es5/glimmer-util.js /^ DictSet.prototype.delete = function _delete(obj) {$/;" m class:DictSet
309819
309822
  delete node_modules/@glimmer/util/dist/commonjs/es5/lib/collections.js /^ DictSet.prototype.delete = function _delete(obj) {$/;" m class:DictSet
@@ -401624,6 +401627,7 @@ ordinalFormatters.forEach node_modules/date-fns/locale/ru/build_format_locale/in
401624
401627
  ordinalGenders node_modules/date-fns/locale/el/build_format_locale/index.js /^ var ordinalGenders = {$/;" v function:buildFormatLocale
401625
401628
  ordinalKeys.forEach node_modules/date-fns/locale/el/build_format_locale/index.js /^ ordinalKeys.forEach(function (formatterToken) {$/;" p
401626
401629
  ordinal_payload lib/turbo_reflex/state.rb /^ def ordinal_payload$/;" f class:State
401630
+ ordinal_payload lib/turbo_reflex/state_manager.rb /^ def ordinal_payload$/;" f class:StateManager
401627
401631
  ordinaryDefineOwnMetadata node_modules/prettier-standard/src/vendor/node_modules/core-js-pure/internals/reflect-metadata.js /^var ordinaryDefineOwnMetadata = function (MetadataKey, MetadataValue, O, P) {$/;" f
401628
401632
  ordinaryDefineOwnMetadata node_modules/prettier-standard/src/vendor/node_modules/core-js-pure/modules/esnext.reflect.define-metadata.js /^var ordinaryDefineOwnMetadata = ReflectMetadataModule.set;$/;" v
401629
401633
  ordinaryDefineOwnMetadata node_modules/prettier-standard/src/vendor/node_modules/core-js-pure/modules/esnext.reflect.metadata.js /^var ordinaryDefineOwnMetadata = ReflectMetadataModule.set;$/;" v
@@ -408758,6 +408762,7 @@ paused node_modules/neo-async/async.js /^ paused: false,$/;" p variable:ano
408758
408762
  paused node_modules/neo-async/async.min.js /^h<n.concurrency&&n._tasks.length;){for(var a=n._tasks.splice(n.payload||n._tasks.length),b=-1,d=/;" p variable:ca.M.na.n
408759
408763
  payload app/javascript/index.js /^ payload = {$/;" v function:invokeReflex
408760
408764
  payload lib/turbo_reflex/state.rb /^ def payload$/;" f class:State
408765
+ payload lib/turbo_reflex/state_manager.rb /^ def payload$/;" f class:StateManager
408761
408766
  payload node_modules/@types/node/module.d.ts /^ readonly payload: SourceMapPayload;$/;" p class:Module.SourceMap
408762
408767
  payload node_modules/@types/node/ts4.8/module.d.ts /^ readonly payload: SourceMapPayload;$/;" p class:Module.SourceMap
408763
408768
  payload node_modules/neo-async/async.js /^ payload: payload,$/;" p variable:anonymousFunction3eb83f570400.baseQueue.q
@@ -468457,7 +468462,7 @@ version node_modules/yaml/dist/index.js /^ version: '1.2'$/;" p variable:defaul
468457
468462
  version node_modules/yaml/dist/test-events.js /^ version: '1.2'$/;" p variable:testEvents.anonymousObjecta2b129440205
468458
468463
  version node_modules/yaml/package.json /^ "version": "1.8.3",$/;" s
468459
468464
  version node_modules/yocto-queue/package.json /^ "version": "0.1.0",$/;" s
468460
- version package.json /^ "version": "0.0.20",$/;" s
468465
+ version package.json /^ "version": "0.0.22",$/;" s
468461
468466
  versionIncluded node_modules/prettier-standard/src/vendor/node_modules/resolve/lib/core.js /^function versionIncluded(specifierValue) {$/;" f
468462
468467
  versionIncluded node_modules/resolve/lib/core.js /^function versionIncluded(specifierValue) {$/;" f
468463
468468
  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.21
4
+ version: 0.0.23
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-09 00:00:00.000000000 Z
11
+ date: 2022-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails