Skip to content

Commit

Permalink
Merge pull request #1579 from mozeryansky/isFulfilledData
Browse files Browse the repository at this point in the history
Split `isFulfilledData` into `isFulfilledBarData` and `isFulfilledLineData` to allow `WhitespaceData` with extra properties
  • Loading branch information
SlicedSilver authored Jul 25, 2024
2 parents f934911 + 0e1ea7d commit 6e70f54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/model/data-consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,19 @@ export function isWhitespaceData<HorzScaleItem = Time>(data: SeriesDataItemTypeM
export function isFulfilledData<HorzScaleItem, T extends SeriesDataItemTypeMap<HorzScaleItem>[SeriesType]>(
data: T
): data is Extract<T, BarData<HorzScaleItem> | LineData<HorzScaleItem> | HistogramData<HorzScaleItem>> {
return (
(data as Partial<BarData<HorzScaleItem>>).open !== undefined ||
(data as Partial<LineData<HorzScaleItem>>).value !== undefined
);
return isFulfilledBarData(data) || isFulfilledLineData(data);
}

export function isFulfilledBarData<HorzScaleItem, T extends SeriesDataItemTypeMap<HorzScaleItem>[SeriesType]>(
data: T
): data is Extract<T, BarData<HorzScaleItem>> {
return (data as Partial<BarData<HorzScaleItem>>).open !== undefined;
}

export function isFulfilledLineData<HorzScaleItem, T extends SeriesDataItemTypeMap<HorzScaleItem>[SeriesType]>(
data: T
): data is Extract<T, LineData<HorzScaleItem> | HistogramData<HorzScaleItem>> {
return (data as Partial<LineData<HorzScaleItem>>).value !== undefined;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/model/data-validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { assert } from '../helpers/assertions';

import { isFulfilledData, SeriesDataItemTypeMap } from './data-consumer';
import { isFulfilledBarData, isFulfilledLineData, SeriesDataItemTypeMap } from './data-consumer';
import { IHorzScaleBehavior } from './ihorz-scale-behavior';
import { CreatePriceLineOptions } from './price-line-options';
import { SeriesMarker } from './series-markers';
Expand Down Expand Up @@ -66,7 +66,7 @@ function checkBarItem<HorzScaleItem>(
type: 'Bar' | 'Candlestick',
barItem: SeriesDataItemTypeMap<HorzScaleItem>[typeof type]
): void {
if (!isFulfilledData(barItem)) {
if (!isFulfilledBarData(barItem)) {
return;
}

Expand Down Expand Up @@ -104,7 +104,7 @@ function checkLineItem<HorzScaleItem>(
type: 'Area' | 'Baseline' | 'Line' | 'Histogram',
lineItem: SeriesDataItemTypeMap<HorzScaleItem>[typeof type]
): void {
if (!isFulfilledData(lineItem)) {
if (!isFulfilledLineData(lineItem)) {
return;
}

Expand Down

0 comments on commit 6e70f54

Please sign in to comment.