Skip to content

Commit d919d3f

Browse files
authored
Merge pull request #445 from matestack/adjust_params_access_for_components
Add params method to base component
2 parents dd1a4eb + e6f1ed7 commit d919d3f

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

app/concepts/matestack/ui/core/component/base.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def initialize(model = nil, options = {})
6767

6868
# TODO: no idea why this is called `url_params` it contains
6969
# much more than this e.g. almost all params so maybe rename it?
70+
# will be deprecated in future releases. use the `params` method in order to access query params
7071
@url_params = context&.[](:params)&.except(:action, :controller, :component_key, :matestack_context)
7172

7273
# used when creating the child component tree
@@ -156,6 +157,11 @@ def prepare
156157
true
157158
end
158159

160+
# access params like you would do on rails views and controllers
161+
def params
162+
context[:params]
163+
end
164+
159165
## ------------------ Rendering ----------------
160166
# Invoked by Cell::ViewModel from Rendering#call
161167
#

app/concepts/matestack/ui/core/component/dynamic.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def dynamic_tag_attributes
1515
attrs = {
1616
"is": self.class.vue_js_name,
1717
"ref": component_id,
18-
":params": @url_params.to_json,
18+
":params": params.except(:controller, :action).to_json,
1919
":component-config": @component_config.to_json,
2020
"inline-template": true,
2121
}
@@ -32,6 +32,6 @@ def vue_js_name
3232
@vue_js_name ||= self.name.split(/(?=[A-Z])/).join("-").downcase.gsub("::", "")
3333
end
3434
end
35-
35+
3636
end
3737
end

spec/0.8/base/core/component/url_params_access_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def response
3535
div id: "my-component" do
3636
# TODO: rather than accessing plain instance variables
3737
# I'd recommend a method based interface (easier to adjust, test, maintain if state is moved elsewhere etc.)
38-
plain @url_params[:foo]
38+
plain params[:foo]
3939
end
4040
end
4141

spec/0.8/base/core/page/url_params_access_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ class ExamplePage < Matestack::Ui::Page
2929

3030
def response
3131
div do
32-
plain "Request Params: #{@url_params}"
32+
plain "foo: #{params[:foo]}"
3333
end
3434
end
3535

3636
end
3737

3838
visit "page_url_params_access_spec/page_test/?foo=bar"
3939

40-
expect(page).to have_content('Request Params: {"foo"=>"bar"}')
40+
expect(page).to have_content("foo: bar")
4141

4242
end
4343

0 commit comments

Comments
 (0)