Skip to content

Commit

Permalink
chore: convert more files to typescript (#7486)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Dec 30, 2022
1 parent 5df8e5c commit 9568934
Show file tree
Hide file tree
Showing 30 changed files with 51 additions and 22 deletions.
8 changes: 6 additions & 2 deletions modules/core/src/controllers/transition-manager.ts
Expand Up @@ -97,6 +97,7 @@ export default class TransitionManager<ControllerState extends IViewState<Contro
if (this._isTransitionEnabled(nextProps)) {
let startProps = currentProps;
if (this.transition.inProgress) {
// @ts-expect-error
const {interruption, endProps} = this.transition.settings as TransitionSettings;
startProps = {
...currentProps,
Expand Down Expand Up @@ -132,7 +133,8 @@ export default class TransitionManager<ControllerState extends IViewState<Contro

_isUpdateDueToCurrentTransition(props: TransitionProps): boolean {
if (this.transition.inProgress && this.propsInTransition) {
return (this.transition.settings as TransitionSettings).interpolator.arePropsEqual(
// @ts-expect-error
return (this.transition.settings as TransitionSettings).interpolator.arePropsEqual(
props,
this.propsInTransition
);
Expand All @@ -142,9 +144,11 @@ export default class TransitionManager<ControllerState extends IViewState<Contro

_shouldIgnoreViewportChange(currentProps: TransitionProps, nextProps: TransitionProps): boolean {
if (this.transition.inProgress) {
// @ts-expect-error
const transitionSettings = this.transition.settings as TransitionSettings;
// Ignore update if it is requested to be ignored
return (
(this.transition.settings as TransitionSettings).interruption ===
transitionSettings.interruption ===
TRANSITION_EVENTS.IGNORE ||
// Ignore update if it is due to current active transition.
this._isUpdateDueToCurrentTransition(nextProps)
Expand Down
Expand Up @@ -9,8 +9,10 @@ const TRANSITION_TYPES = {
};

export default class UniformTransitionManager {
transitions = new Map();
timeline;

constructor(timeline) {
this.transitions = new Map();
this.timeline = timeline;
}

Expand Down
Expand Up @@ -2,6 +2,8 @@ import {lerp} from '@math.gl/core';
import Transition from './transition';

export default class CPUInterpolationTransition extends Transition {
_value;

get value() {
return this._value;
}
Expand Down
Expand Up @@ -53,6 +53,9 @@ function distance(value1, value2) {
}

export default class CPUSpringTransition extends Transition {
_prevValue;
_currValue;

get value() {
return this._currValue;
}
Expand Down
16 changes: 6 additions & 10 deletions modules/core/src/transitions/transition.ts
Expand Up @@ -9,24 +9,19 @@ export type TransitionSettings = {
};

export default class Transition {
private _inProgress: boolean;
private _handle: number | null;
private _inProgress: boolean = false;
private _handle: number | null = null;
private _timeline: Timeline;

time: number;
settings: TransitionSettings;
time: number = 0;
// @ts-expect-error
settings: TransitionSettings & {fromValue, toValue, duration, easing, damping, stiffness} = {duration: 0};

/**
* @params timeline {Timeline}
*/
constructor(timeline: Timeline) {
this._inProgress = false;
this._handle = null;
this._timeline = timeline;
this.time = 0;

// Defaults
this.settings = {duration: 0};
}

/* Public API */
Expand All @@ -40,6 +35,7 @@ export default class Transition {
*/
start(settings: TransitionSettings) {
this.cancel();
// @ts-expect-error
this.settings = settings;
this._inProgress = true;
this.settings.onStart?.(this);
Expand Down
File renamed without changes.
File renamed without changes.
Expand Up @@ -7,6 +7,19 @@ import {TYPE_KEY, FUNCTION_KEY} from './syntactic-sugar';
const isObject = value => value && typeof value === 'object';

export default class JSONConfiguration {
typeKey = TYPE_KEY;
functionKey = FUNCTION_KEY;
log = console; // eslint-disable-line
classes = {};
reactComponents = {};
enumerations = {};
constants = {};
functions = {};
// TODO - this needs to be simpler, function conversion should be built in
convertFunction = parseExpressionString;
preProcessClassProps = (Class, props) => props;
postProcessConvertedJson = json => json;

constructor(...configurations) {
// Initialize config with default values
this.typeKey = TYPE_KEY;
Expand Down
Expand Up @@ -18,19 +18,25 @@ import parseJSON from './helpers/parse-json';

const isObject = value => value && typeof value === 'object';

export type JSONConverterProps = {
configuration: JSONConfiguration | Record<string, any>;
onJSONChange;
};

export default class JSONConverter {
log = console; // eslint-disable-line
configuration: JSONConfiguration;
onJSONChange = () => {};
json = null;
convertedJson = null;

constructor(props) {
this.log = console; // eslint-disable-line
this.configuration = {};
this.onJSONChange = () => {};
this.json = null;
this.convertedJson = null;
this.setProps(props);
}

finalize() {}

setProps(props) {
setProps(props: JSONConverterProps) {
// HANDLE CONFIGURATION PROPS
if ('configuration' in props) {
// Accept object or `JSONConfiguration`
Expand Down
File renamed without changes.
@@ -1,6 +1,6 @@
/* global document */
const state = {
onIninitialize: _ => _,
onInitialize: _ => _,
onFinalize: _ => _,
onMessage: null
};
Expand All @@ -19,10 +19,13 @@ export default class Transport {
// this._flushQueuedConnections();
}

name: string;
_messageQueue = [];
userData = {};
_destroyed: boolean = false;

constructor(name = 'Transport') {
this.name = name;
this._messageQueue = [];
this.userData = {};
}

/**
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 9568934

Please sign in to comment.