Skip to content

Commit

Permalink
chore: unify Array<T> -> T[]
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Aug 14, 2023
1 parent 5fb7097 commit bba9cee
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 39 deletions.
6 changes: 3 additions & 3 deletions src/__tests__/legacyAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface TimelineObject {

[key: string]: any
}
classes?: Array<string>
classes?: string[]
disabled?: boolean
isGroup?: boolean
repeating?: boolean
Expand Down Expand Up @@ -56,7 +56,7 @@ export interface TimelineKeyframe {
// templateData?: any,
[key: string]: any
}
classes?: Array<string>
classes?: string[]
}
export interface UnresolvedLogicObject {
prevOnTimeline?: string | boolean | null
Expand Down Expand Up @@ -137,7 +137,7 @@ export interface Filter {
startTime?: StartTime
endTime?: EndTime
}
export type WhosAskingTrace = Array<string>
export type WhosAskingTrace = string[]
export type objAttributeFunction = (
objId: string,
hook: 'start' | 'end' | 'duration' | 'parentStart',
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/timelineGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function generateTimeline(seed: number, maxCount: number, maxGroupDepth:

const timeline: TimelineObject[] = []

const ref: Array<Array<TimelineObject>> = [timeline]
const ref: TimelineObject[][] = [timeline]

const layers: string[] = []
const layerCount = Math.ceil(random.get() * maxCount * 0.3)
Expand Down
4 changes: 2 additions & 2 deletions src/api/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ export interface ExpressionObj {
r: Expression
}
export interface InnerExpression {
inner: Array<any> // string or Array<string>
rest: Array<string>
inner: any[]
rest: string[]
}
12 changes: 6 additions & 6 deletions src/api/resolvedTimeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export interface ResolvedTimeline<TContent extends Content = Content> {
/** Map of all objects on timeline */
objects: ResolvedTimelineObjects<TContent>
/** Map of all classes on timeline, maps className to object ids */
classes: { [className: string]: Array<string> }
classes: { [className: string]: string[] }
/** Map of the object ids, per layer */
layers: { [layer: string]: Array<string> }
layers: { [layer: string]: string[] }

// states: AllStates
nextEvents: Array<NextEvent>
nextEvents: NextEvent[]

statistics: {
/** Number of timeline objects (including keyframes) in the timeline */
Expand Down Expand Up @@ -56,7 +56,7 @@ export interface ResolvedTimelineObjects<TContent extends Content = Content> {
export interface ResolvedTimelineObject<TContent extends Content = Content> extends TimelineObject<TContent> {
resolved: {
/** Instances of the object on the timeline */
instances: Array<TimelineObjectInstance>
instances: TimelineObjectInstance[]
/** A number that increases the more levels inside of a group the objects is. 0 = no parent */
levelDeep: number
/** Id of the parent object (for children in groups or keyframes) */
Expand Down Expand Up @@ -103,10 +103,10 @@ export interface TimelineObjectInstance extends InstanceBase {
originalEnd?: Time | null

/** array of the id of the referenced objects */
references: Array<Reference>
references: Reference[]

/** If set, tells the cap of the parent. The instance will always be capped inside this. */
caps?: Array<Cap>
caps?: Cap[]
/** If the instance was generated from another instance, reference to the original */
fromInstanceId?: string
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface TimelineObject<TContent extends Content = Content> {
/**
* A list of classes on this Timeline-object. classes can be referenced by other objects using the syntax: ".className"
*/
classes?: Array<string>
classes?: string[]

/** If set to true, the object will be excluded when resolving the timeline. */
disabled?: boolean
Expand Down Expand Up @@ -95,7 +95,7 @@ export interface TimelineKeyframe<TContent extends Content = Content> {
/**
* A list of classes on this Timeline-object. classes can be referenced by other objects using the syntax: ".className"
*/
classes?: Array<string>
classes?: string[]

/** If set to true, the object will be excluded when resolving the timeline. */
disabled?: boolean
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function simplifyExpression(expr0: Expression): Expression {
export function wrapInnerExpressions(words: Array<any>): InnerExpression {
return getExpressionHandler().wrapInnerExpressions(words)
}
export function validateExpression(operatorList: Array<string>, expr0: Expression, breadcrumbs?: string): true {
export function validateExpression(operatorList: string[], expr0: Expression, breadcrumbs?: string): true {
return getExpressionHandler().validateExpression(operatorList, expr0, breadcrumbs)
}

Expand Down
8 changes: 4 additions & 4 deletions src/resolver/ExpressionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ExpressionHandler {
() => {
const expr = expressionString.replace(REGEXP_OPERATORS, ' $1 ') // Make sure there's a space between every operator & operand

const words: Array<string> = compact(expr.split(' '))
const words: string[] = compact(expr.split(' '))

if (words.length === 0) return null // empty expression

Expand Down Expand Up @@ -98,7 +98,7 @@ export class ExpressionHandler {

// Turns ['a', '(', 'b', 'c', ')'] into ['a', ['b', 'c']]
// or ['a', '&', '!', 'b'] into ['a', '&', ['', '!', 'b']]
public wrapInnerExpressions(words: Array<any>): InnerExpression {
public wrapInnerExpressions(words: any[]): InnerExpression {
for (let i = 0; i < words.length; i++) {
if (words[i] === '(') {
const tmp = this.wrapInnerExpressions(words.slice(i + 1))
Expand Down Expand Up @@ -126,7 +126,7 @@ export class ExpressionHandler {
}

/** Validates an expression. Returns true on success, throws error if not */
public validateExpression(operatorList: Array<string>, expr0: Expression, breadcrumbs?: string): true {
public validateExpression(operatorList: string[], expr0: Expression, breadcrumbs?: string): true {
if (!breadcrumbs) breadcrumbs = 'ROOT'

if (isObject(expr0) && !isArray(expr0)) {
Expand Down Expand Up @@ -156,7 +156,7 @@ export class ExpressionHandler {
public clearCache(): void {
this.cache.clear()
}
private words2Expression(operatorList: Array<string>, words: Array<any>): Expression {
private words2Expression(operatorList: string[], words: any[]): Expression {
/* istanbul ignore if */
if (!words?.length) throw new Error('words2Expression: syntax error: unbalanced expression')
while (words.length === 1 && words[0] !== null && isArray(words[0])) words = words[0]
Expand Down
16 changes: 8 additions & 8 deletions src/resolver/InstanceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { joinReferences, isReference } from './lib/reference'
export class InstanceHandler {
constructor(private resolvedTimeline: ResolvedTimelineHandler) {}

public invertInstances(instances: Array<TimelineObjectInstance>): Array<TimelineObjectInstance> {
public invertInstances(instances: TimelineObjectInstance[]): TimelineObjectInstance[] {
if (instances.length) {
instances = this.cleanInstances(instances, true, true)
const invertedInstances: Array<TimelineObjectInstance> = []
const invertedInstances: TimelineObjectInstance[] = []
if (instances[0].start !== 0) {
invertedInstances.push({
id: this.resolvedTimeline.getInstanceId(),
Expand Down Expand Up @@ -54,11 +54,11 @@ export class InstanceHandler {
}
}
public convertEventsToInstances(
events: Array<EventForInstance>,
events: EventForInstance[],
allowMerge: boolean,
allowZeroGaps = false,
omitOriginalStartEnd = false
): Array<TimelineObjectInstance> {
): TimelineObjectInstance[] {
sortEvents(events)

const activeInstances: { [eventId: string]: InstanceEvent } = {}
Expand All @@ -69,7 +69,7 @@ export class InstanceHandler {
let previousNegative = false
let negativeInstanceId: string | null = null

const returnInstances: Array<TimelineObjectInstance> = []
const returnInstances: TimelineObjectInstance[] = []
for (let i = 0; i < events.length; i++) {
const event = events[i]
const eventId: string = event.data.id ?? event.data.instance.id
Expand Down Expand Up @@ -272,15 +272,15 @@ export class InstanceHandler {
* @param instances
*/
public cleanInstances(
instances: Array<TimelineObjectInstance>,
instances: TimelineObjectInstance[],
allowMerge: boolean,
allowZeroGaps = false
): Array<TimelineObjectInstance> {
): TimelineObjectInstance[] {
// First, optimize for certain common situations:
if (instances.length === 0) return []
if (instances.length === 1) return instances

const events: Array<EventForInstance> = []
const events: EventForInstance[] = []

for (let i = 0; i < instances.length; i++) {
const instance = instances[i]
Expand Down
2 changes: 1 addition & 1 deletion src/resolver/LayerStateHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class LayerStateHandler {
// We also assume that the object has a layer

for (const instance of obj.resolved.instances) {
const timeEvents: Array<TimeEvent> = []
const timeEvents: TimeEvent[] = []

timeEvents.push({ time: instance.start, enable: true })
if (instance.end) timeEvents.push({ time: instance.end, enable: false })
Expand Down
12 changes: 6 additions & 6 deletions src/resolver/ReferenceHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { isNumericExpr } from './lib/expression'
type ObjectRefType = 'start' | 'end' | 'duration'
export interface ValueWithReference {
value: number
references: Array<Reference>
references: Reference[]
}
type LookupResult = {
result: TimelineObjectInstance[] | ValueWithReference | null
Expand All @@ -26,7 +26,7 @@ export class ReferenceHandler {
/**
* Look up a reference on the timeline
* Return values:
* Array<TimelineObjectInstance>: Instances on the timeline where the reference expression is true
* TimelineObjectInstance[]: Instances on the timeline where the reference expression is true
* ValueWithReference: A singular value which can be combined arithmetically with Instances
* null: Means "something is invalid", an null-value will always return null when combined with other values
*
Expand Down Expand Up @@ -198,7 +198,7 @@ export class ReferenceHandler {
return operate(array0, array1)
}

const result: Array<TimelineObjectInstance> = []
const result: TimelineObjectInstance[] = []

const minLength = Math.min(
isArray(array0) ? array0.length : Infinity,
Expand Down Expand Up @@ -265,7 +265,7 @@ export class ReferenceHandler {
referencedObjs: ResolvedTimelineObject[],
allReferences: Reference[]
): LookupResult {
const instanceDurations: Array<ValueWithReference> = []
const instanceDurations: ValueWithReference[] = []
for (let i = 0; i < referencedObjs.length; i++) {
const referencedObj: ResolvedTimelineObject = referencedObjs[i]

Expand Down Expand Up @@ -482,7 +482,7 @@ class ReferenceAndOrCombiner {

if (!next || next.time !== e.time) {
const newResultValue = this.calcResult(leftValue, rightValue)
const resultCaps: Array<Cap> = (leftInstance ? leftInstance.caps ?? [] : []).concat(
const resultCaps: Cap[] = (leftInstance ? leftInstance.caps ?? [] : []).concat(
rightInstance ? rightInstance.caps ?? [] : []
)

Expand All @@ -504,7 +504,7 @@ class ReferenceAndOrCombiner {
return this.instances
}

private updateInstance(time: Time, value: boolean, references: Reference[], caps: Array<Cap>) {
private updateInstance(time: Time, value: boolean, references: Reference[], caps: Cap[]) {
if (value) {
this.instances.push({
id: this.resolvedTimeline.getInstanceId(),
Expand Down
2 changes: 1 addition & 1 deletion src/resolver/TimelineValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class TimelineValidator {
/** Validates all objects in the timeline. Throws an error if something's wrong. */
public validateTimeline(
/** The timeline to validate */
timeline: Array<TimelineObject>,
timeline: TimelineObject[],
/** Set to true to enable some optional strict rules. Set this to true to increase future compatibility. */
strict?: boolean
): void {
Expand Down
4 changes: 2 additions & 2 deletions src/resolver/lib/cap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Cap, TimelineObjectInstance } from '../../api'

export function joinCaps(...caps: Array<Array<Cap> | undefined>): Array<Cap> {
export function joinCaps(...caps: Array<Cap[] | undefined>): Cap[] {
const capMap: { [capReference: string]: Cap } = {}
for (let i = 0; i < caps.length; i++) {
const caps2 = caps[i]
Expand All @@ -13,7 +13,7 @@ export function joinCaps(...caps: Array<Array<Cap> | undefined>): Array<Cap> {
}
return Object.values<Cap>(capMap)
}
export function addCapsToResuming(instance: TimelineObjectInstance, ...caps: Array<Array<Cap> | undefined>): void {
export function addCapsToResuming(instance: TimelineObjectInstance, ...caps: Array<Cap[] | undefined>): void {
const capsToAdd: Cap[] = []
const joinedCaps = joinCaps(...caps)
for (let i = 0; i < joinedCaps.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions src/resolver/lib/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export type EventForInstance = InstanceEvent<{
}>

export function sortEvents<T extends InstanceEvent>(
events: Array<T>,
events: T[],
additionalSortFcnBefore?: (a: T, b: T) => number
): Array<T> {
): T[] {
return events.sort((a: T, b: T) => {
if (a.time > b.time) return 1
if (a.time < b.time) return -1
Expand Down

0 comments on commit bba9cee

Please sign in to comment.