@tb-dev/vue 0.1.6 → 0.1.7
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.
- package/dist/index.js +38 -37
- package/dist/utils/error.d.ts +1 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { defineComponent, createBlock, openBlock, unref, withCtx, createElementBlock, renderSlot, toDisplayString, toRef, effectScope, toValue, computed
|
|
1
|
+
import { defineComponent, createBlock, openBlock, unref, withCtx, createElementBlock, renderSlot, toDisplayString, inject as inject$1, toRef, effectScope, toValue, computed } from 'vue';
|
|
2
2
|
import { RouterLink } from 'vue-router';
|
|
3
|
-
import { computedAsync, useAsyncState, useElementSize as useElementSize$1, tryOnScopeDispose, onKeyStroke, useLocalStorage, useWindowSize } from '@vueuse/core';
|
|
4
3
|
import { unwrap, isNil } from '@tb-dev/utils';
|
|
4
|
+
import { computedAsync, useAsyncState, useElementSize as useElementSize$1, tryOnScopeDispose, onKeyStroke, useLocalStorage, useWindowSize } from '@vueuse/core';
|
|
5
5
|
|
|
6
6
|
const _hoisted_1 = { key: 0 };
|
|
7
7
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
@@ -25,28 +25,57 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
25
25
|
});
|
|
26
26
|
|
|
27
27
|
function create$1() {
|
|
28
|
+
let APP = null;
|
|
29
|
+
function get() {
|
|
30
|
+
return unwrap(APP, "no active app");
|
|
31
|
+
}
|
|
32
|
+
function set(app) {
|
|
33
|
+
APP = app;
|
|
34
|
+
}
|
|
35
|
+
return { get, set };
|
|
36
|
+
}
|
|
37
|
+
const { get: getCurrentApp, set: setCurrentApp } = create$1();
|
|
38
|
+
function runWithContext(fn) {
|
|
39
|
+
return getCurrentApp().runWithContext(fn);
|
|
40
|
+
}
|
|
41
|
+
function provide(key, value) {
|
|
42
|
+
getCurrentApp().provide(key, value);
|
|
43
|
+
}
|
|
44
|
+
function inject(key) {
|
|
45
|
+
const value = fallibleInject(key);
|
|
46
|
+
if (typeof value === "undefined") {
|
|
47
|
+
throw new TypeError("injection failed: value not provided");
|
|
48
|
+
}
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
function fallibleInject(key) {
|
|
52
|
+
return runWithContext(() => inject$1(key));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function create() {
|
|
28
56
|
let ERROR_HANDLER_FN = null;
|
|
29
57
|
function get() {
|
|
30
58
|
return ERROR_HANDLER_FN;
|
|
31
59
|
}
|
|
32
|
-
function set(fn,
|
|
60
|
+
function set(fn, app = true) {
|
|
33
61
|
ERROR_HANDLER_FN = fn;
|
|
34
|
-
if (
|
|
35
|
-
|
|
36
|
-
|
|
62
|
+
if (app) {
|
|
63
|
+
const _app = app === true ? getCurrentApp() : app;
|
|
64
|
+
_app.config.errorHandler = (err) => {
|
|
65
|
+
handle(err, true);
|
|
37
66
|
};
|
|
38
67
|
}
|
|
39
68
|
}
|
|
40
|
-
function handle(err,
|
|
69
|
+
function handle(err, rethrow = true) {
|
|
41
70
|
if (ERROR_HANDLER_FN) {
|
|
42
71
|
void Promise.try(ERROR_HANDLER_FN, err);
|
|
43
|
-
} else if (
|
|
72
|
+
} else if (rethrow) {
|
|
44
73
|
throw err;
|
|
45
74
|
}
|
|
46
75
|
}
|
|
47
76
|
return { get, set, handle };
|
|
48
77
|
}
|
|
49
|
-
const { get: getErrorHandler, set: setErrorHandler, handle: handleError } = create
|
|
78
|
+
const { get: getErrorHandler, set: setErrorHandler, handle: handleError } = create();
|
|
50
79
|
|
|
51
80
|
function asyncComputed(initial, callback, options) {
|
|
52
81
|
const state = computedAsync(callback, initial, {
|
|
@@ -165,34 +194,6 @@ function useWindowWidth() {
|
|
|
165
194
|
return useWindowSize().width;
|
|
166
195
|
}
|
|
167
196
|
|
|
168
|
-
function create() {
|
|
169
|
-
let APP = null;
|
|
170
|
-
function get() {
|
|
171
|
-
return unwrap(APP, "no active app");
|
|
172
|
-
}
|
|
173
|
-
function set(app) {
|
|
174
|
-
APP = app;
|
|
175
|
-
}
|
|
176
|
-
return { get, set };
|
|
177
|
-
}
|
|
178
|
-
const { get: getCurrentApp, set: setCurrentApp } = create();
|
|
179
|
-
function runWithContext(fn) {
|
|
180
|
-
return getCurrentApp().runWithContext(fn);
|
|
181
|
-
}
|
|
182
|
-
function provide(key, value) {
|
|
183
|
-
getCurrentApp().provide(key, value);
|
|
184
|
-
}
|
|
185
|
-
function inject(key) {
|
|
186
|
-
const value = fallibleInject(key);
|
|
187
|
-
if (typeof value === "undefined") {
|
|
188
|
-
throw new TypeError("injection failed: value not provided");
|
|
189
|
-
}
|
|
190
|
-
return value;
|
|
191
|
-
}
|
|
192
|
-
function fallibleInject(key) {
|
|
193
|
-
return runWithContext(() => inject$1(key));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
197
|
function maybe(value, fn) {
|
|
197
198
|
const _value = toValue(value);
|
|
198
199
|
return isNil(_value) ? null : fn(_value);
|
package/dist/utils/error.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
import { App } from 'vue';
|
|
2
2
|
import { MaybePromise, Option } from '@tb-dev/utils';
|
|
3
3
|
export type ErrorHandler = (err: unknown) => MaybePromise<void>;
|
|
4
|
-
export
|
|
5
|
-
app?: App;
|
|
6
|
-
}
|
|
7
|
-
export interface HandleErrorOptions {
|
|
8
|
-
rethrow?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare const getErrorHandler: () => Option<ErrorHandler>, setErrorHandler: (fn: ErrorHandler, options?: SetErrorHandlerOptions) => void, handleError: (err: unknown, options?: HandleErrorOptions) => void;
|
|
4
|
+
export declare const getErrorHandler: () => Option<ErrorHandler>, setErrorHandler: (fn: ErrorHandler, app?: Option<App | boolean>) => void, handleError: (err: unknown, rethrow?: boolean) => void;
|