Skip to content

Commit 1d9fdac

Browse files
committed
first draft of defer feature
1 parent e3f5da2 commit 1d9fdac

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-2
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ const componentDef = {
4242
if(this.componentConfig["hide_on"] != undefined){
4343
this.showing = true
4444
}
45+
if(this.componentConfig["defer"] != undefined){
46+
if(!isNaN(this.componentConfig["defer"])){
47+
setTimeout(function () {
48+
self.rerender()
49+
}, parseInt(this.componentConfig["defer"]));
50+
}
51+
}
4552
},
4653
beforeDestroy: function() {
4754
const self = this

app/lib/matestack/ui/core/page_node.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,15 @@ def method_missing meth, *args, &block
5555
end
5656

5757
if block_given?
58-
@hash[current_node]["components"] = PageNode.build(@page_instance, included, &block)
58+
if args.first.is_a?(Hash) && args.first[:defer].present?
59+
if args.first[:url_params].present? && args.first[:url_params][:component_key].present?
60+
@hash[current_node]["components"] = PageNode.build(@page_instance, included, &block)
61+
else
62+
return
63+
end
64+
else
65+
@hash[current_node]["components"] = PageNode.build(@page_instance, included, &block)
66+
end
5967
end
6068
end
6169
end

spec/dummy/app/matestack/pages/my_app/my_first_page.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
class Pages::MyApp::MyFirstPage < Matestack::Ui::Page
2+
#
3+
# def prepare
4+
# @count = DummyModel.all.count
5+
# end
26

37
def response
48
components {
@@ -7,6 +11,21 @@ def response
711
div id: "some-id", class: "some-class" do
812
plain "hello from page 1"
913
end
14+
onclick emit: "test" do
15+
button text: "rerender"
16+
end
17+
async defer: true, url_params: context[:params] do
18+
partial :my_deferred_scope
19+
end
20+
}
21+
end
22+
23+
def my_deferred_scope
24+
@count = DummyModel.all.count
25+
partial {
26+
div do
27+
plain "#{@count}"
28+
end
1029
}
1130
end
1231

vendor/assets/javascripts/matestack-ui-core.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/assets/javascripts/matestack-ui-core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)