mvvm-mobx 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,68 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return useValue ? value : void 0;
|
|
8
|
-
};
|
|
9
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
-
var _, done = false;
|
|
15
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
-
var context = {};
|
|
17
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
-
if (kind === "accessor") {
|
|
22
|
-
if (result === void 0) continue;
|
|
23
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
-
}
|
|
28
|
-
else if (_ = accept(result)) {
|
|
29
|
-
if (kind === "field") initializers.unshift(_);
|
|
30
|
-
else descriptor[key] = _;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
-
done = true;
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
35
7
|
};
|
|
36
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
9
|
exports.RelayCommand = void 0;
|
|
38
10
|
const mobx_1 = require("mobx");
|
|
39
11
|
const CounterFlag_1 = require("../core/CounterFlag");
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
await this.executeFunc(parameter);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
(() => {
|
|
61
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
62
|
-
_execute_decorators = [mobx_1.action];
|
|
63
|
-
__esDecorate(_a, null, _execute_decorators, { kind: "method", name: "execute", static: false, private: false, access: { has: obj => "execute" in obj, get: obj => obj.execute }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
64
|
-
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
65
|
-
})(),
|
|
66
|
-
_a;
|
|
67
|
-
})();
|
|
12
|
+
class RelayCommand {
|
|
13
|
+
constructor(executeFunc, canExecuteFunc) {
|
|
14
|
+
this.executeFunc = executeFunc;
|
|
15
|
+
this.canExecuteFunc = canExecuteFunc;
|
|
16
|
+
this.workingFlag = new CounterFlag_1.CounterFlag();
|
|
17
|
+
(0, mobx_1.makeObservable)(this);
|
|
18
|
+
}
|
|
19
|
+
canExecute(parameter) {
|
|
20
|
+
return this.canExecuteFunc?.(parameter) ?? true;
|
|
21
|
+
}
|
|
22
|
+
async execute(parameter) {
|
|
23
|
+
await this.workingFlag.using(async () => {
|
|
24
|
+
await this.executeFunc(parameter);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
68
28
|
exports.RelayCommand = RelayCommand;
|
|
29
|
+
__decorate([
|
|
30
|
+
mobx_1.action
|
|
31
|
+
], RelayCommand.prototype, "execute", null);
|
package/dist/core/CounterFlag.js
CHANGED
|
@@ -1,37 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return useValue ? value : void 0;
|
|
8
|
-
};
|
|
9
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
-
var _, done = false;
|
|
15
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
-
var context = {};
|
|
17
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
-
if (kind === "accessor") {
|
|
22
|
-
if (result === void 0) continue;
|
|
23
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
-
}
|
|
28
|
-
else if (_ = accept(result)) {
|
|
29
|
-
if (kind === "field") initializers.unshift(_);
|
|
30
|
-
else descriptor[key] = _;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
-
done = true;
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
35
7
|
};
|
|
36
8
|
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
37
9
|
if (value !== null && value !== void 0) {
|
|
@@ -88,65 +60,53 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
|
|
|
88
60
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
89
61
|
exports.CounterFlag = void 0;
|
|
90
62
|
const mobx_1 = require("mobx");
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
increment() {
|
|
129
|
-
this.counter++;
|
|
130
|
-
return {
|
|
131
|
-
[Symbol.dispose]: () => (0, mobx_1.runInAction)(() => this.counter--),
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
get isActive() {
|
|
135
|
-
return this.counter > 0;
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
(() => {
|
|
139
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
140
|
-
_counter_decorators = [mobx_1.observable];
|
|
141
|
-
_using_decorators = [mobx_1.action];
|
|
142
|
-
_increment_decorators = [mobx_1.action];
|
|
143
|
-
_get_isActive_decorators = [mobx_1.computed];
|
|
144
|
-
__esDecorate(_a, null, _using_decorators, { kind: "method", name: "using", static: false, private: false, access: { has: obj => "using" in obj, get: obj => obj.using }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
145
|
-
__esDecorate(_a, null, _increment_decorators, { kind: "method", name: "increment", static: false, private: false, access: { has: obj => "increment" in obj, get: obj => obj.increment }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
146
|
-
__esDecorate(_a, null, _get_isActive_decorators, { kind: "getter", name: "isActive", static: false, private: false, access: { has: obj => "isActive" in obj, get: obj => obj.isActive }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
147
|
-
__esDecorate(null, null, _counter_decorators, { kind: "field", name: "counter", static: false, private: false, access: { has: obj => "counter" in obj, get: obj => obj.counter, set: (obj, value) => { obj.counter = value; } }, metadata: _metadata }, _counter_initializers, _counter_extraInitializers);
|
|
148
|
-
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
149
|
-
})(),
|
|
150
|
-
_a;
|
|
151
|
-
})();
|
|
63
|
+
class CounterFlag {
|
|
64
|
+
constructor() {
|
|
65
|
+
this.counter = 0;
|
|
66
|
+
(0, mobx_1.makeObservable)(this);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Activates the flag while executing the provided function.
|
|
70
|
+
* @param fn The function to execute while the flag is active.
|
|
71
|
+
*/
|
|
72
|
+
async using(fn) {
|
|
73
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
74
|
+
try {
|
|
75
|
+
const _ = __addDisposableResource(env_1, this.increment(), false);
|
|
76
|
+
await fn();
|
|
77
|
+
}
|
|
78
|
+
catch (e_1) {
|
|
79
|
+
env_1.error = e_1;
|
|
80
|
+
env_1.hasError = true;
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
__disposeResources(env_1);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Increments the counter and returns a disposable object that decreases the counter when disposed.
|
|
88
|
+
* @returns A disposable object that decreases the counter when disposed.
|
|
89
|
+
*/
|
|
90
|
+
increment() {
|
|
91
|
+
this.counter++;
|
|
92
|
+
return {
|
|
93
|
+
[Symbol.dispose]: () => (0, mobx_1.runInAction)(() => this.counter--),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
get isActive() {
|
|
97
|
+
return this.counter > 0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
152
100
|
exports.CounterFlag = CounterFlag;
|
|
101
|
+
__decorate([
|
|
102
|
+
mobx_1.observable
|
|
103
|
+
], CounterFlag.prototype, "counter", void 0);
|
|
104
|
+
__decorate([
|
|
105
|
+
mobx_1.action
|
|
106
|
+
], CounterFlag.prototype, "using", null);
|
|
107
|
+
__decorate([
|
|
108
|
+
mobx_1.action
|
|
109
|
+
], CounterFlag.prototype, "increment", null);
|
|
110
|
+
__decorate([
|
|
111
|
+
mobx_1.computed
|
|
112
|
+
], CounterFlag.prototype, "isActive", null);
|
|
@@ -1,78 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return useValue ? value : void 0;
|
|
8
|
-
};
|
|
9
|
-
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
-
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
-
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
-
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
-
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
-
var _, done = false;
|
|
15
|
-
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
-
var context = {};
|
|
17
|
-
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
-
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
-
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
-
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
-
if (kind === "accessor") {
|
|
22
|
-
if (result === void 0) continue;
|
|
23
|
-
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
-
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
-
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
-
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
-
}
|
|
28
|
-
else if (_ = accept(result)) {
|
|
29
|
-
if (kind === "field") initializers.unshift(_);
|
|
30
|
-
else descriptor[key] = _;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
-
done = true;
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
35
7
|
};
|
|
36
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
9
|
exports.SingleConcurrentInteractionManager = void 0;
|
|
38
10
|
const mobx_1 = require("mobx");
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.resolveFunc = resolve;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
respond(interactionResponse) {
|
|
61
|
-
this.interactionRequest = null;
|
|
62
|
-
this.resolveFunc(interactionResponse);
|
|
63
|
-
this.resolveFunc = undefined;
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
(() => {
|
|
67
|
-
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
68
|
-
_interactionRequest_decorators = [mobx_1.observable];
|
|
69
|
-
_requestInteraction_decorators = [mobx_1.action];
|
|
70
|
-
_respond_decorators = [mobx_1.action];
|
|
71
|
-
__esDecorate(_a, null, _requestInteraction_decorators, { kind: "method", name: "requestInteraction", static: false, private: false, access: { has: obj => "requestInteraction" in obj, get: obj => obj.requestInteraction }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
72
|
-
__esDecorate(_a, null, _respond_decorators, { kind: "method", name: "respond", static: false, private: false, access: { has: obj => "respond" in obj, get: obj => obj.respond }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
73
|
-
__esDecorate(null, null, _interactionRequest_decorators, { kind: "field", name: "interactionRequest", static: false, private: false, access: { has: obj => "interactionRequest" in obj, get: obj => obj.interactionRequest, set: (obj, value) => { obj.interactionRequest = value; } }, metadata: _metadata }, _interactionRequest_initializers, _interactionRequest_extraInitializers);
|
|
74
|
-
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
75
|
-
})(),
|
|
76
|
-
_a;
|
|
77
|
-
})();
|
|
11
|
+
class SingleConcurrentInteractionManager {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.interactionRequest = { title: '', content: '' };
|
|
14
|
+
(0, mobx_1.makeObservable)(this);
|
|
15
|
+
this.interactionRequest = null;
|
|
16
|
+
}
|
|
17
|
+
requestInteraction(interactionRequest) {
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
this.interactionRequest = interactionRequest;
|
|
20
|
+
this.resolveFunc = resolve;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
respond(interactionResponse) {
|
|
24
|
+
this.interactionRequest = null;
|
|
25
|
+
this.resolveFunc(interactionResponse);
|
|
26
|
+
this.resolveFunc = undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
78
29
|
exports.SingleConcurrentInteractionManager = SingleConcurrentInteractionManager;
|
|
30
|
+
__decorate([
|
|
31
|
+
mobx_1.observable
|
|
32
|
+
], SingleConcurrentInteractionManager.prototype, "interactionRequest", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
mobx_1.action
|
|
35
|
+
], SingleConcurrentInteractionManager.prototype, "requestInteraction", null);
|
|
36
|
+
__decorate([
|
|
37
|
+
mobx_1.action
|
|
38
|
+
], SingleConcurrentInteractionManager.prototype, "respond", null);
|