Skip to content

Commit

Permalink
[#2004] Remove redundant Segment class (#2085)
Browse files Browse the repository at this point in the history
Remove Segment class, replace with AuthorshipFileSegment

The Segment class and AuthorshipFileSegment interface are equivalent in
their usage and their redundancy seems to be a remnant when the code
was migrated from JS to TS.

Let's remove the Segment class for consistency and to improve runtime
performance.
  • Loading branch information
jonasongg authored Jan 26, 2024
1 parent 3cd680c commit eb7a944
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 26 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/c-segment-collection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script lang='ts'>
import { defineComponent } from 'vue';
import cSegment from './c-segment.vue';
import Segment from '../utils/segment';
import { AuthorshipFileSegment } from '../types/types';
export default defineComponent({
name: 'c-segment-collection',
Expand All @@ -16,7 +16,7 @@ export default defineComponent({
},
props: {
segments: {
type: Array<Segment>,
type: Array<AuthorshipFileSegment>,
required: true,
},
path: {
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/c-segment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
</template>

<script lang='ts'>
import { defineComponent } from 'vue';
import { defineComponent, PropType } from 'vue';
import { mapState } from 'vuex';
import Segment from '../utils/segment';
import { StoreState } from '../types/vuex.d';
import { AuthorshipFileSegment } from '../types/types';
export default defineComponent({
name: 'c-segment',
props: {
segment: {
type: Segment,
type: Object as PropType<AuthorshipFileSegment>,
required: true,
},
path: {
Expand Down
13 changes: 0 additions & 13 deletions frontend/src/utils/segment.ts

This file was deleted.

15 changes: 7 additions & 8 deletions frontend/src/views/c-authorship.vue
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,10 @@ import minimatch from 'minimatch';
import brokenLinkDisabler from '../mixin/brokenLinkMixin';
import tooltipPositioner from '../mixin/dynamicTooltipMixin';
import cSegmentCollection from '../components/c-segment-collection.vue';
import Segment from '../utils/segment';
import getNonRepeatingColor from '../utils/random-color-generator';
import { StoreState } from '../types/vuex.d';
import { FileResult, Line } from '../types/zod/authorship-type';
import { AuthorshipFile } from '../types/types';
import { AuthorshipFile, AuthorshipFileSegment } from '../types/types';
import { FilesSortType, FilterType } from '../types/authorship';
const filesSortDict = {
Expand Down Expand Up @@ -518,11 +517,11 @@ export default defineComponent({
return name === '-';
},
splitSegments(lines: Line[]): { segments: Segment[]; blankLineCount: number; } {
splitSegments(lines: Line[]): { segments: AuthorshipFileSegment[]; blankLineCount: number; } {
// split into segments separated by knownAuthor
let lastState: string | null;
let lastId = -1;
const segments: Segment[] = [];
const segments: AuthorshipFileSegment[] = [];
let blankLineCount = 0;
lines.forEach((line, lineCount) => {
Expand All @@ -532,11 +531,11 @@ export default defineComponent({
const knownAuthor = (line.author && isAuthorMatched) ? line.author.gitId : null;
if (knownAuthor !== lastState || lastId === -1) {
segments.push(new Segment(
segments.push({
knownAuthor,
[],
[],
));
lineNumbers: [],
lines: [],
});
lastId += 1;
lastState = knownAuthor;
Expand Down

0 comments on commit eb7a944

Please sign in to comment.