turbo_reflex 0.0.18 → 0.0.19

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: 127406acb7baa53df13d22c480bdfa2fb31dbb31325597f180a70bd5cf00b1f5
4
- data.tar.gz: f620a566e61912c458dd3a31b3a3fcbe056ff07272ef7a78768b5aad0d9c2e93
3
+ metadata.gz: b78482199f5511c05dc38df6ca1f83c27d84c716556ec8b2e1483a421036e174
4
+ data.tar.gz: 455d99d13aa858807fd032c85eb9ac3978298cf9cef5a5304dc0ca1005fbbc3a
5
5
  SHA512:
6
- metadata.gz: a49b91394ab6fe733eb77a2fc07813d31c21e78ad2649b352849dfe47408c3578517728f3e412c6760cff7f9bc038b69ac5d5ddf4dd75520552e13125c97cdde
7
- data.tar.gz: 6f5732b75a22103397dd0195e8f934772948c34a860cbab2b9b61e14c3ebbb679cb91295dbdeb4c1b02b735d137115a262e5aac873788e25c477fc764ddb0c28
6
+ metadata.gz: 670cda02201904ca047a872668f77f3cb2d37cda11e9b8a6c7fa3e2445cdd1fd8f73f526fdbdb59042659bb2786d0e7085b9e93d7aa947983fb2db1994131019
7
+ data.tar.gz: b15e05526613bc79feb38f5d7a8c3f7a252db44a673e392d126c02cb6912d9e1e6a23f2baec36c6dbc75c801cef53307dfb31d92c9e13f1de6aad0c9382a2305
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- turbo_reflex (0.0.18)
4
+ turbo_reflex (0.0.19)
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-1147-47d299.svg" />
11
+ <img alt="Lines of Code" src="https://img.shields.io/badge/loc-1176-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" />
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "state"
4
+
5
+ class TurboReflex::ProvisionalState
6
+ def initialize(state_manager)
7
+ @state_manager = state_manager
8
+ @keys = Set.new
9
+ end
10
+
11
+ attr_reader :keys
12
+
13
+ def [](*keys, default: nil)
14
+ state_manager[*keys, default: default]
15
+ end
16
+
17
+ def []=(*keys, value)
18
+ key = TurboReflex::State.key_for(*keys)
19
+ value.nil? ? self.keys.delete(key) : self.keys.add(key)
20
+ state_manager[key] = value
21
+ end
22
+
23
+ private
24
+
25
+ attr_reader :state_manager
26
+ end
@@ -27,17 +27,22 @@ class TurboReflex::State
27
27
  rescue => error
28
28
  raise TurboReflex::StateDeserializationError, "Unable to decode, inflate, and load Base64 string! \"#{string}\" #{error.message}"
29
29
  end
30
+
31
+ def key_for(*keys)
32
+ keys.map { |key| key.try(:cache_key) || key.to_s }.join("/")
33
+ end
30
34
  end
31
35
 
32
36
  def initialize(ordinal_payload = nil)
33
37
  @internal_keys = []
34
38
  @internal_data = {}.with_indifferent_access
35
39
 
36
- self.class.deserialize(ordinal_payload).each do |(key, value)|
40
+ deserialize(ordinal_payload).each do |(key, value)|
37
41
  write key, value
38
42
  end
39
43
  end
40
44
 
45
+ delegate :deserialize, :key_for, :serialize, :serialize_base64, to: "self.class"
41
46
  delegate :size, to: :internal_data
42
47
  delegate :include?, :has_key?, :key?, :member?, to: :internal_data
43
48
 
@@ -60,11 +65,11 @@ class TurboReflex::State
60
65
  end
61
66
 
62
67
  def payload
63
- self.class.serialize_base64 internal_data
68
+ serialize_base64 internal_data
64
69
  end
65
70
 
66
71
  def ordinal_payload
67
- self.class.serialize internal_list
72
+ serialize internal_list
68
73
  end
69
74
 
70
75
  def shrink!
@@ -100,10 +105,6 @@ class TurboReflex::State
100
105
  internal_keys.map { |key| [key, internal_data[key]] }
101
106
  end
102
107
 
103
- def key_for(*keys)
104
- keys.map { |key| key.try(:cache_key) || key.to_s }.join("/")
105
- end
106
-
107
108
  def shrink(obj)
108
109
  case obj
109
110
  when Array
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "state"
4
+ require_relative "provisional_state"
4
5
 
5
6
  # Class used to hold ephemeral state related to the rendered UI.
6
7
  #
@@ -109,8 +110,15 @@ class TurboReflex::StateManager
109
110
  state.write(*keys, value)
110
111
  end
111
112
 
113
+ def provisional_state
114
+ @provisional_state ||= TurboReflex::ProvisionalState.new(self)
115
+ end
116
+
117
+ alias_method :now, :provisional_state
118
+
112
119
  def write_cookie
113
120
  return unless changed?
121
+ clear_provisional_state!
114
122
  state.shrink!
115
123
  state.prune! max_bytesize: TurboReflex::StateManager.cookie_max_bytesize
116
124
  cookies.signed["turbo_reflex.state"] = {value: state.ordinal_payload, path: "/", expires: 1.day.from_now}
@@ -137,4 +145,9 @@ class TurboReflex::StateManager
137
145
  def cookie
138
146
  cookies.signed["turbo_reflex.state"]
139
147
  end
148
+
149
+ def clear_provisional_state!
150
+ provisional_state.keys.each { |key| state.write key, nil }
151
+ @provisional_state = nil
152
+ end
140
153
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TurboReflex
4
- VERSION = "0.0.18"
4
+ VERSION = "0.0.19"
5
5
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turbo_reflex",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
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
@@ -204570,6 +204570,7 @@ ProviderViewContext node_modules/@angular/compiler/fesm5/compiler.js /^var Provi
204570
204570
  ProviderViewContext node_modules/@angular/compiler/src/provider_analyzer.js /^ function ProviderViewContext(reflector, component) {$/;" c class:anonymousFunctionaf1fb6270200.ProviderViewContext
204571
204571
  ProviderViewContext node_modules/@angular/compiler/src/provider_analyzer.js /^ var ProviderViewContext = \/** @class *\/ (function () {$/;" c function:anonymousFunctionaf1fb6270200
204572
204572
  ProvidersFeature node_modules/@angular/compiler/src/render3/r3_identifiers.d.ts /^ static ProvidersFeature: o.ExternalReference;$/;" p class:Identifiers
204573
+ ProvisionalState lib/turbo_reflex/provisional_state.rb /^class TurboReflex::ProvisionalState$/;" c module:TurboReflex
204573
204574
  Proxy node_modules/globals/globals.json /^ "Proxy": false,$/;" b object:builtin
204574
204575
  Proxy node_modules/globals/globals.json /^ "Proxy": false,$/;" b object:es2015
204575
204576
  Proxy node_modules/globals/globals.json /^ "Proxy": false,$/;" b object:es2017
@@ -216619,7 +216620,7 @@ VDash node_modules/parse-srcset/tests/he.js /^ var decodeMap = {'Aacute':'\\xC1'
216619
216620
  VDash node_modules/simple-html-tokenizer/dist/es6/index.js /^ Aacute: "Á", aacute: "á", Abreve: "Ă", abreve: "ă", ac: "∾", acd: "∿", acE: "∾̳",/;" p variable:namedCharRefs
216620
216621
  VDash node_modules/simple-html-tokenizer/dist/simple-html-tokenizer.js /^ Aacute: "Á", aacute: "á", Abreve: "Ă", abreve: "ă", ac: "∾", acd: "∿", acE: "∾/;" p variable:anonymousFunction3825d8d70300.namedCharRefs
216621
216622
  VDash node_modules/simple-html-tokenizer/dist/types/generated/html5-named-char-refs.d.ts /^ VDash: string;$/;" C
216622
- VERSION lib/turbo_reflex/version.rb /^ VERSION = "0.0.18"$/;" C module:TurboReflex
216623
+ VERSION lib/turbo_reflex/version.rb /^ VERSION = "0.0.19"$/;" C module:TurboReflex
216623
216624
  VERSION node_modules/@angular/compiler/esm2015/src/output/source_map.js /^const VERSION = 3;$/;" C
216624
216625
  VERSION node_modules/@angular/compiler/esm2015/src/version.js /^export const VERSION = new Version('8.2.14');$/;" C
216625
216626
  VERSION node_modules/@angular/compiler/esm5/src/output/source_map.js /^var VERSION = 3;$/;" v
@@ -221140,7 +221141,9 @@ Zu node_modules/prettier-standard/src/vendor/node_modules/lodash/lodash.min.js /
221140
221141
  [[Writable]] node_modules/prettier-standard/src/vendor/node_modules/es-abstract/test/tests.js /^ '[[Writable]]': !!data['[[Writable]]']$/;" p variable:anonymousObjectc14549e4bf05
221141
221142
  [[Writable]] node_modules/prettier-standard/src/vendor/node_modules/es-abstract/test/tests.js /^ '[[Writable]]': false$/;" p variable:anonymousObjectc14549e4be05
221142
221143
  [[Writable]] node_modules/prettier-standard/src/vendor/node_modules/es-abstract/test/tests.js /^ ES.ArraySetLength(a, { '[[Writable]]': false });$/;" p variable:anonymousObjectc14549e423b05
221144
+ [] lib/turbo_reflex/provisional_state.rb /^ def [](*keys, default: nil)$/;" f class:ProvisionalState
221143
221145
  [] lib/turbo_reflex/state_manager.rb /^ def [](*keys, default: nil)$/;" f class:StateManager
221146
+ []= lib/turbo_reflex/provisional_state.rb /^ def []=(*keys, value)$/;" f class:ProvisionalState
221144
221147
  []= lib/turbo_reflex/state_manager.rb /^ def []=(*keys, value)$/;" f class:StateManager
221145
221148
  [_contentType] node_modules/@iarna/toml/lib/toml-parser.js /^ [_contentType]: {value: type}$/;" p variable:anonymousObject9ed27cbe0505
221146
221149
  [_declared] node_modules/@iarna/toml/lib/toml-parser.js /^ [_declared]: {value: false, writable: true}$/;" p variable:anonymousObject9ed27cbe0405
@@ -292883,6 +292886,7 @@ clearTimeout node_modules/prettier-standard/src/vendor/node_modules/globals/glob
292883
292886
  clearTimeout node_modules/prettier-standard/src/vendor/node_modules/globals/globals.json /^ "clearTimeout": false,$/;" b object:shared-node-browser
292884
292887
  clearTimeout node_modules/prettier-standard/src/vendor/node_modules/globals/globals.json /^ "clearTimeout": false,$/;" b object:worker
292885
292888
  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
292886
292890
  clear_write_only node_modules/uglify-js/lib/compress.js /^ function clear_write_only(assign) {$/;" f function:collapse
292887
292891
  clear_write_only node_modules/uglify-js/lib/compress.js /^ function clear_write_only(node) {$/;" f function:anonymousFunction8b3d0ad81e500.trim_destructured
292888
292892
  cleartext node_modules/@types/node/tls.d.ts /^ cleartext: TLSSocket;$/;" p interface:SecurePair
@@ -352226,6 +352230,7 @@ initialWindowSize node_modules/@types/node/http2.d.ts /^ initialWindowSiz
352226
352230
  initialWindowSize node_modules/@types/node/ts4.8/http2.d.ts /^ initialWindowSize?: number | undefined;$/;" p interface:Settings
352227
352231
  initialize lib/turbo_reflex/base.rb /^ def initialize(runner)$/;" f class:Base
352228
352232
  initialize lib/turbo_reflex/controller_pack.rb /^ def initialize(controller)$/;" f class:ControllerPack
352233
+ initialize lib/turbo_reflex/provisional_state.rb /^ def initialize(state_manager)$/;" f class:ProvisionalState
352229
352234
  initialize lib/turbo_reflex/runner.rb /^ def initialize(controller)$/;" f class:Runner
352230
352235
  initialize lib/turbo_reflex/sanitizer.rb /^ def initialize$/;" f class:Sanitizer
352231
352236
  initialize lib/turbo_reflex/state.rb /^ def initialize(ordinal_payload = nil)$/;" f class:State
@@ -363562,12 +363567,13 @@ keyValMap node_modules/graphql/jsutils/keyValMap.js /^function keyValMap(list, k
363562
363567
  keyValMap node_modules/graphql/jsutils/keyValMap.mjs /^export default function keyValMap(list, keyFn, valFn) {$/;" f
363563
363568
  key_access node_modules/sprintf-js/dist/sprintf.min.js /^!function(a){function b(){var a=arguments[0],c=b.cache;return c[a]&&c.hasOwnProperty(a)||(c[a]=b/;" p variable:anonymousFunctiona0a600570100.e
363564
363569
  key_access node_modules/sprintf-js/src/sprintf.js /^ key_access: \/^\\.([a-z_][a-z_\\d]*)\/i,$/;" p variable:anonymousFunction4f5f53590100.re
363565
- key_for lib/turbo_reflex/state.rb /^ def key_for(*keys)$/;" f class:State
363570
+ key_for lib/turbo_reflex/state.rb /^ def key_for(*keys)$/;" S class:State
363566
363571
  keyboard node_modules/prettier-standard/src/vendor/node_modules/jsx-ast-utils/lib/eventHandlers.js /^ keyboard: ['onKeyDown', 'onKeyPress', 'onKeyUp'],$/;" p variable:eventHandlersByType
363567
363572
  keyboard node_modules/prettier-standard/src/vendor/node_modules/jsx-ast-utils/src/eventHandlers.js /^ keyboard: [$/;" p variable:eventHandlersByType
363568
363573
  keygen node_modules/prettier-standard/src/vendor/node_modules/eslint-plugin-react/lib/rules/void-dom-elements-no-children.js /^ keygen: true,$/;" p variable:VOID_DOM_ELEMENTS
363569
363574
  keyofStringsOnly node_modules/ansi-escapes/node_modules/type-fest/source/tsconfig-json.d.ts /^ keyofStringsOnly?: boolean;$/;" p interface:TsConfigJson.CompilerOptions
363570
363575
  keyofStringsOnly node_modules/type-fest/source/tsconfig-json.d.ts /^ keyofStringsOnly?: boolean;$/;" p interface:TsConfigJson.CompilerOptions
363576
+ keys lib/turbo_reflex/provisional_state.rb /^ attr_reader :keys$/;" A class:ProvisionalState
363571
363577
  keys node_modules/@babel/runtime/helpers/esm/regeneratorRuntime.js /^ }), exports.keys = function (val) {$/;" f function:exports
363572
363578
  keys node_modules/@babel/runtime/helpers/regeneratorRuntime.js /^ }), exports.keys = function (val) {$/;" f function:exports
363573
363579
  keys node_modules/@glimmer/syntax/dist/types/lib/traversal/visitor.d.ts /^ keys?: KeysVisitor<N>;$/;" p interface:FullNodeTraversal
@@ -395564,6 +395570,7 @@ notnivc node_modules/parse-srcset/tests/he.js /^ var decodeMap = {'Aacute':'\\xC
395564
395570
  notnivc node_modules/simple-html-tokenizer/dist/es6/index.js /^ Aacute: "Á", aacute: "á", Abreve: "Ă", abreve: "ă", ac: "∾", acd: "∿", acE: "∾̳",/;" p variable:namedCharRefs
395565
395571
  notnivc node_modules/simple-html-tokenizer/dist/simple-html-tokenizer.js /^ Aacute: "Á", aacute: "á", Abreve: "Ă", abreve: "ă", ac: "∾", acd: "∿", acE: "∾/;" p variable:anonymousFunction3825d8d70300.namedCharRefs
395566
395572
  notnivc node_modules/simple-html-tokenizer/dist/types/generated/html5-named-char-refs.d.ts /^ notnivc: string;$/;" C
395573
+ now lib/turbo_reflex/state_manager.rb /^ alias_method :now, :provisional_state$/;" a class:StateManager
395567
395574
  now node_modules/@types/node/perf_hooks.d.ts /^ now(): number;$/;" m interface:Performance
395568
395575
  now node_modules/@types/node/ts4.8/perf_hooks.d.ts /^ now(): number;$/;" m interface:Performance
395569
395576
  now node_modules/lodash/date.js /^ 'now': require('.\/now')$/;" p property:module.exports
@@ -415136,6 +415143,7 @@ providers node_modules/angular-html-parser/lib/compiler/src/core.d.ts /^ prov
415136
415143
  provides node_modules/globals/globals.json /^ "provides": false,$/;" b object:couch
415137
415144
  provides node_modules/prettier-standard/node_modules/globals/globals.json /^ "provides": false,$/;" b object:couch
415138
415145
  provides node_modules/prettier-standard/src/vendor/node_modules/globals/globals.json /^ "provides": false,$/;" b object:couch
415146
+ provisional_state lib/turbo_reflex/state_manager.rb /^ def provisional_state$/;" f class:StateManager
415139
415147
  proxy node_modules/https-proxy-agent/package.json /^ "proxy": "1"$/;" s object:devDependencies
415140
415148
  proxy node_modules/mute-stream/mute.js /^function proxy (fn) { return function () {$/;" f
415141
415149
  proxy node_modules/rustywind/lib/download.js /^ const proxy = proxy_from_env.getProxyForUrl(url.parse(_url));$/;" C
@@ -437362,6 +437370,7 @@ stateLoad app/javascript/events.js /^ stateLoad: 'turbo-reflex:state-load',$/;"
437362
437370
  stateMap node_modules/eslint/lib/rules/no-dupe-class-members.js /^ stateMap[key] = {$/;" v function:module.exports.create.getState
437363
437371
  stateMap node_modules/prettier-standard/node_modules/eslint/lib/rules/no-dupe-class-members.js /^ stateMap[key] = {$/;" v function:module.exports.create.getState
437364
437372
  stateName node_modules/@iarna/toml/lib/parser-debug.js /^ stateName (state) {$/;" m class:DebugParser
437373
+ state_manager lib/turbo_reflex/provisional_state.rb /^ attr_reader :state_manager$/;" A class:ProvisionalState
437365
437374
  state_manager lib/turbo_reflex/runner.rb /^ attr_reader :controller, :state_manager$/;" A class:Runner
437366
437375
  state_override_block lib/turbo_reflex/state_manager.rb /^ def state_override_block(controller)$/;" S class:StateManager
437367
437376
  state_override_blocks lib/turbo_reflex/state_manager.rb /^ def state_override_blocks$/;" S class:StateManager
@@ -468446,7 +468455,7 @@ version node_modules/yaml/dist/index.js /^ version: '1.2'$/;" p variable:defaul
468446
468455
  version node_modules/yaml/dist/test-events.js /^ version: '1.2'$/;" p variable:testEvents.anonymousObjecta2b129440205
468447
468456
  version node_modules/yaml/package.json /^ "version": "1.8.3",$/;" s
468448
468457
  version node_modules/yocto-queue/package.json /^ "version": "0.1.0",$/;" s
468449
- version package.json /^ "version": "0.0.17",$/;" s
468458
+ version package.json /^ "version": "0.0.18",$/;" s
468450
468459
  versionIncluded node_modules/prettier-standard/src/vendor/node_modules/resolve/lib/core.js /^function versionIncluded(specifierValue) {$/;" f
468451
468460
  versionIncluded node_modules/resolve/lib/core.js /^function versionIncluded(specifierValue) {$/;" f
468452
468461
  versionInfo node_modules/graphql/version.d.ts /^export const versionInfo: {$/;" C
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_reflex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nate Hopkins (hopsoft)
@@ -398,6 +398,7 @@ files:
398
398
  - lib/turbo_reflex/controller_pack.rb
399
399
  - lib/turbo_reflex/engine.rb
400
400
  - lib/turbo_reflex/errors.rb
401
+ - lib/turbo_reflex/provisional_state.rb
401
402
  - lib/turbo_reflex/runner.rb
402
403
  - lib/turbo_reflex/sanitizer.rb
403
404
  - lib/turbo_reflex/state.rb