Skip to content

Commit 82ea932

Browse files
author
abusedmedia
committed
fixed minor issue on router and arrow controller
1 parent facc313 commit 82ea932

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/controllers/arrows/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,20 @@ const arrows = function (rootElement, router, ctrlConfig, projectConfig) {
4141
}
4242
}
4343

44-
router.on('indexChanged', e => {
44+
const changed = e => {
4545
setMouseMove()
4646
left.style.visibility = 'visible'
4747
right.style.visibility = 'visible'
4848
if (e.isFirst) left.style.visibility = 'hidden'
4949
if (e.isLast && e.totalSteps === e.currentStep) right.style.visibility = 'hidden'
50+
}
51+
52+
router.on('stepChanged', e => {
53+
changed(e)
54+
})
55+
56+
router.on('indexChanged', e => {
57+
changed(e)
5058
})
5159

5260
const scheduleForHide = () => {

src/core/Router.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ const Router = function (rootElement, projectConfig) {
1313

1414
let currentIndex = 0
1515
let currentStep = 0
16-
let numSteps = 0
16+
// let numSteps = 0
1717

18-
const setNumSteps = () => {
19-
numSteps = scenes[currentIndex] &&
18+
const numSteps = () => {
19+
return scenes[currentIndex] &&
2020
scenes[currentIndex]._steps
2121
? scenes[currentIndex]._steps.length
2222
: 0
2323
}
24-
// setNumSteps()
2524

2625
const updateRouterWrapper = () => {
2726
const sceneConfig = scenes[currentIndex]
@@ -33,7 +32,7 @@ const Router = function (rootElement, projectConfig) {
3332
}
3433

3534
this.next = () => {
36-
if (currentStep === numSteps) {
35+
if (currentStep === numSteps()) {
3736
this.nextIndex()
3837
} else {
3938
currentStep++
@@ -53,10 +52,10 @@ const Router = function (rootElement, projectConfig) {
5352
notify(['nextIndex', 'indexChanged'])
5453
} else {
5554
currentIndex = numScenes()
56-
currentStep = numSteps
55+
currentStep = numSteps()
5756
notify('end')
5857
}
59-
setNumSteps()
58+
// setNumSteps()
6059
}
6160
this.prevIndex = () => {
6261
if (currentIndex > 0) {
@@ -68,7 +67,7 @@ const Router = function (rootElement, projectConfig) {
6867
currentStep = 0
6968
notify('begin')
7069
}
71-
setNumSteps()
70+
// setNumSteps()
7271
}
7372

7473
this.goto = v => {
@@ -90,7 +89,7 @@ const Router = function (rootElement, projectConfig) {
9089
currentIndex,
9190
currentStep,
9291
totalScenes: this.totalScenes(),
93-
totalSteps: numSteps,
92+
totalSteps: numSteps(),
9493
isFirst: this.isFirst(),
9594
isLast: this.isLast()
9695
})
@@ -120,7 +119,7 @@ const Router = function (rootElement, projectConfig) {
120119
}
121120

122121
this.totalScenes = () => numScenes() + 1
123-
this.totalSteps = () => numSteps
122+
this.totalSteps = () => numSteps()
124123
this.currentIndex = () => currentIndex
125124
this.currentStep = () => currentStep
126125
this.isFirst = () => currentIndex === 0
@@ -145,7 +144,7 @@ const Router = function (rootElement, projectConfig) {
145144

146145
setTimeout(() => {
147146
notify('init')
148-
setNumSteps()
147+
// setNumSteps()
149148
})
150149
}
151150

0 commit comments

Comments
 (0)