Created
March 4, 2016 02:08
-
-
Save jgaskins/489ef7abeeaac91f6658 to your computer and use it in GitHub Desktop.
Nested render caching in Clearwater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GanttChart | |
include Clearwater::Component | |
include Clearwater::CachedRender | |
attr_reader :tasks | |
def initialize(tasks) | |
@tasks = tasks | |
end | |
def should_render?(previous) | |
!tasks.equal?(previous.tasks) | |
end | |
def render | |
div([ | |
TaskList.new(tasks), | |
]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TaskList | |
include Clearwater::Component | |
include Clearwater::CachedRender | |
attr_reader :task | |
def initialize(task) | |
@task = task | |
end | |
def should_render?(previous) | |
!task.equal?(previous.task) | |
end | |
def render | |
div([ | |
task.title, | |
]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TaskList | |
include Clearwater::Component | |
include Clearwater::CachedRender | |
attr_reader :tasks | |
def initialize(tasks) | |
@tasks = tasks | |
end | |
def should_render?(previous) | |
!tasks.equal?(previous.tasks) | |
end | |
def render | |
ul(tasks.map { |task| | |
li({ key: task.id }, Task.new(task)) | |
}) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment