Skip to content

Commit

Permalink
Merge pull request #163 from henrikbjorn/importmap-changes
Browse files Browse the repository at this point in the history
Separate importmap from the application
  • Loading branch information
rosa authored Oct 30, 2024
2 parents 4963d28 + 9b6eae0 commit 78ee499
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="turbo-cache-control" content="no-cache">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.1/css/bulma.min.css">
<%= stylesheet_link_tag "mission_control/jobs/application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags "application-mcj" %>
<%= javascript_importmap_tags "application", importmap: MissionControl::Jobs.importmap %>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion config/importmap.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pin "application-mcj", to: "mission_control/jobs/application.js", preload: true
pin "application", to: "mission_control/jobs/application.js", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
Expand Down
1 change: 1 addition & 0 deletions lib/mission_control/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module Jobs
mattr_accessor :internal_query_count_limit, default: 500_000 # Hard limit to keep unlimited count queries fast enough
mattr_accessor :show_console_help, default: true
mattr_accessor :scheduled_job_delay_threshold, default: 1.minute
mattr_accessor :importmap, default: Importmap::Map.new
mattr_accessor :backtrace_cleaner
end
end
10 changes: 7 additions & 3 deletions lib/mission_control/jobs/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ class Engine < ::Rails::Engine
app.config.assets.precompile += %w[ mission_control_jobs_manifest ]
end

initializer "mission_control-jobs.importmap", before: "importmap" do |app|
app.config.importmap.paths << root.join("config/importmap.rb")
app.config.importmap.cache_sweepers << root.join("app/javascript")
initializer "mission_control-jobs.importmap", after: "importmap" do |app|
MissionControl::Jobs.importmap.draw(root.join("config/importmap.rb"))
MissionControl::Jobs.importmap.cache_sweeper(watches: root.join("app/javascript"))

ActiveSupport.on_load(:action_controller_base) do
before_action { MissionControl::Jobs.importmap.cache_sweeper.execute_if_updated }
end
end
end
end
Expand Down

0 comments on commit 78ee499

Please sign in to comment.