Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for page refreshes and broadcasting #499

Merged
merged 14 commits into from
Nov 23, 2023
Merged

Support for page refreshes and broadcasting #499

merged 14 commits into from
Nov 23, 2023

Commits on Oct 27, 2023

  1. Support for page refreshes and broadcasting

    This PR is the Rails companion for the Turbo changes to add page
    refreshes.
    
    ```ruby
    turbo_refreshes_with scroll method: :morph, scroll: :preserve
    ```
    
    This adds new Active Record helpers to broadcast page refreshes from
    models:
    
    ```ruby
    class Board
      broadcast_refreshes
    end
    ```
    
    This works great in hierarchical structures, where child record touch
    parent records automatically to invalidate cache:
    
    ```ruby
    class Column
      belongs_to :board, touch: true # +Board+ will trigger a page refresh
      on column changes
    end
    ```
    
    You can also specify the streamable declaratively:
    
    ```ruby
    class Column
      belongs_to :board
      broadcast_refreshes_to :board
    end
    ```
    
    There are also instance-level companion methods to broadcast page
    refreshes:
    
    - `broadcast_refresh_later`
    - `broadcast_refresh_later_to(*streamables)`
    
    This PR introduces a new mechanism to suppress broadcasting of turbo
    treams for arbitrary blocks of code:
    
    ```ruby
    Recording.suppressing_turbo_broadcasts do
    ...
    end
    ```
    
    When broadcasting page refreshes, the system will automatically debounce
    multiple calls in a row to only broadcast the last one. This is meant
    for scenarios where you process records in mass. Because of the nature
    of such signals, it makes no sense to broadcast them repeatedly and
    individually.
    jorgemanrubia committed Oct 27, 2023
    Configuration menu
    Copy the full SHA
    a9e011d View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6b94462 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    ddeeeb8 View commit details
    Browse the repository at this point in the history

Commits on Oct 30, 2023

  1. Configuration menu
    Copy the full SHA
    a669409 View commit details
    Browse the repository at this point in the history

Commits on Oct 31, 2023

  1. Debounce jobs to broadcast page refresh signals

    A page refresh stream signals the need to reload the page. It's a global action
    that makes sense to aggregate when multiple signals are generated in a short period
    of time for a given streamable.
    
    This implementation is based on creating a thread-level debouncer associated to
    the set of streamables. The debouncer is implemented using concurrent-ruby's
    scheduled tasks.
    jorgemanrubia committed Oct 31, 2023
    Configuration menu
    Copy the full SHA
    8fcc54b View commit details
    Browse the repository at this point in the history

Commits on Nov 6, 2023

  1. Configuration menu
    Copy the full SHA
    9d3fdeb View commit details
    Browse the repository at this point in the history

Commits on Nov 13, 2023

  1. Configuration menu
    Copy the full SHA
    a49f6a6 View commit details
    Browse the repository at this point in the history

Commits on Nov 14, 2023

  1. Commit js changes

    afcapel committed Nov 14, 2023
    Configuration menu
    Copy the full SHA
    d86dc96 View commit details
    Browse the repository at this point in the history

Commits on Nov 16, 2023

  1. Configuration menu
    Copy the full SHA
    57671f9 View commit details
    Browse the repository at this point in the history
  2. Make wait noop if scheduled_task is nil

    This can happen when the Debouncer has finished its work and we clear it
    from the current thread. The next call to refresh_debouncer_for creates
    a new Debouncer, but it doesn't have a scheduled_task yet.
    
    We only use the wait method in tests, to ensure that the debounces has
    finished its work. But if the scheduled_task is nil, we know that the
    debouncer has already finished its work.
    afcapel committed Nov 16, 2023
    Configuration menu
    Copy the full SHA
    00b2b24 View commit details
    Browse the repository at this point in the history

Commits on Nov 17, 2023

  1. Configuration menu
    Copy the full SHA
    b385276 View commit details
    Browse the repository at this point in the history

Commits on Nov 20, 2023

  1. Build with latest turbo/main

    afcapel committed Nov 20, 2023
    Configuration menu
    Copy the full SHA
    1d6b6d3 View commit details
    Browse the repository at this point in the history

Commits on Nov 23, 2023

  1. Configuration menu
    Copy the full SHA
    ec710c7 View commit details
    Browse the repository at this point in the history
  2. Use released Turbo version

    afcapel committed Nov 23, 2023
    Configuration menu
    Copy the full SHA
    3199f7a View commit details
    Browse the repository at this point in the history