Skip to content

Commit e6f1ed7

Browse files
committed
add params method to base component in order to enable params access via params method like we're used to from rails views or controllers
1 parent 015c434 commit e6f1ed7

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Base < Trailblazer::Cell
55
include Matestack::Ui::Core::HtmlAttributes
66
include Matestack::Ui::Core::Properties
77

8-
# define html global attributes
8+
# define html global attributes
99
html_attributes *HTML_GLOBAL_ATTRIBUTES, *HTML_EVENT_ATTRIBUTES
1010

1111
# probably eed to remove for other tests to be green again
@@ -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
@@ -159,6 +160,11 @@ def prepare
159160
true
160161
end
161162

163+
# access params like you would do on rails views and controllers
164+
def params
165+
context[:params]
166+
end
167+
162168
## ------------------ Rendering ----------------
163169
# Invoked by Cell::ViewModel from Rendering#call
164170
#
@@ -318,7 +324,7 @@ def add_context_to_options(args, included_config=nil)
318324
case args.size
319325
when 0 then [
320326
{
321-
context: context,
327+
context: context,
322328
included_config: included_config,
323329
}
324330
]

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)