cable_ready 5.0.0.rc2 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/app/assets/javascripts/cable_ready.js +1 -1
  4. data/app/assets/javascripts/cable_ready.umd.js +1 -1
  5. data/{lib → app/models/concerns}/cable_ready/updatable/memory_cache_debounce_adapter.rb +2 -0
  6. data/app/models/concerns/cable_ready/updatable.rb +1 -1
  7. data/cable_ready.gemspec +1 -1
  8. data/lib/cable_ready/version.rb +1 -1
  9. data/lib/cable_ready.rb +0 -2
  10. data/lib/generators/cable_ready/templates/app/javascript/channels/consumer.js.tt +6 -0
  11. data/lib/generators/cable_ready/templates/app/javascript/channels/index.js.esbuild.tt +4 -0
  12. data/lib/generators/cable_ready/templates/app/javascript/channels/index.js.importmap.tt +2 -0
  13. data/lib/generators/cable_ready/templates/app/javascript/channels/index.js.shakapacker.tt +5 -0
  14. data/lib/generators/cable_ready/templates/app/javascript/channels/index.js.vite.tt +1 -0
  15. data/lib/generators/cable_ready/templates/app/javascript/channels/index.js.webpacker.tt +5 -0
  16. data/lib/generators/cable_ready/templates/app/javascript/config/cable_ready.js.tt +4 -0
  17. data/lib/generators/cable_ready/templates/app/javascript/config/index.js.tt +1 -0
  18. data/lib/generators/cable_ready/templates/app/javascript/config/mrujs.js.tt +9 -0
  19. data/lib/generators/cable_ready/templates/app/javascript/controllers/%file_name%_controller.js.tt +38 -0
  20. data/lib/generators/cable_ready/templates/app/javascript/controllers/application.js.tt +11 -0
  21. data/lib/generators/cable_ready/templates/app/javascript/controllers/index.js.esbuild.tt +7 -0
  22. data/lib/generators/cable_ready/templates/app/javascript/controllers/index.js.importmap.tt +5 -0
  23. data/lib/generators/cable_ready/templates/app/javascript/controllers/index.js.shakapacker.tt +5 -0
  24. data/lib/generators/cable_ready/templates/app/javascript/controllers/index.js.vite.tt +5 -0
  25. data/lib/generators/cable_ready/templates/app/javascript/controllers/index.js.webpacker.tt +5 -0
  26. data/lib/generators/cable_ready/templates/esbuild.config.mjs.tt +94 -0
  27. data/package.json +1 -1
  28. metadata +22 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1687c9081cb1be11d90f3bd9c4dc317eb86230c72be676df1f496fc3011c1fed
4
- data.tar.gz: ca21279f5a056b68b1491327fbfbc641699a61ac8b856e58f15d273e853b26dd
3
+ metadata.gz: 2ba59c02e54e924e8c187c22a6f4025775c6de9b7732ffab37e46e9992088a95
4
+ data.tar.gz: f064e043e65174039dc33f28278436058b1999fb9feecae60d2c880b58385d57
5
5
  SHA512:
6
- metadata.gz: 9043dd3cf743413f53ec3da53f612213b58b5e231be3a3838b0d629f5df9687dd5f4dbffcec70d85b6f6597fd3a5bd362b194d50416451d6f1230083dab9bd3d
7
- data.tar.gz: afe419203dbfba527c79d4673fe37af172d9cd7f8c3549e09eb0b58264178f44090ddc6e66da1828b4a1eb99e29151aae4adfbd04fdf102ba142190d7dcb6685
6
+ metadata.gz: df84a551ce0d77685c67c60914a020290d89cbd429df12be9bba5bd5031beac2d595f6863bbc624476b0d8e00f25483c327bf00c78108208704aa4940efbeadf
7
+ data.tar.gz: 0f8222d6fd31691bf60bf3d695478e6a982c1c7471a278a4881ff6cb62e50b6caf22894ee66a9d37222c0aadf0634c3631a2540a459b2b50b72ae0e6d29caab3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cable_ready (5.0.0.rc2)
4
+ cable_ready (5.0.0)
5
5
  actionpack (>= 5.2)
6
6
  actionview (>= 5.2)
7
7
  activesupport (>= 5.2)
@@ -2,7 +2,7 @@ import morphdom from "morphdom";
2
2
 
3
3
  var name = "cable_ready";
4
4
 
5
- var version = "5.0.0-rc2";
5
+ var version = "5.0.0";
6
6
 
7
7
  var description = "CableReady helps you create great real-time user experiences by making it simple to trigger client-side DOM changes from server-side Ruby.";
8
8
 
@@ -4,7 +4,7 @@
4
4
  })(this, (function(exports, morphdom) {
5
5
  "use strict";
6
6
  var name = "cable_ready";
7
- var version = "5.0.0-rc2";
7
+ var version = "5.0.0";
8
8
  var description = "CableReady helps you create great real-time user experiences by making it simple to trigger client-side DOM changes from server-side Ruby.";
9
9
  var keywords = [ "ruby", "rails", "websockets", "actioncable", "cable", "ssr", "stimulus_reflex", "client-side", "dom" ];
10
10
  var homepage = "https://cableready.stimulusreflex.com";
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CableReady
2
4
  module Updatable
3
5
  class MemoryCacheDebounceAdapter
@@ -6,7 +6,7 @@ module CableReady
6
6
  module Updatable
7
7
  extend ::ActiveSupport::Concern
8
8
 
9
- mattr_accessor :debounce_adapter, default: MemoryCacheDebounceAdapter.instance
9
+ mattr_accessor :debounce_adapter, default: ::CableReady::Updatable::MemoryCacheDebounceAdapter.instance
10
10
 
11
11
  included do |base|
12
12
  if defined?(ActiveRecord) && base < ActiveRecord::Base
data/cable_ready.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
12
12
  gem.summary = "Out-of-Band Server Triggered DOM Operations"
13
13
 
14
14
  gem.files = Dir[
15
- "lib/**/*.{rb,rake}",
15
+ "lib/**/*.{rb,rake,tt}",
16
16
  "app/**/*.rb",
17
17
  "app/assets/javascripts/*",
18
18
  "bin/*",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CableReady
4
- VERSION = "5.0.0.rc2"
4
+ VERSION = "5.0.0"
5
5
  end
data/lib/cable_ready.rb CHANGED
@@ -17,8 +17,6 @@ require "cable_ready/version"
17
17
  require "cable_ready_helper"
18
18
 
19
19
  module CableReady
20
- autoload :MemoryCacheDebounceAdapter, "cable_ready/updatable/memory_cache_debounce_adapter"
21
-
22
20
  class << self
23
21
  def config
24
22
  CableReady::Config.instance
@@ -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()
@@ -0,0 +1,4 @@
1
+ // Load all the channels within this directory and all subdirectories.
2
+ // Channel files must be named *_channel.js.
3
+
4
+ import './**/*_channel.js'
@@ -0,0 +1,2 @@
1
+ // app/channels/index.js
2
+ // Importmaps don't require anything here
@@ -0,0 +1,5 @@
1
+ // Load all the channels within this directory and all subdirectories.
2
+ // Channel files must be named *_channel.js.
3
+
4
+ const channels = require.context('.', true, /_channel\.js$/)
5
+ channels.keys().forEach(channels)
@@ -0,0 +1 @@
1
+ const channels = import.meta.globEager('./**/*_channel.js')
@@ -0,0 +1,5 @@
1
+ // Load all the channels within this directory and all subdirectories.
2
+ // Channel files must be named *_channel.js.
3
+
4
+ const channels = require.context('.', true, /_channel\.js$/)
5
+ channels.keys().forEach(channels)
@@ -0,0 +1,4 @@
1
+ import consumer from '../channels/consumer'
2
+ import CableReady from 'cable_ready'
3
+
4
+ CableReady.initialize({ consumer })
@@ -0,0 +1 @@
1
+ import './cable_ready'
@@ -0,0 +1,9 @@
1
+ import CableReady from "cable_ready"
2
+ import mrujs from "mrujs"
3
+ import { CableCar } from "mrujs/plugins"
4
+
5
+ mrujs.start({
6
+ plugins: [
7
+ new CableCar(CableReady)
8
+ ]
9
+ })
@@ -0,0 +1,38 @@
1
+ import { Controller } from '@hotwired/stimulus'
2
+ import CableReady from 'cable_ready'
3
+
4
+ export default class extends Controller {
5
+ static values = { id: Number }
6
+
7
+ connect () {
8
+ if (this.preview) return
9
+ if (this.application.consumer) {
10
+ this.channel = this.application.consumer.subscriptions.create(
11
+ {
12
+ channel: '<%= class_name %>Channel',
13
+ id: this.idValue
14
+ },
15
+ {
16
+ received (data) {
17
+ if (data.cableReady) CableReady.perform(data.operations)
18
+ }
19
+ }
20
+ )
21
+ } else {
22
+ console.error(
23
+ `The "<%= class_name.underscore.dasherize %>" Stimulus controller requires an Action Cable consumer.\nPlease set 'application.consumer = consumer' in your application.js.`
24
+ )
25
+ }
26
+ }
27
+
28
+ disconnect () {
29
+ this.channel.unsubscribe()
30
+ }
31
+
32
+ get preview () {
33
+ return (
34
+ document.documentElement.hasAttribute('data-turbolinks-preview') ||
35
+ document.documentElement.hasAttribute('data-turbo-preview')
36
+ )
37
+ }
38
+ }
@@ -0,0 +1,11 @@
1
+ import { Application } from "@hotwired/stimulus"
2
+ import consumer from "../channels/consumer"
3
+
4
+ const application = Application.start()
5
+
6
+ // Configure Stimulus development experience
7
+ application.debug = false
8
+ application.consumer = consumer
9
+ window.Stimulus = application
10
+
11
+ export { application }
@@ -0,0 +1,7 @@
1
+ import { application } from "./application"
2
+
3
+ import controllers from "./**/*_controller.js"
4
+
5
+ controllers.forEach((controller) => {
6
+ application.register(controller.name, controller.module.default)
7
+ })
@@ -0,0 +1,5 @@
1
+ import { application } from "./application"
2
+
3
+ // Eager load all controllers defined in the import map under controllers/**/*_controller
4
+ import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
5
+ eagerLoadControllersFrom("controllers", application)
@@ -0,0 +1,5 @@
1
+ import { application } from "./application"
2
+ import { definitionsFromContext } from "@hotwired/stimulus-webpack-helpers"
3
+
4
+ const controllers = definitionsFromContext(require.context("controllers", true, /_controller\.js$/))
5
+ application.load(controllers)
@@ -0,0 +1,5 @@
1
+ import { application } from "./application"
2
+ import { registerControllers } from "stimulus-vite-helpers"
3
+
4
+ const controllers = import.meta.globEager("./**/*_controller.js");
5
+ registerControllers(application, controllers)
@@ -0,0 +1,5 @@
1
+ import { application } from "./application"
2
+ import { definitionsFromContext } from "@hotwired/stimulus-webpack-helpers"
3
+
4
+ const controllers = definitionsFromContext(require.context("controllers", true, /_controller\.js$/))
5
+ application.load(controllers)
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Esbuild is configured with 3 modes:
4
+ //
5
+ // `yarn build` - Build JavaScript and exit
6
+ // `yarn build --watch` - Rebuild JavaScript on change
7
+ // `yarn build --reload` - Reloads page when views, JavaScript, or stylesheets change
8
+ //
9
+ // Minify is enabled when "RAILS_ENV=production"
10
+ // Sourcemaps are enabled in non-production environments
11
+
12
+ import * as esbuild from "esbuild"
13
+ import path from "path"
14
+ import rails from "esbuild-rails"
15
+ import chokidar from "chokidar"
16
+ import http from "http"
17
+ import { setTimeout } from "timers/promises"
18
+
19
+ const clients = []
20
+
21
+ const entryPoints = [
22
+ "application.js"
23
+ ]
24
+
25
+ const watchDirectories = [
26
+ "./app/javascript/**/*.js",
27
+ "./app/views/**/*.html.erb",
28
+ "./app/assets/builds/**/*.css", // Wait for cssbundling changes
29
+ ]
30
+
31
+ const config = {
32
+ absWorkingDir: path.join(process.cwd(), "app/javascript"),
33
+ bundle: true,
34
+ entryPoints: entryPoints,
35
+ minify: process.env.RAILS_ENV == "production",
36
+ outdir: path.join(process.cwd(), "app/assets/builds"),
37
+ plugins: [rails()],
38
+ sourcemap: process.env.RAILS_ENV != "production"
39
+ }
40
+
41
+ async function buildAndReload() {
42
+ // Foreman & Overmind assign a separate PORT for each process
43
+ const port = parseInt(process.env.PORT)
44
+ const context = await esbuild.context({
45
+ ...config,
46
+ banner: {
47
+ js: ` (() => new EventSource("http://localhost:${port}").onmessage = () => location.reload())();`,
48
+ }
49
+ })
50
+
51
+ // Reload uses an HTTP server as an even stream to reload the browser
52
+ http.createServer((req, res) => {
53
+ return clients.push(
54
+ res.writeHead(200, {
55
+ "Content-Type": "text/event-stream",
56
+ "Cache-Control": "no-cache",
57
+ "Access-Control-Allow-Origin": "*",
58
+ Connection: "keep-alive",
59
+ })
60
+ )
61
+ }).listen(port)
62
+
63
+ await context.rebuild()
64
+ console.log("[reload] initial build succeeded")
65
+
66
+ let ready = false
67
+ chokidar.watch(watchDirectories).on("ready", () => {
68
+ console.log("[reload] ready")
69
+ ready = true
70
+ }).on("all", async (event, path) => {
71
+ if (ready === false) return
72
+
73
+ if (path.includes("javascript")) {
74
+ try {
75
+ await setTimeout(20)
76
+ await context.rebuild()
77
+ console.log("[reload] build succeeded")
78
+ } catch (error) {
79
+ console.error("[reload] build failed", error)
80
+ }
81
+ }
82
+ clients.forEach((res) => res.write("data: update\n\n"))
83
+ clients.length = 0
84
+ })
85
+ }
86
+
87
+ if (process.argv.includes("--reload")) {
88
+ buildAndReload()
89
+ } else if (process.argv.includes("--watch")) {
90
+ let context = await esbuild.context({...config, logLevel: 'info'})
91
+ context.watch()
92
+ } else {
93
+ esbuild.build(config)
94
+ }
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cable_ready",
3
- "version": "5.0.0-rc2",
3
+ "version": "5.0.0",
4
4
  "description": "CableReady helps you create great real-time user experiences by making it simple to trigger client-side DOM changes from server-side Ruby.",
5
5
  "keywords": [
6
6
  "ruby",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cable_ready
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.rc2
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-27 00:00:00.000000000 Z
11
+ date: 2023-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -214,6 +214,7 @@ files:
214
214
  - app/models/concerns/cable_ready/updatable.rb
215
215
  - app/models/concerns/cable_ready/updatable/collection_updatable_callbacks.rb
216
216
  - app/models/concerns/cable_ready/updatable/collections_registry.rb
217
+ - app/models/concerns/cable_ready/updatable/memory_cache_debounce_adapter.rb
217
218
  - app/models/concerns/cable_ready/updatable/model_updatable_callbacks.rb
218
219
  - app/models/concerns/extend_has_many.rb
219
220
  - bin/console
@@ -235,11 +236,27 @@ files:
235
236
  - lib/cable_ready/operation_builder.rb
236
237
  - lib/cable_ready/sanity_checker.rb
237
238
  - lib/cable_ready/stream_identifier.rb
238
- - lib/cable_ready/updatable/memory_cache_debounce_adapter.rb
239
239
  - lib/cable_ready/version.rb
240
240
  - lib/cable_ready_helper.rb
241
241
  - lib/generators/cable_ready/channel_generator.rb
242
+ - lib/generators/cable_ready/templates/app/javascript/channels/consumer.js.tt
243
+ - lib/generators/cable_ready/templates/app/javascript/channels/index.js.esbuild.tt
244
+ - lib/generators/cable_ready/templates/app/javascript/channels/index.js.importmap.tt
245
+ - lib/generators/cable_ready/templates/app/javascript/channels/index.js.shakapacker.tt
246
+ - lib/generators/cable_ready/templates/app/javascript/channels/index.js.vite.tt
247
+ - lib/generators/cable_ready/templates/app/javascript/channels/index.js.webpacker.tt
248
+ - lib/generators/cable_ready/templates/app/javascript/config/cable_ready.js.tt
249
+ - lib/generators/cable_ready/templates/app/javascript/config/index.js.tt
250
+ - lib/generators/cable_ready/templates/app/javascript/config/mrujs.js.tt
251
+ - lib/generators/cable_ready/templates/app/javascript/controllers/%file_name%_controller.js.tt
252
+ - lib/generators/cable_ready/templates/app/javascript/controllers/application.js.tt
253
+ - lib/generators/cable_ready/templates/app/javascript/controllers/index.js.esbuild.tt
254
+ - lib/generators/cable_ready/templates/app/javascript/controllers/index.js.importmap.tt
255
+ - lib/generators/cable_ready/templates/app/javascript/controllers/index.js.shakapacker.tt
256
+ - lib/generators/cable_ready/templates/app/javascript/controllers/index.js.vite.tt
257
+ - lib/generators/cable_ready/templates/app/javascript/controllers/index.js.webpacker.tt
242
258
  - lib/generators/cable_ready/templates/config/initializers/cable_ready.rb
259
+ - lib/generators/cable_ready/templates/esbuild.config.mjs.tt
243
260
  - lib/install/action_cable.rb
244
261
  - lib/install/broadcaster.rb
245
262
  - lib/install/bundle.rb
@@ -277,9 +294,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
277
294
  version: 2.7.0
278
295
  required_rubygems_version: !ruby/object:Gem::Requirement
279
296
  requirements:
280
- - - ">"
297
+ - - ">="
281
298
  - !ruby/object:Gem::Version
282
- version: 1.3.1
299
+ version: '0'
283
300
  requirements: []
284
301
  rubygems_version: 3.4.1
285
302
  signing_key: