Skip to content

Commit

Permalink
Merge pull request #3 from VeryWow/dev
Browse files Browse the repository at this point in the history
isSkip method in the step
  • Loading branch information
kaskar2008 authored May 26, 2017
2 parents 50a84aa + 9040e53 commit f74f3c7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
3 changes: 3 additions & 0 deletions classes/Step.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export class Step {
this._data = params.data || {}
params.interceptors = params.interceptors || {}
this.interceptors = {
isSkip: params.interceptors.isSkip || this.methods.isSkip || function () {
return false
},
beforeRender: params.interceptors.beforeRender || this.methods.beforeRender || function () {
return {status: true}
},
Expand Down
21 changes: 12 additions & 9 deletions classes/StepSystem.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* StepSystem v1.0.0
* Last update: 19.05.2017
* StepSystem v1.0.1
* Last update: 25.05.2017
*
* Dependencies: jQuery
*
Expand Down Expand Up @@ -89,12 +89,6 @@ export class StepSystem {
this.onProgress(this.progress)
}

finish () {
if (this.onFinish) {
this.onFinish()
}
}

goNextTimeout (timeout = 300) {
const $this = this
clearTimeout(this._next_timeout)
Expand All @@ -114,8 +108,11 @@ export class StepSystem {
if (next_step) {
this.goToStep(this.step(next_step), { from: curr_step.name })
} else {
this.finish()
if (this.onFinish) {
this.onFinish()
}
}
return this
}

goBack () {
Expand All @@ -132,9 +129,14 @@ export class StepSystem {
}
this.goToStep(this.step(prev_step), { is_back: true })
}
return this
}

goToStep (step, params = {}) {
let is_skip = step.interceptors.isSkip(step)
if (is_skip) {
step = this.step(step.next)
}
let from = params.from || null
let is_back = params.is_back || false
if (from) {
Expand All @@ -146,6 +148,7 @@ export class StepSystem {
this.steps_past.push(step.name)
}
this.updateProgress()
return this
}

collectData () {
Expand Down
3 changes: 3 additions & 0 deletions example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ window.app = new StepSystem({
name: 'second-step',
next: 'third-step',
methods: {
isSkip: (step) => {
return app.step('first-step').data.lol == 'lol'
},
beforeRender: (step) => {
console.log('second-step beforeRender')
return { status: true }
Expand Down
28 changes: 18 additions & 10 deletions example/dist/app.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/dist/app.js.map

Large diffs are not rendered by default.

0 comments on commit f74f3c7

Please sign in to comment.