Skip to content

Commit

Permalink
Add Sensor base class
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Dec 27, 2023
1 parent 3016e39 commit 6ab19dc
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-schools-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nxjs-runtime': patch
---

Add `Sensor` base class
1 change: 1 addition & 0 deletions packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export type * from './crypto';
export type * from './image';
export type { DOMPoint, DOMPointInit, DOMPointReadOnly } from './dompoint';
export type * from './domrect';
export type * from './sensor';
export type {
TimerHandler,
setTimeout,
Expand Down
71 changes: 71 additions & 0 deletions packages/runtime/src/sensor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { EventTarget } from './polyfills/event-target';
import { assertInternalConstructor, def } from './utils';

/**
* `Sensor` is the base class for all the other sensor interfaces.
* This interface cannot be used directly. Instead it provides properties,
* event handlers, and methods accessed by interfaces that inherit from it.
*
* @see https://developer.mozilla.org/docs/Web/API/Sensor
*/
export abstract class Sensor extends EventTarget {
constructor() {
super();
assertInternalConstructor(arguments);
}

/**
* A read-only boolean value indicating whether the sensor is active.
*
* @see https://developer.mozilla.org/docs/Web/API/Sensor/activated
*/
abstract get activated(): boolean;

/**
* A read-only boolean value indicating whether the sensor has a reading.
*
* @see https://developer.mozilla.org/docs/Web/API/Sensor/hasReading
*/
abstract get hasReading(): boolean;

/**
* A read-only number representing the timestamp of the latest sensor reading.
* Value is `null` if there has not yet been a reading of the sensor.
*
* @see https://developer.mozilla.org/docs/Web/API/Sensor/timestamp
*/
abstract get timestamp(): number | null;

/**
* Activates the sensor.
*
* @see https://developer.mozilla.org/docs/Web/API/Sensor/start
*/
abstract start(): void;

/**
* Deactivates the sensor.
*
* @see https://developer.mozilla.org/docs/Web/API/Sensor/stop
*/
abstract stop(): void;

addEventListener(
type: 'activate' | 'error' | 'reading',
listener: (ev: Event) => any,
options?: boolean | AddEventListenerOptions
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject,
options?: boolean | AddEventListenerOptions
): void;
addEventListener(
type: string,
callback: EventListenerOrEventListenerObject | null,
options?: boolean | AddEventListenerOptions
): void {
super.addEventListener(type, callback, options);
}
}
def('Sensor', Sensor);

0 comments on commit 6ab19dc

Please sign in to comment.