Skip to content

Commit

Permalink
first working proto
Browse files Browse the repository at this point in the history
  • Loading branch information
Karen committed May 15, 2017
1 parent 512a173 commit 1d8a78a
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 42 deletions.
1 change: 1 addition & 0 deletions classes/Step.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class Step {
this.template = params.template || ''
this.from = null
this._data = {}
params.interceptors = params.interceptors || {}
this.interceptors = {
beforeRender: params.interceptors.beforeRender || this.methods.beforeRender || function () {
return {status: true}
Expand Down
25 changes: 14 additions & 11 deletions classes/StepSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class StepSystem {
*/
addStep (step) {
step.parent = this
this._steps.push(step)
this._steps[step.name] = step
return this
}

Expand All @@ -34,7 +34,7 @@ export class StepSystem {
}

get current_step () {
return this.steps[this._current_step] || null
return this.step(this._current_step) || null
}

step (name) {
Expand All @@ -55,42 +55,45 @@ export class StepSystem {
if (_br.onError) _br.onError()
return this
}
this.container.html(step.template)
this.container.find('.step').html(step.template || this._container.find(`#${step.name}`).html())
}

goNext () {
let _bn = step.interceptors.beforeNext()
let curr_step = this.current_step || {}
let next_step = curr_step.next || null
let _bn = curr_step.interceptors.beforeNext()
if (!_bn.status) {
if (_bn.onError) _bn.onError()
return this
}
let curr_step = this.current_step || {}
let next_step = curr_step.next || null
if (next_step) {
this.goToStep(this.step(next_step))
}
}

goBack () {
let _bb = step.interceptors.beforeBack()
let curr_step = this.current_step || {}
let prev_step = curr_step.from || null
let _bb = curr_step.interceptors.beforeBack()
if (!_bb.status) {
if (_bb.onError) _bb.onError()
return this
}
let curr_step = this.current_step || {}
let prev_step = curr_step.from || null
if (prev_step) {
this.goToStep(this.step(prev_step))
}
}

goToStep (step) {
goToStep (step, from = null) {
let curr_step = this.current_step || {}
step.from = curr_step.name || null
this._current_step = step.name
this.render(step)
}

init () {
init (from_step) {
this.commonHandlers()
this._current_step = from_step
this.render(this.step(this._current_step))
}
}
48 changes: 44 additions & 4 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,48 @@
import { Step } from '../classes/Step'
import { StepSystem } from '../classes/StepSystem'

window.app = new StepSystem();
window.app = new StepSystem($('.container'));

(function ($, app) {
console.log(app)
})(jQuery, window.app)
(function (app) {

const first_step = 'first-step'

app
/**
* FIRST STEP
*/
.addStep(new Step({
name: 'first-step',
next: 'second-step',
methods: {
beforeRender: () => {
console.log('first-step beforeRender')
return { status: true }
},
beforeNext: () => {
console.log('first-step beforeNext')
return { status: true }
}
}
}))

/**
* SECOND STEP
*/
.addStep(new Step({
name: 'second-step',
methods: {
beforeRender: () => {
console.log('second-step beforeRender')
return { status: true }
},
beforeNext: () => {
console.log('second-step beforeNext')
return { status: true }
}
}
}))

app.init(first_step)

})(window.app)
97 changes: 71 additions & 26 deletions example/dist/app.js

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

Loading

0 comments on commit 1d8a78a

Please sign in to comment.