Skip to content

Commit

Permalink
impr: change indicator.onDataStatusChange to `indicator.onDataState…
Browse files Browse the repository at this point in the history
…Change`
  • Loading branch information
liihuu committed Sep 25, 2024
1 parent 19306e5 commit 8c658bf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/component/Indicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ export type IndicatorDrawCallback<D> = (params: IndicatorDrawParams<D>) => boole
export type IndicatorCalcCallback<D> = (dataList: KLineData[], indicator: Indicator<D>) => Promise<D[]> | D[]
export type IndicatorShouldUpdateCallback<D> = (prev: Indicator<D>, current: Indicator<D>) => (boolean | { calc: boolean, draw: boolean })

export enum IndicatorDataStatus {
export enum IndicatorDataState {
Loading = 'loading',
Error = 'error',
Ready = 'ready'
}

export interface IndicatorOnDataStatusChangeParams<D> {
status: IndicatorDataStatus
export interface IndicatorOnDataStateChangeParams<D> {
state: IndicatorDataState
type: LoadDataType
indicator: Indicator<D>
}
export type IndicatorOnDataStatusChangeCallback<D> = (params: IndicatorOnDataStatusChangeParams<D>) => void
export type IndicatorOnDataStateChangeCallback<D> = (params: IndicatorOnDataStateChangeParams<D>) => void

export interface Indicator<D = unknown> {
/**
Expand Down Expand Up @@ -228,9 +228,9 @@ export interface Indicator<D = unknown> {
draw: Nullable<IndicatorDrawCallback<D>>

/**
* Data status change
* Data state change
*/
onDataStatusChange: Nullable<IndicatorOnDataStatusChangeCallback<D>>
onDataStateChange: Nullable<IndicatorOnDataStateChangeCallback<D>>

/**
* Calculation result
Expand Down Expand Up @@ -355,7 +355,7 @@ export default class IndicatorImp<D = unknown> implements Indicator<D> {
createTooltipDataSource: Nullable<IndicatorCreateTooltipDataSourceCallback<D>> = null
draw: Nullable<IndicatorDrawCallback<D>> = null

onDataStatusChange: Nullable<IndicatorOnDataStatusChangeCallback<D>> = null
onDataStateChange: Nullable<IndicatorOnDataStateChangeCallback<D>> = null

result: D[] = []

Expand Down
14 changes: 7 additions & 7 deletions src/store/IndicatorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { isValid, isString } from '../common/utils/typeChecks'

import type ChartStore from './ChartStore'

import { IndicatorDataStatus, type IndicatorCreate, type IndicatorFilter } from '../component/Indicator'
import { IndicatorDataState, type IndicatorCreate, type IndicatorFilter } from '../component/Indicator'
import type IndicatorImp from '../component/Indicator'
import { IndicatorSeries } from '../component/Indicator'
import { getIndicatorClass } from '../extension/indicator/index'
Expand Down Expand Up @@ -47,23 +47,23 @@ export default class IndicatorStore {
this._scheduler.addTask({
id: generateTaskId(paneId, indicator.name),
handler: () => {
indicator.onDataStatusChange?.({
status: IndicatorDataStatus.Loading,
indicator.onDataStateChange?.({
state: IndicatorDataState.Loading,
type: loadDataType,
indicator
})
indicator.calcImp(this._chartStore.getDataList()).then(result => {
if (result) {
this._chartStore.getChart().adjustPaneViewport(false, true, true, true)
indicator.onDataStatusChange?.({
status: IndicatorDataStatus.Ready,
indicator.onDataStateChange?.({
state: IndicatorDataState.Ready,
type: loadDataType,
indicator
})
}
}).catch(() => {
indicator.onDataStatusChange?.({
status: IndicatorDataStatus.Error,
indicator.onDataStateChange?.({
state: IndicatorDataState.Error,
type: loadDataType,
indicator
})
Expand Down

0 comments on commit 8c658bf

Please sign in to comment.