@frui.ts/screens
Advanced tools
Comparing version 0.17.0 to 0.17.1
@@ -1,9 +0,9 @@ | ||
import { IBusyWatcher } from "./types"; | ||
import { BusyWatcherKey, IBusyWatcher } from "./types"; | ||
export default class BusyWatcher implements IBusyWatcher { | ||
private counter; | ||
private busyItems; | ||
get isBusy(): boolean; | ||
getBusyTicket(): () => void; | ||
checkBusy(key: BusyWatcherKey): boolean; | ||
getBusyTicket(key?: BusyWatcherKey): (() => boolean) & import("mobx").IAction; | ||
watch<T>(watchedAction: Promise<T>): Promise<T>; | ||
private decrement; | ||
} | ||
export declare function watchBusy(target: any, propertyKey: string, descriptor: PropertyDescriptor): void; |
@@ -15,7 +15,7 @@ "use strict"; | ||
function BusyWatcher() { | ||
this.counter = 0; | ||
this.busyItems = new mobx_1.ObservableSet(); | ||
} | ||
Object.defineProperty(BusyWatcher.prototype, "isBusy", { | ||
get: function () { | ||
return this.counter > 0; | ||
return this.busyItems.size > 0; | ||
}, | ||
@@ -25,26 +25,17 @@ enumerable: true, | ||
}); | ||
BusyWatcher.prototype.getBusyTicket = function () { | ||
BusyWatcher.prototype.checkBusy = function (key) { | ||
return this.busyItems.has(key); | ||
}; | ||
BusyWatcher.prototype.getBusyTicket = function (key) { | ||
var _this = this; | ||
this.counter++; | ||
var wasUsed = false; | ||
return function () { | ||
if (!wasUsed) { | ||
wasUsed = true; | ||
_this.decrement(); | ||
} | ||
}; | ||
if (key === void 0) { key = Symbol(); } | ||
this.busyItems.add(key); | ||
return mobx_1.action(function () { return _this.busyItems.delete(key); }); | ||
}; | ||
BusyWatcher.prototype.watch = function (watchedAction) { | ||
this.counter++; | ||
watchedAction.then(this.decrement, this.decrement); | ||
var ticket = this.getBusyTicket(); | ||
watchedAction.then(ticket, ticket); | ||
return watchedAction; | ||
}; | ||
BusyWatcher.prototype.decrement = function () { | ||
this.counter--; | ||
}; | ||
__decorate([ | ||
mobx_1.observable, | ||
__metadata("design:type", Object) | ||
], BusyWatcher.prototype, "counter", void 0); | ||
__decorate([ | ||
mobx_1.computed, | ||
@@ -57,17 +48,5 @@ __metadata("design:type", Object), | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:paramtypes", [Object]), | ||
__metadata("design:returntype", void 0) | ||
], BusyWatcher.prototype, "getBusyTicket", null); | ||
__decorate([ | ||
mobx_1.action.bound, | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", [Promise]), | ||
__metadata("design:returntype", void 0) | ||
], BusyWatcher.prototype, "watch", null); | ||
__decorate([ | ||
mobx_1.action.bound, | ||
__metadata("design:type", Function), | ||
__metadata("design:paramtypes", []), | ||
__metadata("design:returntype", void 0) | ||
], BusyWatcher.prototype, "decrement", null); | ||
return BusyWatcher; | ||
@@ -83,8 +62,15 @@ }()); | ||
} | ||
var _a; | ||
var ticket = (_a = this.busyWatcher) === null || _a === void 0 ? void 0 : _a.getBusyTicket(); | ||
var result = originalFunction.apply(this, args); | ||
if (result && result.then && typeof result.then === "function") { | ||
result.then(undefined, function (error) { return console.error(error); }); | ||
if (this.busyWatcher && typeof this.busyWatcher.watch === "function") { | ||
this.busyWatcher.watch(result); | ||
if (ticket) { | ||
if (isPromise(result)) { | ||
result.then(ticket, function (error) { | ||
console.error(error); | ||
ticket(); | ||
}); | ||
} | ||
else { | ||
ticket(); | ||
} | ||
} | ||
@@ -95,2 +81,5 @@ return result; | ||
exports.watchBusy = watchBusy; | ||
function isPromise(value) { | ||
return typeof (value === null || value === void 0 ? void 0 : value.then) === "function"; | ||
} | ||
//# sourceMappingURL=busyWatcher.js.map |
@@ -23,4 +23,6 @@ export interface IActivatable { | ||
} | ||
export declare type BusyWatcherKey = string | symbol; | ||
export interface IBusyWatcher { | ||
readonly isBusy: boolean; | ||
checkBusy(key: BusyWatcherKey): boolean; | ||
} |
@@ -6,3 +6,3 @@ { | ||
}, | ||
"version": "0.17.0", | ||
"version": "0.17.1", | ||
"description": "Frui.ts core classes for application structure and navigation", | ||
@@ -38,3 +38,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@frui.ts/helpers": "^0.17.0", | ||
"@frui.ts/helpers": "^0.17.1", | ||
"query-string": "^6.9.0", | ||
@@ -49,3 +49,3 @@ "route-parser": "^0.0.5" | ||
}, | ||
"gitHead": "6aa967ac587f48ee3958b21a119e701fea28c24a" | ||
"gitHead": "f412ca8001ffdd03434200eab53375128ed07c9a" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
190832
2257
Updated@frui.ts/helpers@^0.17.1