react-antd-admin-panel
Version:
Easy prototyping admin panel using React and Antd
61 lines • 2.03 kB
JavaScript
export default class Cycle {
constructor(main, route, next, failed) {
this._states = {
get: [],
};
this._main = main;
this._next = next;
this._failed = failed;
let path = this._main.$map.$path(route);
this._key = path._actualPath;
this._path = path;
this._route = path._route;
}
$access(access) {
return this._main.$access(access, this);
}
handle() {
if (!this._route) {
console.log('Not a valid page.', this);
this._main.Controller.onCycleFailed(this);
}
if (this._main.Controller.isDebug()) {
this.get();
return;
}
let access = typeof this._route._access === 'function' ? this._route._access(this) : this._route._access;
access = this.$access(access);
if (!access.access) {
this._main.Controller.onCycleFailed(this);
}
else {
this.get();
}
}
get() {
if (this._route._gets.length === 0)
this._main.Controller.onCycleComplete(this);
this._route._gets.forEach(() => this._states.get.push(false));
this._route._gets.forEach((r, i) => {
r.onComplete(() => this.getCompleted(i));
r.onError(() => this.getFailed(i));
r.get(this);
});
}
getCompleted(i) {
// Calls nextPhase if current phase is completed.
this._states.get[i] = true;
if (this._states.get.every((r) => r === true))
this._main.Controller.onCycleComplete(this);
}
getFailed(i) {
// Calls nextPhase if current phase is completed.
this._states.get[i] = undefined;
if (this._states.get.every((r) => r === true || r === undefined))
this._main.Controller.onCycleFailed(this);
}
params(key) {
return this._path._params[key];
}
}
//# sourceMappingURL=Cycle.js.map