Skip to content

Commit

Permalink
Allow nested CachedRenders
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaskins committed Mar 22, 2016
1 parent c45ef44 commit 2c0e24d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion opal/clearwater/cached_render.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ def self.included base
if(prev && prev.vnode && #{!should_render?(`prev`)}) {
return prev.vnode;
} else {
return #{Component.sanitize_content(render)};
var content = #{Component.sanitize_content(render)};
while(content && content.type == 'Thunk' && content.render) {
content = #{Component.sanitize_content(`content.render(prev)`)};
}
return content;
}
});
}
Expand Down
22 changes: 22 additions & 0 deletions spec/clearwater/cached_render_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,27 @@ def component.should_render?

2.times { `component.render(component)` }
end

it 'allows nested CachedRender renders' do
foo = Class.new do
include Clearwater::Component
include Clearwater::CachedRender

def render
'hi'
end
end

bar = Class.new do
include Clearwater::Component
include Clearwater::CachedRender

define_method :render do
foo.new
end
end.new

expect(`bar.render()`).to eq 'hi'
end
end
end

0 comments on commit 2c0e24d

Please sign in to comment.