mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-21 13:39:30 -07:00
fix(nav.ts): fix circular dependency in desktop view
This commit is contained in:
@@ -57,10 +57,17 @@ for (const [index, link] of links.entries()) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export function initNav(): void {
|
export function initNav(): void {
|
||||||
|
const s = state.get()
|
||||||
// init threshold text
|
// init threshold text
|
||||||
updateThresholdText()
|
updateThresholdText(expand(s.threshold))
|
||||||
// init index text
|
// init index text
|
||||||
updateIndexText()
|
updateIndexText(expand(s.index + 1), expand(s.length))
|
||||||
|
// add watcher for updating nav text
|
||||||
|
state.addWatcher((o) => {
|
||||||
|
updateIndexText(expand(o.index + 1), expand(o.length))
|
||||||
|
updateThresholdText(expand(o.threshold))
|
||||||
|
})
|
||||||
|
|
||||||
// event listeners
|
// event listeners
|
||||||
decButton.addEventListener(
|
decButton.addEventListener(
|
||||||
'click',
|
'click',
|
||||||
@@ -80,16 +87,13 @@ export function initNav(): void {
|
|||||||
|
|
||||||
// helper
|
// helper
|
||||||
|
|
||||||
export function updateThresholdText(): void {
|
export function updateThresholdText(thresholdValue: string): void {
|
||||||
const thresholdValue: string = expand(state.get().threshold)
|
|
||||||
thresholdDispNums.forEach((e: HTMLSpanElement, i: number) => {
|
thresholdDispNums.forEach((e: HTMLSpanElement, i: number) => {
|
||||||
e.innerText = thresholdValue[i]
|
e.innerText = thresholdValue[i]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateIndexText(): void {
|
export function updateIndexText(indexValue: string, indexLength: string): void {
|
||||||
const indexValue: string = expand(state.get().index + 1)
|
|
||||||
const indexLength: string = expand(state.get().length)
|
|
||||||
indexDispNums.forEach((e: HTMLSpanElement, i: number) => {
|
indexDispNums.forEach((e: HTMLSpanElement, i: number) => {
|
||||||
if (i < 4) {
|
if (i < 4) {
|
||||||
e.innerText = indexValue[i]
|
e.innerText = indexValue[i]
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { updateIndexText, updateThresholdText } from './nav'
|
|
||||||
import { Watchable, decrement, increment } from './utils'
|
import { Watchable, decrement, increment } from './utils'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -36,10 +35,6 @@ export function initState(length: number): void {
|
|||||||
const s = state.get()
|
const s = state.get()
|
||||||
s.length = length
|
s.length = length
|
||||||
state.set(s)
|
state.set(s)
|
||||||
state.addWatcher(() => {
|
|
||||||
updateIndexText()
|
|
||||||
updateThresholdText()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setIndex(index: number): void {
|
export function setIndex(index: number): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user