Skip to content

Commit fd453b3

Browse files
Merge pull request #145 from vue-pivottable/ts-composables
Ts composables
2 parents 84fa7f7 + 0ab12b0 commit fd453b3

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11
import { reactive } from 'vue'
22

3+
type PivotUiState = {
4+
unusedOrder: string[]
5+
zIndices: Record<string, number>
6+
maxZIndex: number
7+
openStatus: Record<string, boolean>
8+
}
9+
310
export function usePivotUiState() {
4-
const pivotUiState = reactive({
11+
const pivotUiState = reactive<PivotUiState>({
512
unusedOrder: [],
613
zIndices: {},
714
maxZIndex: 1000,
815
openStatus: {}
916
})
1017

11-
const onMoveFilterBoxToTop = (attributeName) => {
18+
const onMoveFilterBoxToTop = (attributeName: string) => {
1219
pivotUiState.maxZIndex++
1320
pivotUiState.zIndices[attributeName] = pivotUiState.maxZIndex
1421
}
1522

16-
const onUpdateOpenStatus = ({ key, value }) => {
23+
const onUpdateOpenStatus = ({
24+
key,
25+
value
26+
}: {
27+
key: string
28+
value: boolean
29+
}) => {
1730
pivotUiState.openStatus[key] = value
1831
}
1932

20-
const onUpdateUnusedOrder = (newOrder) => {
33+
const onUpdateUnusedOrder = (newOrder: string[]) => {
2134
pivotUiState.unusedOrder = newOrder
2235
}
2336

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ import { computed, inject, provide } from 'vue'
22
import { getSort } from '../helper/utilities'
33
const filterBoxKey = Symbol('filterBox')
44

5-
export function provideFilterBox(props) {
5+
interface ProvideFilterBoxProps {
6+
languagePack: Record<string, any>
7+
locale: string
8+
sorters: Record<string, any>
9+
menuLimit: number
10+
[key: string]: any
11+
}
12+
13+
export function provideFilterBox(props: ProvideFilterBoxProps) {
614
const localeStrings = computed(
715
() => props.languagePack[props.locale].localeStrings
816
)
917
const sorters = computed(() => props.sorters)
10-
const sorter = (x) => getSort(sorters.value, x)
18+
const sorter = (x: string) => getSort(sorters.value, x)
1119
const menuLimit = computed(() => props.menuLimit)
1220
provide(filterBoxKey, {
1321
localeStrings,

0 commit comments

Comments
 (0)