vuetify
Version:
Vue.js 2 Semantic Component Framework
41 lines (36 loc) • 1.06 kB
text/typescript
export type TargetProp = 'bar' | 'bottom' | 'footer' | 'insetFooter' | 'left' | 'right' | 'top'
interface TargetPropValues {
[uid: number]: number
}
export default {
bar: 0,
bottom: 0,
footer: 0,
insetFooter: 0,
left: 0,
right: 0,
top: 0,
components: {
bar: {} as TargetPropValues,
bottom: {} as TargetPropValues,
footer: {} as TargetPropValues,
insetFooter: {} as TargetPropValues,
left: {} as TargetPropValues,
right: {} as TargetPropValues,
top: {} as TargetPropValues
},
bind (uid: number, target: TargetProp, value: number): void {
if (!this.components[target]) return
this.components[target] = { [uid]: value }
this.update(target)
},
unbind (uid: number, target: TargetProp): void {
if (this.components[target][uid] == null) return
delete (this.components as any)[target][uid]
this.update(target)
},
update (target: TargetProp): void {
this[target] = Object.values(this.components[target])
.reduce((acc: number, cur: number): number => (acc + cur), 0)
}
}