Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split isFulfilledData into isFulfilledBarData and isFulfilledLineData to allow WhitespaceData with extra properties #1579

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>> {
mozeryansky marked this conversation as resolved.
Show resolved Hide resolved
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;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can add this:

export function isFulfilledData<HorzScaleItem, T extends SeriesDataItemTypeMap<HorzScaleItem>[SeriesType]>(
	data: T
): data is Extract<T, BarData<HorzScaleItem> | LineData<HorzScaleItem> | HistogramData<HorzScaleItem>> {
	return isFulfilledBarData(data) || isFulfilledLineData(data);
}

and then undo the changes in chart-api.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I just noticed too, the data in _convertMouseParams is actually generated, meaning this assert is not for user input, so it's kinda unrelated to the pr.

/**
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