Skip to content

Commit 3bb4922

Browse files
committed
fix: returning promises from next() and jumpToStep()
1 parent 8cb01d1 commit 3bb4922

File tree

2 files changed

+99
-122
lines changed

2 files changed

+99
-122
lines changed

dist/main.js

Lines changed: 52 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ Object.defineProperty(exports, "__esModule", {
44
value: true
55
});
66

7-
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
8-
97
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
108

119
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -176,72 +174,66 @@ var StepZilla = function (_Component) {
176174
// a child step wants to invoke a jump between steps. in this case 'evt' is the numeric step number and not the JS event
177175
this.setNavState(evt);
178176
} else {
179-
var _ret = function () {
180-
// the main navigation step ui is invoking a jump between steps
181-
if (!_this3.props.stepsNavigation || evt.target.value === _this3.state.compState) {
182-
// if stepsNavigation is turned off or user clicked on existing step again (on step 2 and clicked on 2 again) then ignore
183-
evt.preventDefault();
184-
evt.stopPropagation();
185-
186-
return {
187-
v: void 0
188-
};
189-
}
177+
// the main navigation step ui is invoking a jump between steps
178+
if (!this.props.stepsNavigation || evt.target.value === this.state.compState) {
179+
// if stepsNavigation is turned off or user clicked on existing step again (on step 2 and clicked on 2 again) then ignore
180+
evt.preventDefault();
181+
evt.stopPropagation();
190182

191-
evt.persist(); // evt is a react event so we need to persist it as we deal with aync promises which nullifies these events (https://facebook.github.io/react/docs/events.html#event-pooling)
183+
return;
184+
}
192185

193-
var movingBack = evt.target.value < _this3.state.compState; // are we trying to move back or front?
194-
var passThroughStepsNotValid = false; // if we are jumping forward, only allow that if inbetween steps are all validated. This flag informs the logic...
195-
var proceed = false; // flag on if we should move on
186+
evt.persist(); // evt is a react event so we need to persist it as we deal with aync promises which nullifies these events (https://facebook.github.io/react/docs/events.html#event-pooling)
196187

197-
_this3.abstractStepMoveAllowedToPromise(movingBack).then(function () {
198-
var valid = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
199-
// validation was a success (promise or sync validation). In it was a Promise's resolve() then proceed will be undefined, so make it true. Or else 'proceed' will carry the true/false value from sync v
200-
proceed = valid;
188+
var movingBack = evt.target.value < this.state.compState; // are we trying to move back or front?
189+
var passThroughStepsNotValid = false; // if we are jumping forward, only allow that if inbetween steps are all validated. This flag informs the logic...
190+
var proceed = false; // flag on if we should move on
201191

202-
if (!movingBack) {
203-
_this3.updateStepValidationFlag(proceed);
204-
}
192+
this.abstractStepMoveAllowedToPromise(movingBack).then(function () {
193+
var valid = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
194+
// validation was a success (promise or sync validation). In it was a Promise's resolve() then proceed will be undefined, so make it true. Or else 'proceed' will carry the true/false value from sync v
195+
proceed = valid;
205196

206-
if (proceed) {
207-
if (!movingBack) {
208-
// looks like we are moving forward, 'reduce' a new array of step>validated values we need to check and 'some' that to get a decision on if we should allow moving forward
209-
passThroughStepsNotValid = _this3.props.steps.reduce(function (a, c, i) {
210-
if (i >= _this3.state.compState && i < evt.target.value) {
211-
a.push(c.validated);
212-
}
213-
return a;
214-
}, []).some(function (c) {
215-
return c === false;
216-
});
217-
}
218-
}
219-
}).catch(function (e) {
220-
// Promise based validation was a fail (i.e reject())
197+
if (!movingBack) {
198+
_this3.updateStepValidationFlag(proceed);
199+
}
200+
201+
if (proceed) {
221202
if (!movingBack) {
222-
_this3.updateStepValidationFlag(false);
223-
}
224-
}).then(function () {
225-
// this is like finally(), executes if error no no error
226-
if (proceed && !passThroughStepsNotValid) {
227-
if (evt.target.value === _this3.props.steps.length - 1 && _this3.state.compState === _this3.props.steps.length - 1) {
228-
_this3.setNavState(_this3.props.steps.length);
229-
} else {
230-
_this3.setNavState(evt.target.value);
231-
}
232-
}
233-
}).catch(function (e) {
234-
if (e) {
235-
// see note below called "CatchRethrowing"
236-
// ... plus the finally then() above is what throws the JS Error so we need to catch that here specifically
237-
setTimeout(function () {
238-
throw e;
203+
// looks like we are moving forward, 'reduce' a new array of step>validated values we need to check and 'some' that to get a decision on if we should allow moving forward
204+
passThroughStepsNotValid = _this3.props.steps.reduce(function (a, c, i) {
205+
if (i >= _this3.state.compState && i < evt.target.value) {
206+
a.push(c.validated);
207+
}
208+
return a;
209+
}, []).some(function (c) {
210+
return c === false;
239211
});
240212
}
241-
});
242-
}();
243-
244-
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
213+
}
214+
}).catch(function (e) {
215+
// Promise based validation was a fail (i.e reject())
216+
if (!movingBack) {
217+
_this3.updateStepValidationFlag(false);
218+
}
219+
}).then(function () {
220+
// this is like finally(), executes if error no no error
221+
if (proceed && !passThroughStepsNotValid) {
222+
if (evt.target.value === _this3.props.steps.length - 1 && _this3.state.compState === _this3.props.steps.length - 1) {
223+
_this3.setNavState(_this3.props.steps.length);
224+
} else {
225+
_this3.setNavState(evt.target.value);
226+
}
227+
}
228+
}).catch(function (e) {
229+
if (e) {
230+
// see note below called "CatchRethrowing"
231+
// ... plus the finally then() above is what throws the JS Error so we need to catch that here specifically
232+
setTimeout(function () {
233+
throw e;
234+
});
235+
}
236+
});
245237
}
246238
}
247239

0 commit comments

Comments
 (0)