view_component_reflex 2.0.2 → 2.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6da4b2d9e532fefeb33b06d18081a1be6a281545a7716dc0650f2e5facd44d3
4
- data.tar.gz: f267ea6850f2fd12250d19af6183ca4b48266b38c37d0486375efa11871ab391
3
+ metadata.gz: 415195dd61211d392433d4e85963a6807871143f255b3264e2f7b4871bb42c42
4
+ data.tar.gz: 69f6030f02557d4d9886e3cfc00c738c66d748eb7a1a4b8149136ddaef8f8e9d
5
5
  SHA512:
6
- metadata.gz: 9bfecb324ea02fc969beba3a393752d73881a6fd917e16bcbbc49a0082113c46c4a2a0c27e1c2f9a8eb501f6429b992a0eff4ce078cc32ebc87cec1f589f0612
7
- data.tar.gz: 45b0510fea9923a7edc82eef3ade6d01459134627c9e505c0c92aadd2c16be05c11ab08aa9220e363d3ee79b8f73a9885138777f963b9e38bf4252178312a3f4
6
+ metadata.gz: e12ff695c21dc3f6c140c9d7aa7ccc854eeaeacf2a8071dc519f87c4ca1447464c01f8dfc9c200c0ac720dd864a71788fcc80f74072577c4c833743ccea29c79
7
+ data.tar.gz: ed7a85c244de733490571e7c4b529ce7b8dd295c0f6c1a5d57b15f40460b4a3737f2669bf8f28845d80a06b2ed721de49bc810c7ac9477629ead664635b2f2ee
data/README.md CHANGED
@@ -108,6 +108,20 @@ def collection_key
108
108
  end
109
109
  ```
110
110
 
111
+ ### stimulate(target, data)
112
+ Stimulate another reflex from within your component. This typically requires the key of the component you're stimulating
113
+ which can be passed in via parameters.
114
+
115
+ ```ruby
116
+ def initialize(parent_key)
117
+ @parent_key = parent_key
118
+ end
119
+
120
+ def stimulate_other
121
+ stimulate("OtherComponent#method", { key: @parent_key })
122
+ end
123
+ ```
124
+
111
125
  ### refresh!(selectors)
112
126
  Refresh a specific element on the page. Using this will implicitly run `prevent_render!`.
113
127
  If you want to render a specific element, as well as the component, a common pattern would be to pass `selector` as one of the parameters
@@ -91,7 +91,11 @@ module ViewComponentReflex
91
91
  else
92
92
  initial_state = ViewComponentReflex::Engine.state_adapter.state(request, "#{@key}_initial")
93
93
  ViewComponentReflex::Engine.state_adapter.state(request, @key).each do |k, v|
94
- unless permit_parameter?(initial_state[k], instance_variable_get(k))
94
+ instance_value = instance_variable_get(k)
95
+ if permit_parameter?(initial_state[k], instance_value)
96
+ ViewComponentReflex::Engine.state_adapter.set_state(request, controller, "#{@key}_initial", { k => instance_value })
97
+ ViewComponentReflex::Engine.state_adapter.set_state(request, controller, @key, { k => instance_value })
98
+ else
95
99
  instance_variable_set(k, v)
96
100
  end
97
101
  end
@@ -96,11 +96,23 @@ module ViewComponentReflex
96
96
  component_class.stimulus_controller
97
97
  end
98
98
 
99
+ def stimulate(target, data)
100
+ dataset = {}
101
+ data.each do |k, v|
102
+ dataset["data-#{k}"] = v.to_s
103
+ end
104
+ channel.receive({
105
+ "target" => target,
106
+ "attrs" => element.attributes.to_h.symbolize_keys,
107
+ "dataset" => dataset
108
+ })
109
+ end
110
+
99
111
  def component
100
112
  return @component if @component
101
113
  @component = component_class.allocate
102
114
  reflex = self
103
- exposed_methods = [:params, :request, :element, :refresh!, :refresh_all!, :stimulus_controller, :session, :prevent_refresh!, :selector]
115
+ exposed_methods = [:params, :request, :element, :refresh!, :refresh_all!, :stimulus_controller, :session, :prevent_refresh!, :selector, :stimulate]
104
116
  exposed_methods.each do |meth|
105
117
  @component.define_singleton_method(meth) do |*a|
106
118
  reflex.send(meth, *a)
@@ -1,3 +1,3 @@
1
1
  module ViewComponentReflex
2
- VERSION = '2.0.2'
2
+ VERSION = '2.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component_reflex
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua LeBlanc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2020-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails