Skip to content

Commit

Permalink
Merge pull request #135 from klee0kai/fix_multy_subscribe_crashes
Browse files Browse the repository at this point in the history
Fix multy subscribe crashes
  • Loading branch information
makedonsky94 authored Aug 14, 2023
2 parents d6c8862 + c9f98be commit 08c3dbd
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions lightweightlibrary/lib/app/subscriptions-function-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ export default class SubscriptionsFunctionManager {
(input, callback) => {
try {
const subscription = (params) => {
let customSeries = []
params.seriesPrices.forEach((value, key, map) => {
customSeries.push({id: this.seriesFunctionManager.getSeriesId(key, input), prices: value})
})
params.seriesPrices = customSeries
callback(params)
let mouseEvent = this.mouseEvent(params, input)
callback(mouseEvent)
}
chart.subscribeClick(subscription)
logger.d("subscribeOnChartClicked successful")
Expand All @@ -43,22 +39,8 @@ export default class SubscriptionsFunctionManager {
(input, callback) => {
try {
const subscription = (params) => {
params.sourceEvent = this.selectProps(
"clientX", "clientY", "pageX", "pageY", "screenX", "screenY",
"localX", "localY", "ctrlKey", "altKey", "shiftKey", "metaKey"
)(params.sourceEvent)

let customSeries = []
params.seriesData.forEach((value, key, map) => {
customSeries.push({id: this.seriesFunctionManager.getSeriesId(key, input), prices: value})
})
params.seriesData = customSeries

if (params.hoveredSeries) {
params.hoveredSeries = this.seriesFunctionManager.getSeriesId(params.hoveredSeries, input)
}

callback(params)
let mouseEvent = this.mouseEvent(params, input)
callback(mouseEvent)
}
chart.subscribeCrosshairMove(subscription)
logger.d("subscribeCrosshairMove successful")
Expand All @@ -79,6 +61,27 @@ export default class SubscriptionsFunctionManager {
)
}

mouseEvent(params, input) {
let result = this.selectProps("time", "logical", "point")(params)
result.sourceEvent = this.selectProps(
"clientX", "clientY", "pageX", "pageY", "screenX", "screenY",
"localX", "localY", "ctrlKey", "altKey", "shiftKey", "metaKey"
)(params.sourceEvent)

result.seriesData = []
params.seriesData.forEach((value, key, map) => {
result.seriesData.push({
id: this.seriesFunctionManager.getSeriesId(key, input),
prices: value
})
})


if (params.hoveredSeries) {
result.hoveredSeries = this.seriesFunctionManager.getSeriesId(params.hoveredSeries, input)
}
return result
}

selectProps(...props) {
return function (obj) {
Expand Down

0 comments on commit 08c3dbd

Please sign in to comment.