-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restore mechanism based on parsing import maps
This won't cause trouble with CSP policies. Fixes #50 Closes #49 It incorporates a fix for the problem that Andrey Maslov detected in #49: it wills support namespaced stimulus controllers. Co-authored-by: Andrey Maslov <[email protected]>
- Loading branch information
1 parent
c82dfd1
commit 1434832
Showing
7 changed files
with
158 additions
and
109 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 was deleted.
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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class Hotwire::Spark::Change | ||
attr_reader :paths, :extensions, :changed_path, :action | ||
|
||
def initialize(paths, extensions, changed_path, action) | ||
@paths = paths | ||
@extensions = extensions | ||
@changed_path = changed_path | ||
@action = action | ||
end | ||
|
||
def broadcast | ||
broadcast_reload_action if should_broadcast? | ||
end | ||
|
||
private | ||
def broadcast_reload_action | ||
Hotwire::Spark.cable_server.broadcast "hotwire_spark", reload_message | ||
end | ||
|
||
def reload_message | ||
{ action: action, path: canonical_changed_path } | ||
end | ||
|
||
def canonical_changed_path | ||
canonical_changed_path = changed_path | ||
paths.each { |path| canonical_changed_path = changed_path.to_s.gsub(/^#{path}/, "") } | ||
canonical_changed_path | ||
end | ||
|
||
def should_broadcast? | ||
changed_path.to_s =~ extension_regexp | ||
end | ||
|
||
def extension_regexp | ||
/#{extensions.map { |ext| "\\." + ext }.join("|")}$/ | ||
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