Skip to content

Commit b9050d9

Browse files
committed
refactor: Move Sprocket JS files to Webpack
wip
1 parent 6cc642c commit b9050d9

File tree

14 files changed

+35
-14
lines changed

14 files changed

+35
-14
lines changed

app/assets/javascripts/application.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,16 @@
1313
//= require rails-timeago
1414
//= require locales/jquery.timeago.de.js
1515
//
16-
// lib/assets
17-
//= require flash
18-
//= require color_mode_picker
19-
//
2016
// app/assets
2117
// --> Include some assets first, as they are used by other assets.
2218
// --> Hence, the order specified here is important.
2319
//
24-
// 1. Some common base functions and monkey patches
25-
//= require base
26-
// 2. Programming groups are required by "channels/synchronized_editor_channel.js"
20+
// 1. Programming groups are required by "channels/synchronized_editor_channel.js"
2721
//= require programming_groups
28-
// 3. The turtle library is required by "editor/turtle.js"
22+
// 2. The turtle library is required by "editor/turtle.js"
2923
//= require turtle
30-
// 4. Some channels are required by "editor/editor.js.erb"
31-
//= require_tree ./channels
32-
// 5. Require the editor components, as needed by "./editor.js" and "./community_solution.js"
24+
// 3. Some channels are required by "editor/editor.js.erb"
25+
// 4. Require the editor components, as needed by "./editor.js" and "./community_solution.js"
3326
//= require_tree ./editor
3427
//
3528
// All remaining assets are loaded in alphabetical order

app/javascript/application.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,10 @@ window.ace = ace; // Publish ace in global namespace
8888
// Turbo
8989
import '@hotwired/turbo-rails';
9090
import './turbo-migration';
91+
92+
// ActionCable
93+
import "@rails/actioncable"
94+
import "./channels"
95+
96+
// Import of Rails sprocket assets with minimal changes.
97+
import 'sprocket_assets'

app/javascript/channels/consumer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Action Cable provides the framework to deal with WebSockets in Rails.
2+
// You can generate new channels where WebSocket features live using the `bin/rails generate channel` command.
3+
4+
import { createConsumer } from "@rails/actioncable"
5+
6+
export default createConsumer()

app/javascript/channels/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Import all the channels to be used by Action Cable
2+
const channels = require.context(".", true, /_channel\.js$/)
3+
channels.keys().forEach(channels)

app/assets/javascripts/channels/la_exercises.js renamed to app/javascript/channels/la_exercises_channel.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import consumer from "./consumer"
2+
13
$(document).on('turbo-migration:load', function() {
24
if ($.isController('exercises') && $('.teacher_dashboard').isPresent()) {
35

@@ -18,7 +20,7 @@ $(document).on('turbo-migration:load', function() {
1820
const specific_channel = { channel: "LaExercisesChannel", exercise_id: exercise_id, study_group_id: study_group_id };
1921

2022

21-
App.la_exercise = App.cable.subscriptions.create(specific_channel, {
23+
consumer.subscriptions.create(specific_channel, {
2224
connected: function () {
2325
// Called when the subscription is ready for use on the server
2426
},

app/assets/javascripts/channels/pg_matching_channel.js renamed to app/javascript/channels/pg_matching_channel.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import consumer from "./consumer";
2+
13
$(document).on('turbo-migration:load', function () {
24

35
if ($.isController('programming_groups') && window.location.pathname.includes('programming_groups/new')) {
46
const matching_page = $('#matching');
57
const exercise_id = matching_page.data('exercise-id');
68
const specific_channel = { channel: "PgMatchingChannel", exercise_id: exercise_id};
79

8-
App.pg_matching = App.cable.subscriptions.create(specific_channel, {
10+
consumer.subscriptions.create(specific_channel, {
911
connected() {
1012
// Called when the subscription is ready for use on the server
1113
},

0 commit comments

Comments
 (0)