inertia_rails 1.6.0 → 1.7.0

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: b889c5a06cf6c9310b1d64c1e19a5e979aea7ba874c3014867a462386dd28937
4
- data.tar.gz: c5e1bf21eb3ff8dc1e14ebadedf43bb82f8b1af6aa46680610ad4b0054d90b3b
3
+ metadata.gz: 91a7d64f22c5d539db5dcfe7527b2bde7d4661bbab098ce75c6d6822a036dec7
4
+ data.tar.gz: 64e327c2079918628e2ff6ef21a85959691a48ed7493006cb280bff504fdfe41
5
5
  SHA512:
6
- metadata.gz: 65a66ab26b16808a9b88467a6b579074f68ba68877c055b8d2e333422454041f3461ff4ab0a947f2a52572edd8bf1c88d62d6d32ec7a1c8bd6ca776158f756c0
7
- data.tar.gz: 724961702c0bd5ffb53e427d8791f1064dcc080c4cbc253297f30207c0017065b0f2c12b4822c5969401582972810c8960fbc494884bebb32fe1df907e6a7d79
6
+ metadata.gz: de83b986de171f75fb64f28f1610e6ff7960722ea586c9ac2183dc99e6ef96fab2e5e5009e580766d595d6594ad3b7b14555b054f5302d03c7d7ac26fd4d3df8
7
+ data.tar.gz: dca78a5fbb54dac45a328958dc026f9fb08428bb860fad36835c18ce7814e892329cdad6ab860faef9b095e672485a3b40748c7a7c27cdad8d9d7f90d9526b5d
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [1.7.0] - 2020-11-24
8
+
9
+ * Add support for "lazy" props while rendering. These are props that never compute on the initial page load. The only render during a partial update that calls for them explicitly.
10
+
7
11
  ## [1.6.0] - 2020-11-20
8
12
 
9
13
  * Built in error sharing across redirects! adding `{ inertia: { errors: 'errors go here' } }` as an option in `redirect_to` will automatically feed an `errors` prop to whatever is rendered after the redirect.
@@ -1,5 +1,6 @@
1
1
  # Needed for `thread_mattr_accessor`
2
2
  require 'active_support/core_ext/module/attribute_accessors_per_thread'
3
+ require 'inertia_rails/lazy'
3
4
 
4
5
  module InertiaRails
5
6
  thread_mattr_accessor :threadsafe_shared_plain_data
@@ -36,6 +37,10 @@ module InertiaRails
36
37
  self.shared_blocks = []
37
38
  end
38
39
 
40
+ def self.lazy(value = nil, &block)
41
+ InertiaRails::Lazy.new(value, &block)
42
+ end
43
+
39
44
  private
40
45
 
41
46
  module Configuration
@@ -0,0 +1,26 @@
1
+ class InertiaRails::Lazy
2
+ def initialize(value = nil, &block)
3
+ @value = value
4
+ @block = block
5
+ end
6
+
7
+ def call
8
+ to_proc.call
9
+ end
10
+
11
+ def to_proc
12
+ # This is called by controller.instance_exec, which changes self to the
13
+ # controller instance. That makes the instance variables unavailable to the
14
+ # proc via closure. Copying the instance variables to local variables before
15
+ # the proc is returned keeps them in scope for the returned proc.
16
+ value = @value
17
+ block = @block
18
+ if value.respond_to?(:call)
19
+ value
20
+ elsif value
21
+ Proc.new { value }
22
+ else
23
+ block
24
+ end
25
+ end
26
+ end
@@ -27,13 +27,13 @@ module InertiaRails
27
27
  private
28
28
 
29
29
  def props
30
- only = (@request.headers['X-Inertia-Partial-Data'] || '').split(',').compact.map(&:to_sym)
31
-
32
- _props = ::InertiaRails.shared_data(@controller).merge(@props)
33
-
34
- _props = (only.any? && @request.headers['X-Inertia-Partial-Component'] == component) ?
35
- _props.select {|key| key.in? only} :
36
- _props
30
+ _props = ::InertiaRails.shared_data(@controller).merge(@props).select do |key, prop|
31
+ if rendering_partial_component?
32
+ key.in? partial_keys
33
+ else
34
+ !prop.is_a?(InertiaRails::Lazy)
35
+ end
36
+ end
37
37
 
38
38
  deep_transform_values(_props, lambda {|prop| prop.respond_to?(:call) ? @controller.instance_exec(&prop) : prop })
39
39
  end
@@ -52,5 +52,13 @@ module InertiaRails
52
52
 
53
53
  hash.transform_values {|value| deep_transform_values(value, proc)}
54
54
  end
55
+
56
+ def partial_keys
57
+ (@request.headers['X-Inertia-Partial-Data'] || '').split(',').compact.map(&:to_sym)
58
+ end
59
+
60
+ def rendering_partial_component?
61
+ @request.inertia_partial? && @request.headers['X-Inertia-Partial-Component'] == component
62
+ end
55
63
  end
56
64
  end
@@ -1,3 +1,3 @@
1
1
  module InertiaRails
2
- VERSION = "1.6.0"
2
+ VERSION = "1.7.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inertia_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Knoles
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-11-20 00:00:00.000000000 Z
13
+ date: 2020-11-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -141,6 +141,7 @@ files:
141
141
  - lib/inertia_rails/controller.rb
142
142
  - lib/inertia_rails/engine.rb
143
143
  - lib/inertia_rails/inertia_rails.rb
144
+ - lib/inertia_rails/lazy.rb
144
145
  - lib/inertia_rails/middleware.rb
145
146
  - lib/inertia_rails/renderer.rb
146
147
  - lib/inertia_rails/rspec.rb