Skip to content

Commit b7bd0ab

Browse files
Merge pull request #140 from vue-pivottable/feature/useMaterializeInput-ts
feat(composables): useMaterializeInput TypeScript 마이그레이션
2 parents a4a6bf3 + 49a5905 commit b7bd0ab

File tree

3 files changed

+25
-219
lines changed

3 files changed

+25
-219
lines changed

src/composables/useMaterializeInput.js renamed to src/composables/useMaterializeInput.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
1-
import { ref, watch } from 'vue'
2-
import { PivotData } from '@/helper/utilities.js'
1+
import { Ref, ref, watch } from 'vue'
2+
import { PivotData } from '@/helper/utilities'
33

4-
export function useMaterializeInput(dataSource, options) {
5-
const rawData = ref(null)
6-
const allFilters = ref({})
7-
const materializedInput = ref([])
4+
export interface UseMaterializeInputOptions {
5+
derivedAttributes: Ref<Record<string, (record: Record<string, any>) => any>>
6+
}
7+
8+
export interface UseMaterializeInputReturn {
9+
rawData: Ref<any>
10+
allFilters: Ref<Record<string, Record<string, number>>>
11+
materializedInput: Ref<any[]>
12+
processData: (data: any) => { AllFilters: Record<string, Record<string, number>>; materializedInput: any[] } | void
13+
}
814

9-
function processData(data) {
15+
export function useMaterializeInput (
16+
dataSource: Ref<any>,
17+
options: UseMaterializeInputOptions
18+
): UseMaterializeInputReturn {
19+
const rawData = ref<any>(null)
20+
const allFilters = ref<Record<string, Record<string, number>>>({})
21+
const materializedInput = ref<any[]>([])
22+
23+
function processData (data: any) {
1024
if (!data || rawData.value === data) return
1125

1226
rawData.value = data
13-
const newAllFilters = {}
14-
const newMaterializedInput = []
27+
const newAllFilters: Record<string, Record<string, number>> = {}
28+
const newMaterializedInput: any[] = []
1529

1630
let recordsProcessed = 0
1731

1832
PivotData.forEachRecord(
1933
data,
2034
options.derivedAttributes.value,
21-
function (record) {
35+
function (record: Record<string, any>) {
2236
newMaterializedInput.push(record)
2337

2438
for (const attr of Object.keys(record)) {
@@ -66,4 +80,4 @@ export function useMaterializeInput(dataSource, options) {
6680
materializedInput,
6781
processData
6882
}
69-
}
83+
}

src/composables/usePropsState.js

Lines changed: 0 additions & 72 deletions
This file was deleted.

src/composables/useProvidePivotData.js

Lines changed: 0 additions & 136 deletions
This file was deleted.

0 commit comments

Comments
 (0)