Skip to content

Commit

Permalink
Core - Clenup some other unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
smastrom committed Jan 27, 2024
1 parent c7c062f commit f15f857
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
4 changes: 1 addition & 3 deletions packages/notivue/Notivue/composables/useRepositioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { useWindowSize } from './useWindowSize'
import { useResizeListObserver } from './useResizeListObserver'
import { useStore } from '@/core/useStore'

import { TransitionType as TType } from '@/core/constants'

export function useRepositioning() {
const { elements, animations } = useStore()

useWindowSize(() => animations.updatePositions(TType.IMMEDIATE))
useWindowSize(() => animations.updatePositions({ isImmediate: true }))

useResizeListObserver(elements.items.value, () => animations.updatePositions())
}
5 changes: 0 additions & 5 deletions packages/notivue/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ export const NotificationTypeKeys: Record<string, NTypeU> = {
PROMISE_REJECT: 'promise-reject',
}

export enum TransitionType {
PUSH,
IMMEDIATE,
}

const success: NotificationOptions = {
title: '',
message: '',
Expand Down
14 changes: 7 additions & 7 deletions packages/notivue/core/createStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from './utils'
import { getSlotItem } from '@/Notivue/utils'

import { DEFAULT_CONFIG, NotificationTypeKeys as NKeys, TransitionType as TType } from './constants'
import { DEFAULT_CONFIG, NotificationTypeKeys as NKeys } from './constants'

import type {
DeepPartial,
Expand Down Expand Up @@ -59,7 +59,7 @@ export function createQueue() {
this.triggerRef()
},
get(id: string) {
return this.entries.value.find(({ id: _id }) => id === _id)
return this.entries.value.find((e) => e.id === id)
},
update(id: string, newOptions: DeepPartial<StoreItem>) {
Object.assign(this.get(id) ?? {}, newOptions)
Expand All @@ -68,7 +68,7 @@ export function createQueue() {
triggerRef(this.entries)
},
remove(id: string) {
this.entries.value = this.entries.value.filter(({ id: _id }) => id !== _id)
this.entries.value = this.entries.value.filter((e) => e.id !== id)
},
clear() {
this.entries.value = []
Expand Down Expand Up @@ -97,7 +97,7 @@ export function createItems(config: ConfigSlice, queue: QueueSlice) {
this.add(next)
},
get(id: string) {
return this.entries.value.find(({ id: _id }) => id === _id)
return this.entries.value.find((e) => e.id === id)
},
update(id: string, newOptions: DeepPartial<StoreItem>) {
Object.assign(this.get(id) ?? {}, newOptions)
Expand All @@ -109,7 +109,7 @@ export function createItems(config: ConfigSlice, queue: QueueSlice) {
this.entries.value = this.entries.value.map(updateItem)
},
remove(id: string) {
this.entries.value = this.entries.value.filter(({ id: _id }) => id !== _id)
this.entries.value = this.entries.value.filter((e) => e.id !== id)

const shouldDequeue = queue.length > 0 && this.length < config.limit.value
if (shouldDequeue) {
Expand Down Expand Up @@ -211,8 +211,8 @@ export function createAnimations(config: ConfigSlice, items: ItemsSlice, element
onAnimationend: () => items.clear(),
})
},
updatePositions(type = TType.PUSH) {
const isReduced = this.isReducedMotion.value || type === TType.IMMEDIATE
updatePositions({ isImmediate = false } = {}) {
const isReduced = this.isReducedMotion.value || isImmediate
const leaveClass = config.animations.value.leave

let accPrevHeights = 0
Expand Down
5 changes: 2 additions & 3 deletions packages/notivue/core/createWatchers.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { watch } from 'vue'
import { TransitionType as TType } from './constants'

import type { NotivueStore } from 'notivue'

export function createWatchers(store: NotivueStore) {
watch(
store.config.isTopAlign,
() => {
store.animations.updatePositions(TType.IMMEDIATE)
store.animations.updatePositions({ isImmediate: true })
},
{ flush: 'post' }
)

watch(
() => store.items.length,
() => {
store.animations.updatePositions(TType.PUSH)
store.animations.updatePositions()
},
{ flush: 'post' }
)
Expand Down

0 comments on commit f15f857

Please sign in to comment.