-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73864e0
commit 3002d87
Showing
5 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type {Time, ISeriesPrimitive} from 'lightweight-charts'; | ||
|
||
export interface $$PROPS<T = Time> { | ||
view: ISeriesPrimitive<T>; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface $$EVENTS { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<svelte:options immutable={true}/> | ||
|
||
<script lang="ts"> | ||
import type {$$PROPS} from './series-primitive.interface.js'; | ||
import {useSeriesPrimitiveEffect} from './internal/utils.js'; | ||
export let view: $$PROPS['view']; | ||
useSeriesPrimitiveEffect(() => [{ view }]); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type {ISeriesApi, ISeriesPrimitive, SeriesType, Time} from 'lightweight-charts'; | ||
import type {ActionResult} from './utils.js'; | ||
|
||
export interface SeriesPrimitiveParams<T = Time> { | ||
view: ISeriesPrimitive<T>; | ||
} | ||
|
||
export type SeriesPrimitiveActionResult<T = Time> = ActionResult<SeriesPrimitiveParams<T>>; | ||
|
||
export function seriesPrimitive<S extends SeriesType, T = Time>( | ||
target: ISeriesApi<S, T>, | ||
params: SeriesPrimitiveParams<T> | ||
): SeriesPrimitiveActionResult<T> { | ||
let { view } = params; | ||
target.attachPrimitive(view); | ||
|
||
return { | ||
update(nextParams: SeriesPrimitiveParams<T>): void { | ||
if (nextParams.view !== view) { | ||
target.detachPrimitive(view); | ||
view = nextParams.view; | ||
target.attachPrimitive(view); | ||
} | ||
}, | ||
destroy(): void { | ||
target.detachPrimitive(view); | ||
} | ||
}; | ||
} |