Skip to content

Commit

Permalink
Update API and fix IIFE example
Browse files Browse the repository at this point in the history
  • Loading branch information
afshin committed Sep 11, 2022
1 parent fcf2bc8 commit 9f078b6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions examples/example-dockpanel-iife/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<script src="https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.js"></script>

<script src="../../packages/algorithm/dist/index.js"></script>
<script src="../../packages/coreutils/dist/index.js"></script>
<script src="../../packages/collections/dist/index.js"></script>
<script src="../../packages/properties/dist/index.js"></script>
<script src="../../packages/messaging/dist/index.js"></script>
Expand Down
20 changes: 10 additions & 10 deletions packages/coreutils/src/schedule.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

/**
* Test whether the client is a brower and can request animation frames.
*/
const BROWSER =
typeof document !== 'undefined' &&
typeof requestAnimationFrame === 'function';

/**
* A composite type for callback handles, useful for unscheduling the callback.
*/
type Handle =
export type ScheduleHandle =
| ReturnType<typeof requestAnimationFrame>
| ReturnType<typeof setImmediate>
| ReturnType<typeof setTimeout>;

/**
* Whether the client is a brower and can request animation frames.
*/
const BROWSER =
typeof document !== 'undefined' &&
typeof requestAnimationFrame === 'function';

/**
* Schedules a function for invocation as soon as possible asynchronously.
*
* @param fn The function to invoke when called back.
*
* @returns A handle that can be used to `unschedule` the `fn` if possible.
*/
export function schedule(fn: () => unknown): Handle {
export function schedule(fn: () => unknown): ScheduleHandle {
if (BROWSER && document.visibilityState === 'hidden') {
return setTimeout(fn);
}
Expand All @@ -38,7 +38,7 @@ export function schedule(fn: () => unknown): Handle {
*
* @param handle The handle for the callback to unschedule.
*/
export function unschedule(handle: Handle): void {
export function unschedule(handle: ScheduleHandle): void {
if (BROWSER && document.visibilityState === 'hidden') {
return clearTimeout(handle as ReturnType<typeof setTimeout>);
}
Expand Down
10 changes: 10 additions & 0 deletions review/api/coreutils.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
```ts

/// <reference types="node" />

// @public
export interface JSONArray extends Array<JSONValue> {
}
Expand Down Expand Up @@ -106,12 +108,20 @@ export interface ReadonlyPartialJSONObject {
// @public
export type ReadonlyPartialJSONValue = JSONPrimitive | ReadonlyPartialJSONObject | ReadonlyPartialJSONArray;

// Warning: (ae-forgotten-export) The symbol "Handle" needs to be exported by the entry point index.d.ts
//
// @public
export function schedule(fn: () => unknown): Handle;

// @public
export class Token<T> {
constructor(name: string);
readonly name: string;
}

// @public
export function unschedule(handle: Handle): void;

// @public
export namespace UUID {
const uuid4: () => string;
Expand Down
5 changes: 3 additions & 2 deletions review/api/polling.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ export class Poll<T = any, U = any, V extends string = 'standby'> implements IOb
get disposed(): ISignal<this, void>;
get frequency(): IPoll.Frequency;
set frequency(frequency: IPoll.Frequency);
get hidden(): boolean;
get isDisposed(): boolean;
readonly name: string;
refresh(): Promise<void>;
schedule(next?: Partial<IPoll.State<T, U, V> & {
cancel: (last: IPoll.State<T, U, V>) => boolean;
}>): Promise<void>;
get standby(): Poll.Standby | (() => boolean | Poll.Standby);
set standby(standby: Poll.Standby | (() => boolean | Poll.Standby));
standby: Poll.Standby | (() => boolean | Poll.Standby);
start(): Promise<void>;
get state(): IPoll.State<T, U, V>;
stop(): Promise<void>;
Expand All @@ -78,6 +78,7 @@ export namespace Poll {
auto?: boolean;
factory: Factory<T, U, V>;
frequency?: Partial<IPoll.Frequency>;
linger?: number;
name?: string;
standby?: Standby | (() => boolean | Standby);
}
Expand Down

0 comments on commit 9f078b6

Please sign in to comment.