VolkovLabs / business-text

The Business Text panel plugin allows you to construct a text visualization template from the values of a dataset returned by a data source query.
https://volkovlabs.io
Apache License 2.0
83 stars 13 forks source link

Add Event Bus object to JavaScript function #179

Closed asimonok closed 1 year ago

asimonok commented 1 year ago

Pass eventBus object to javascript function.

Resolves #175.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 95.23% and project coverage change: +2.92 :tada:

Comparison is base (d0dc393) 78.60% compared to head (3bbcdd7) 81.52%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #179 +/- ## ========================================== + Coverage 78.60% 81.52% +2.92% ========================================== Files 25 25 Lines 229 249 +20 Branches 28 32 +4 ========================================== + Hits 180 203 +23 + Misses 46 43 -3 Partials 3 3 ``` | [Impacted Files](https://app.codecov.io/gh/VolkovLabs/volkovlabs-dynamictext-panel/pull/179?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VolkovLabs) | Coverage Δ | | |---|---|---| | [src/constants/editor.ts](https://app.codecov.io/gh/VolkovLabs/volkovlabs-dynamictext-panel/pull/179?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VolkovLabs#diff-c3JjL2NvbnN0YW50cy9lZGl0b3IudHM=) | `100.00% <ø> (ø)` | | | [src/constants/tests.ts](https://app.codecov.io/gh/VolkovLabs/volkovlabs-dynamictext-panel/pull/179?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VolkovLabs#diff-c3JjL2NvbnN0YW50cy90ZXN0cy50cw==) | `100.00% <ø> (ø)` | | | [src/types/panel.ts](https://app.codecov.io/gh/VolkovLabs/volkovlabs-dynamictext-panel/pull/179?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VolkovLabs#diff-c3JjL3R5cGVzL3BhbmVsLnRz) | `100.00% <ø> (ø)` | | | [src/helpers/html.ts](https://app.codecov.io/gh/VolkovLabs/volkovlabs-dynamictext-panel/pull/179?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VolkovLabs#diff-c3JjL2hlbHBlcnMvaHRtbC50cw==) | `78.26% <80.00%> (+13.04%)` | :arrow_up: | | [src/components/Text/Text.tsx](https://app.codecov.io/gh/VolkovLabs/volkovlabs-dynamictext-panel/pull/179?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VolkovLabs#diff-c3JjL2NvbXBvbmVudHMvVGV4dC9UZXh0LnRzeA==) | `97.72% <97.22%> (+1.89%)` | :arrow_up: | | [src/components/TextPanel/TextPanel.tsx](https://app.codecov.io/gh/VolkovLabs/volkovlabs-dynamictext-panel/pull/179?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=VolkovLabs#diff-c3JjL2NvbXBvbmVudHMvVGV4dFBhbmVsL1RleHRQYW5lbC50c3g=) | `81.25% <100.00%> (ø)` | |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

asimonok commented 1 year ago

Example of using EventBus subscriptions with unsubscribe.

The problem: To prevent memory leaks, subscriptions must be canceled before create new ones or when component is unmounted.

The solution: Returned function will be called on component update/unmount

const subscription = eventBus.subscribe({type: 'data-hover'}, () => {
  console.log('hello')
})

return () => {
  subscription.unsubscribe();
}