Skip to content

Commit

Permalink
Add Shiny.initializedPromise (#4063)
Browse files Browse the repository at this point in the history
* Convert Shiny from interface to class

* Remove unused global Shiny type

* Add prettier plugin for organizing imports

* Disable eslint indentation rule

* Simplify types

* Add Shiny.connectedPromise and Shiny.sessionInitPromise

* Fix typing issue

* Move prettier plugin to devDependencies

* Rename Shiny class to ShinyClass, and export type

* Remove global Shiny type; use internal imports

* Small code cleanup

* Move initShiny() function into ShinyClass

* Rebuild type files

* Raise error if window.Shiny already exists

* Rename promises

* Add InitStatusPromise class

* `yarn build` (GitHub Actions)

* Update news

* Remove isConnected

* Update yarn.lock

* Rename isInitialized to initializedPromise

* Rebuild shiny.js

* `yarn build` (GitHub Actions)

* Update NEWS

---------

Co-authored-by: wch <[email protected]>
  • Loading branch information
wch and wch authored Jul 24, 2024
1 parent 25c4096 commit bb89cf9
Show file tree
Hide file tree
Showing 28 changed files with 8,246 additions and 8,297 deletions.
4 changes: 0 additions & 4 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ rules:

default-case:
- error
indent:
- error
- 2
- SwitchCase: 1
linebreak-style:
- error
- unix
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## New features and improvements

* The client-side TypeScript code for Shiny has been refactored so that the `Shiny` object is now an instance of class `ShinyClass`. (#4063)

* In TypeScript, the `Shiny` object has a new property `initializedPromise`, which is a Promise-like object that can be `await`ed or chained with `.then()`. This Promise-like object corresponds to the `shiny:sessioninitialized` JavaScript event, but is easier to use because it can be used both before and after the events have occurred. (#4063)

* Added new functions, `useBusyIndicators()` and `busyIndicatorOptions()`, for enabling and customizing busy indication. Busy indicators provide a visual cue to users when the server is busy calculating outputs or otherwise serving requests to the client. When enabled, a spinner is shown on each calculating/recalculating output, and a pulsing banner is shown at the top of the page when the app is otherwise busy. (#4040)

* Output bindings now include the `.recalculating` CSS class when they are first bound, up until the first render. This makes it possible/easier to show progress indication when the output is calculating for the first time. (#4039)
Expand Down
15,074 changes: 7,483 additions & 7,591 deletions inst/www/shared/shiny.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions inst/www/shared/shiny.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/www/shared/shiny.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions inst/www/shared/shiny.min.js.map

Large diffs are not rendered by default.

11 changes: 2 additions & 9 deletions srcts/extras/globalShiny.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@
// Project: Shiny <https://shiny.rstudio.com/>
// Definitions by: RStudio <https://www.rstudio.com/>

import type { Shiny as RStudioShiny } from "../src/shiny/index";
import type { ShinyClass } from "../src/shiny/index";

declare global {
// Tell Shiny variable globally exists
// eslint-disable-next-line @typescript-eslint/naming-convention
const Shiny: RStudioShiny;

// Tell window.Shiny exists
interface Window {
// eslint-disable-next-line @typescript-eslint/naming-convention
Shiny: RStudioShiny;
Shiny: ShinyClass;
}

// Make `Shiny` a globally available type definition. (No need to import the type)
type Shiny = RStudioShiny;
}
5 changes: 2 additions & 3 deletions srcts/src/bindings/input/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ import { TextInputBinding } from "./text";
import { TextareaInputBinding } from "./textarea";

// TODO-barret make this an init method
type InitInputBindings = {
function initInputBindings(): {
inputBindings: BindingRegistry<InputBinding>;
fileInputBinding: FileInputBinding;
};
function initInputBindings(): InitInputBindings {
} {
const inputBindings = new BindingRegistry<InputBinding>();

inputBindings.register(new TextInputBinding(), "shiny.textInput");
Expand Down
1 change: 1 addition & 0 deletions srcts/src/components/errorConsole.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/naming-convention */

import { css, html, LitElement } from "lit";
import { Shiny } from "..";
import { ShinyClientError } from "../shiny/error";

const buttonStyles = css`
Expand Down
1 change: 1 addition & 0 deletions srcts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { init } from "./initialize";
export { Shiny, type ShinyClass } from "./initialize";

init();
13 changes: 9 additions & 4 deletions srcts/src/initialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,20 @@ import { determineBrowserInfo } from "./browser";
import { disableFormSubmission } from "./disableForm";
import { trackHistory } from "./history";

import { setShiny } from "../shiny";
import { ShinyClass } from "../shiny";
import { setUserAgent } from "../utils/userAgent";
import { windowShiny } from "../window/libraries";
import { windowUserAgent } from "../window/userAgent";

import { initReactlog } from "../shiny/reactlog";

// eslint-disable-next-line @typescript-eslint/naming-convention
let Shiny: ShinyClass;

function init(): void {
setShiny(windowShiny());
if (window.Shiny) {
throw new Error("Trying to create window.Shiny, but it already exists!");
}
Shiny = window.Shiny = new ShinyClass();
setUserAgent(windowUserAgent()); // before determineBrowserInfo()

determineBrowserInfo();
Expand All @@ -21,4 +26,4 @@ function init(): void {
initReactlog();
}

export { init };
export { init, Shiny, type ShinyClass };
1 change: 1 addition & 0 deletions srcts/src/shiny/bind.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import $ from "jquery";
import { Shiny } from "..";
import type { InputBinding, OutputBinding } from "../bindings";
import { OutputBindingAdapter } from "../bindings/outputAdapter";
import type { BindingRegistry } from "../bindings/registry";
Expand Down
Loading

0 comments on commit bb89cf9

Please sign in to comment.