Skip to content

Commit

Permalink
Only change interesting JS files
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemanrubia committed Nov 26, 2024
1 parent a84c2e5 commit f931771
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
13 changes: 9 additions & 4 deletions app/assets/javascripts/pulse_wire.js
Original file line number Diff line number Diff line change
Expand Up @@ -9956,9 +9956,14 @@

class StimulusReloader {
static async reload() {
return new StimulusReloader().reload();
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
params[_key] = arguments[_key];
}
return new StimulusReloader(...params).reload();
}
constructor() {
let filePattern = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : /./;
this.filePattern = filePattern;
this.application = window.Stimulus || Application.start();
}
async reload() {
Expand All @@ -9971,7 +9976,7 @@
await Promise.all(this.#stimulusControllerPaths.map(async moduleName => this.#reloadStimulusController(moduleName)));
}
get #stimulusControllerPaths() {
return Object.keys(this.#stimulusPathsByModule).filter(path => path.endsWith("_controller"));
return Object.keys(this.#stimulusPathsByModule).filter(path => path.endsWith("_controller") && this.filePattern.test(path));
}
get #stimulusPathsByModule() {
this.pathsByModule = this.pathsByModule || this.#parseImportmapJson();
Expand Down Expand Up @@ -10010,7 +10015,6 @@
}
async #reloadHtml() {
try {
console.debug("HOLA");
log("Reload html...");
const reloadedDocument = await reloadHtmlDocument();
this.#updateBody(reloadedDocument.body);
Expand Down Expand Up @@ -10038,7 +10042,8 @@
};

StreamActions.reload_stimulus = function () {
StimulusReloader.reload();
const filePath = nameFromFilePath(this.getAttribute("file_path"));
StimulusReloader.reload(new RegExp(filePath));
};

const PulseWire = {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/pulse_wire.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/assets/javascripts/pulse_wire.min.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions app/javascript/pulse_wire/reloaders/stimulus_reloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { log } from "../logger.js"
import { cacheBustedUrl } from "../helpers.js";

export class StimulusReloader {
static async reload() {
return new StimulusReloader().reload()
static async reload(...params) {
return new StimulusReloader(...params).reload()
}

constructor() {
constructor(filePattern = /./) {
this.filePattern = filePattern
this.application = window.Stimulus || Application.start()
}

Expand All @@ -28,7 +29,7 @@ export class StimulusReloader {
}

get #stimulusControllerPaths() {
return Object.keys(this.#stimulusPathsByModule).filter(path => path.endsWith("_controller"))
return Object.keys(this.#stimulusPathsByModule).filter(path => path.endsWith("_controller") && this.filePattern.test(path))
}

get #stimulusPathsByModule() {
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/pulse_wire/stream_actions/reload_stimulus.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Turbo } from "@hotwired/turbo-rails"
import { StimulusReloader } from "../reloaders/stimulus_reloader.js";
import { nameFromFilePath } from "../helpers.js";

Turbo.StreamActions.reload_stimulus = function () {
StimulusReloader.reload()
const filePath = nameFromFilePath(this.getAttribute("file_path"))
StimulusReloader.reload(new RegExp(filePath))
}

0 comments on commit f931771

Please sign in to comment.