Skip to content

Commit da91f4f

Browse files
author
Nils Henning
committed
Merge branch '20200810_refactor-isolated-component' into next-release
2 parents 93651a7 + dfd97e6 commit da91f4f

File tree

27 files changed

+189
-92
lines changed

27 files changed

+189
-92
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,23 +231,23 @@ def add_child(child_class, *args, &block)
231231
# the childs content in order to respond to the subsequent component rendering call with
232232
# the childs content. In this case: "I should be deferred"
233233
skip_deferred_child_response = false
234-
if child_class <= Matestack::Ui::Core::Async::Async || child_class < Matestack::Ui::Core::Isolate::Isolate
234+
if child_class <= Matestack::Ui::Core::Async::Async || child_class < Matestack::Ui::Core::Isolated::Isolated
235235
if args.any? { |arg| arg[:defer].present? } && @matestack_skip_defer == true
236236
skip_deferred_child_response = true
237237
end
238238
end
239239

240240
# check only allowed keys are passed to isolated components
241-
if child_class < Matestack::Ui::Core::Isolate::Isolate
242-
unless args.empty? || args[0].keys.all? { |key| [:defer, :public_options, :rerender_on, :init_on, :rerender_delay].include? key }
241+
if child_class < Matestack::Ui::Core::Isolated::Isolated
242+
unless args.empty? || args[0].keys.all? { |key| [:defer, :public_options, :rerender_on, :init_on, :rerender_delay, :matestack_context].include? key }
243243
raise "isolated components can only take params in a public_options hash, which will be exposed to the client side in order to perform an async request with these params."
244244
end
245245
if args.any? { |arg| arg[:init_on].present? } && @matestack_skip_defer == true
246246
skip_deferred_child_response = true
247247
end
248248
end
249249

250-
if self.class < Matestack::Ui::Core::Isolate::Isolate
250+
if self.class < Matestack::Ui::Core::Isolated::Isolated
251251
parent_context_included_config = @current_parent_context.get_included_config || {}
252252
parent_context_included_config.merge!({ isolated_parent_class: self.class.name })
253253
args_with_context = add_context_to_options(args,parent_context_included_config)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
%div{ class: 'matestack-isolated-component-root'}
2+
=yield

app/concepts/matestack/ui/core/isolate/isolate.js renamed to app/concepts/matestack/ui/core/isolated/isolated.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,15 @@ const componentDef = {
7171
},
7272
mounted: function (){
7373
const self = this
74-
console.log('mounted isolated component')
7574
if(this.componentConfig["init_on"] === undefined || this.componentConfig["init_on"] === null){
76-
console.log('Its me')
7775
if(self.componentConfig["defer"] == true || Number.isInteger(self.componentConfig["defer"])){
78-
console.log('I should render deferred')
7976
if(!isNaN(self.componentConfig["defer"])){
8077
self.startDefer()
8178
}
8279
else{
8380
self.renderIsolatedContent();
8481
}
8582
}
86-
else {
87-
console.log('I should NOT render deferred')
88-
}
8983
}else{
9084
if(self.componentConfig["defer"] != undefined){
9185
if(!isNaN(self.componentConfig["defer"])){

app/concepts/matestack/ui/core/isolate/isolate.rb renamed to app/concepts/matestack/ui/core/isolated/isolated.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
module Matestack::Ui::Core::Isolate
2-
class Isolate < Matestack::Ui::Core::Component::Dynamic
1+
module Matestack::Ui::Core::Isolated
2+
class Isolated < Matestack::Ui::Core::Component::Dynamic
33
vue_js_component_name "matestack-ui-core-isolate"
44

55
def initialize(*args)
@@ -11,9 +11,9 @@ def public_options
1111
@public_options ||= {}
1212
end
1313

14-
def params
15-
context[:params] ||= {}
16-
end
14+
# def params
15+
# context[:params] || matestack_context[:params]
16+
# end
1717

1818
def setup
1919
@component_config[:component_class] = self.class.name
@@ -35,12 +35,14 @@ def render_content
3535

3636
# only render vuejs component wrapper on show
3737
def show
38-
render :isolate
38+
render :isolated
3939
end
4040

4141
# this method gets called when the isolate vuejs component requests isolated content
4242
def render_isolated_content
43-
render :children if authorized?
43+
render :children_wrapper do
44+
render :children if authorized?
45+
end
4446
end
4547

4648
def authorized?

app/concepts/matestack/ui/core/js/core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import onclick from '../onclick/onclick'
1616
import collectionContent from '../collection/content/content'
1717
import collectionFilter from '../collection/filter/filter'
1818
import collectionOrder from '../collection/order/order'
19-
import isolate from '../isolate/isolate'
19+
import isolate from '../isolated/isolated'
2020

2121
let matestackUiApp = undefined
2222

app/helpers/matestack/ui/core/application_helper.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,11 @@ def render(*args)
4444
(matestack_arg < Matestack::Ui::Page)
4545
Rendering::MainRenderer.render(self, matestack_arg, options)
4646
else
47-
# if called from a controller and params contains a component key render without layout
48-
# else it was called from within an app/page and should render normally
49-
# if self.is_a?(ActionController::Base) && params&.dig(:component_key)
50-
# super layout: false
51-
# else
47+
if params[:component_class].present? && !((options = args.first).is_a?(Hash) && options[:html].present?)
48+
Rendering::MainRenderer.render(self, Matestack::Ui::Page, {})
49+
else
5250
super
53-
# end
51+
end
5452
end
5553
end
5654

app/lib/matestack/ui/core/rendering/main_renderer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def resolve_component(name)
153153

154154
def resolve_isolated_component(name)
155155
constant = const_get(name)
156-
if constant < Matestack::Ui::Core::Isolate::Isolate
156+
if constant < Matestack::Ui::Core::Isolated::Isolated
157157
constant
158158
else
159159
nil
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Matestack::Ui::IsolatedComponent = Matestack::Ui::Core::Isolate::Isolate
1+
Matestack::Ui::IsolatedComponent = Matestack::Ui::Core::Isolated::Isolated

docker-compose.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ services:
99
- "3000:3000"
1010
environment:
1111
RAILS_ENV: development
12+
links:
13+
- postgres_dummy
1214
volumes:
1315
- ./:/app
1416
- gem-volume:/usr/local/bundle
@@ -59,6 +61,17 @@ services:
5961
volumes:
6062
- test-data-volume:/var/lib/postgresql/data
6163

64+
postgres_dummy:
65+
image: postgres
66+
expose:
67+
- 5432
68+
environment:
69+
POSTGRES_USER: postgres
70+
POSTGRES_PASSWORD: postgres
71+
POSTGRES_DB: dummy
72+
volumes:
73+
- test-data-volume:/var/lib/postgresql/data
74+
6275
volumes:
6376
test-data-volume:
6477
gem-volume:

0 commit comments

Comments
 (0)