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

[#1936] Migrate c-resizer.vue to typescript #2038

Merged
merged 6 commits into from
Oct 4, 2023
Merged
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
20 changes: 13 additions & 7 deletions frontend/src/components/c-resizer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,30 @@
slot(name="right")
</template>

<script>
<script lang='ts'>
import { mapState } from 'vuex';
import { defineComponent } from 'vue';

const DRAG_BAR_WIDTH = 13.25;
const SCROLL_BAR_WIDTH = 17;
const GUIDE_BAR_WIDTH = 2;

const throttledEvent = (delay, handler) => {
/** The following eslint suppression suppresses a rare false positive case where event cannot be accessed due to
* handler being a lambda function parameter. The explicit lambda function here allows us to easily discern handler's
* parameters, i.e. an event of type MouseEvent.
*/
// eslint-disable-next-line no-unused-vars
const throttledEvent = (delay: number, handler: (event: MouseEvent) => unknown) => {
let lastCalled = 0;
return (...args) => {
return (event: MouseEvent) => {
if (Date.now() - lastCalled > delay) {
lastCalled = Date.now();
handler(...args);
handler(event);
}
};
};

export default {
export default defineComponent({
name: 'c-resizer',

data() {
Expand Down Expand Up @@ -68,7 +74,7 @@ export default {

mouseMove() {
if (this.isResizing) {
return throttledEvent(25, (event) => {
return throttledEvent(25, (event: MouseEvent) => {
this.guideWidth = (
Math.min(
Math.max(
Expand Down Expand Up @@ -102,5 +108,5 @@ export default {
this.$store.commit('updateTabState', false);
},
},
};
});
</script>
Loading