-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move hydration mechanics to the lower level commands lib (#21)
- Loading branch information
Showing
14 changed files
with
238 additions
and
253 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
class TurboBoost::Elements::ApplicationCommand < TurboBoost::Commands::Command | ||
protected | ||
|
||
def render_payload | ||
return {} if element.renders.blank? | ||
@render_payload ||= {partial: idomatic_partial_path(element.renders)}.tap do |payload| | ||
if element.assigns.present? | ||
payload[:assigns] = JSON.parse(element.assigns) | ||
payload[:assigns].each { |key, value| payload[:assigns][key] = hydrate_value(value) } | ||
end | ||
if element.locals.present? | ||
payload[:locals] = JSON.parse(element.locals) | ||
payload[:locals].each { |key, value| payload[:locals][key] = hydrate_value(value) } | ||
end | ||
end.deep_symbolize_keys | ||
end | ||
|
||
private | ||
|
||
def hydrate_value(value) | ||
hydrated = begin | ||
GlobalID::Locator.locate_signed(value) | ||
rescue | ||
value | ||
end | ||
hydrated.blank? ? nil : hydrated | ||
end | ||
|
||
def idomatic_partial_path(partial_path) | ||
partial_path.to_s.gsub("/_", "/").split(".").first | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.