Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@byloth/vuert

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@byloth/vuert - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0-rc.3

244

dist/vuert.js

@@ -1,10 +0,11 @@

var N = Object.defineProperty;
var S = (t, e, s) => e in t ? N(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
var i = (t, e, s) => (S(t, typeof e != "symbol" ? e + "" : e, s), s);
import { getCurrentScope as A, inject as I, ref as V, computed as k, nextTick as F, defineComponent as $, shallowRef as E, onMounted as P, onUnmounted as C, openBlock as D, createBlock as U, resolveDynamicComponent as R, withCtx as B, renderSlot as H, createCommentVNode as L } from "vue";
import { RuntimeException as u, ValueException as w, FatalErrorException as K } from "@byloth/exceptions";
const O = { $vuert: Symbol("[vuert]: vuert") }, d = class d {
var x = Object.defineProperty;
var T = (t, e, i) => e in t ? x(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
var s = (t, e, i) => (T(t, typeof e != "symbol" ? e + "" : e, i), i);
import { getCurrentScope as j, inject as C, ref as k, computed as A, defineComponent as F, shallowRef as I, onMounted as N, onUnmounted as V, openBlock as U, createBlock as $, resolveDynamicComponent as E, withCtx as D, renderSlot as P, createCommentVNode as R, nextTick as B } from "vue";
import { RuntimeException as h, ValueException as _ } from "@byloth/exceptions";
import { DeferredPromise as H, Subscribers as u, delay as v } from "@byloth/core";
const y = { $vuert: Symbol("[vuert]: vuert") }, d = class d {
constructor(e) {
i(this, "_subscribers");
i(this, "_options");
s(this, "_subscribers");
s(this, "_options");
this._subscribers = [], this._options = { ...d.DEFAULT_OPTS, ...e };

@@ -19,27 +20,29 @@ }

emit(e) {
const o = this._subscribers.slice().map((n) => n(e)).filter((n) => !!n);
const o = this._subscribers.slice().map((l) => l(e)).filter((l) => !!l);
if (!o.length)
throw new u("Unable to handle the emitted alert properly. There wasn't found any supported subscribers.");
return Promise.any(o);
throw new h("Unable to handle the emitted alert properly. There wasn't found any supported subscribers.");
if (o.length > 1)
throw new h("Unable to handle the emitted alert properly. There were found too many supported subscribers.");
return o[0];
}
subscribe(e) {
return this._subscribers.push(e), () => {
const s = this._subscribers.indexOf(e);
return this._subscribers.splice(s, 1)[0];
const i = this._subscribers.indexOf(e);
return this._subscribers.splice(i, 1)[0];
};
}
};
i(d, "VERSION", "1.1.0");
let b = d, j;
const M = (t) => {
j = t;
}, q = () => A() ? I(O.$vuert) : j, X = (t) => ({
install: ({ config: e, provide: s }) => {
const c = new b(t);
M(c), e.globalProperties.$vuert = c, s(O.$vuert, c);
s(d, "VERSION", "1.2.0-rc.3");
let p = d, w;
const L = (t) => {
w = t;
}, K = () => j() ? C(y.$vuert) : w, Q = (t) => ({
install: ({ config: e, provide: i }) => {
const r = new p(t);
L(r), e.globalProperties.$vuert = r, i(y.$vuert, r);
}
}), _ = () => {
const t = q();
}), g = () => {
const t = K();
if (!t)
throw new u(
throw new h(
"`useVuert()` was called but there was not active Vuert. Did you forget to install `Vuert` plugin in your App?"

@@ -49,9 +52,9 @@ );

};
class x {
class S {
constructor(e) {
i(this, "id");
i(this, "type");
i(this, "icon");
i(this, "label");
i(this, "callback");
s(this, "id");
s(this, "type");
s(this, "icon");
s(this, "label");
s(this, "callback");
this.id = e.id ?? Symbol(), this.type = e.type ?? "secondary", this.icon = e.icon, this.label = e.label, this.callback = e.callback ?? (() => {

@@ -61,21 +64,21 @@ });

}
class l {
constructor(e, s) {
i(this, "id");
i(this, "type");
i(this, "priority");
i(this, "icon");
i(this, "title");
i(this, "message");
i(this, "component");
i(this, "props");
i(this, "actions");
i(this, "dismissible");
i(this, "timeout");
var c;
class a {
constructor(e, i) {
s(this, "id");
s(this, "type");
s(this, "priority");
s(this, "icon");
s(this, "title");
s(this, "message");
s(this, "component");
s(this, "props");
s(this, "actions");
s(this, "dismissible");
s(this, "timeout");
var r;
if (this.id = e.id ?? Symbol(), this.type = e.type ?? "info", this.priority = e.priority ?? "normal", this.icon = e.icon, this.title = e.title, e.message !== void 0 && e.component !== void 0)
throw new w("The `message` and `component` properties cannot both be valued at the same time.");
if (this.message = e.message, this.component = e.component, this.props = e.props, this.actions = ((c = e.actions) == null ? void 0 : c.map((o) => new x(o))) ?? [], this.dismissible = e.dismissible || !1, e.timeout !== void 0) {
throw new _("The `message` and `component` properties cannot both be valued at the same time.");
if (this.message = e.message, this.component = e.component, this.props = e.props, this.actions = ((r = e.actions) == null ? void 0 : r.map((o) => new S(o))) ?? [], this.dismissible = e.dismissible || !1, e.timeout !== void 0) {
if (e.timeout <= 0)
throw new w("The `timeout` property must be a positive integer or -at least- `undefined`.");
throw new _("The `timeout` property must be a positive integer or -at least- `undefined`.");
this.timeout = e.timeout;

@@ -86,32 +89,54 @@ } else

}
class z {
constructor(e, { resolve: s, reject: c }) {
i(this, "_timeoutId");
i(this, "_isOpen");
i(this, "alert");
i(this, "isOpen");
i(this, "resolver");
i(this, "rejecter");
this.alert = new l(e);
const o = () => {
class M extends H {
constructor(i, r) {
const o = async () => {
if (!this._isOpen.value)
throw new u("Unable to close the alert. It has already been closed or not even opened.");
this._timeoutId !== void 0 && (clearTimeout(this._timeoutId), this._timeoutId = void 0), this._isOpen.value = !1;
throw new Error("Unable to close the alert. It has already been closed or not even opened yet.");
this._isOpen.value = !1, this._timeoutId !== void 0 && (clearTimeout(this._timeoutId), this._timeoutId = void 0), this._closingSubscribers.call(), await v(this._duration.leave), this._closedSubscribers.call();
};
this.resolver = (n) => {
o(), n instanceof x ? s(n.callback()) : n instanceof Function ? s(n()) : s(n);
}, this.rejecter = (n) => {
o(), c(n);
}, this._isOpen = V(!1), this.isOpen = k(() => this._isOpen.value);
super((c) => (o(), c instanceof S ? c.callback() : c instanceof Function ? c() : c), (c) => {
throw o(), c;
});
s(this, "_duration");
s(this, "_timeoutId");
s(this, "_openingSubscribers");
s(this, "_openedSubscribers");
s(this, "_closingSubscribers");
s(this, "_closedSubscribers");
s(this, "_isOpen");
s(this, "alert");
s(this, "isOpen");
if (typeof r == "object")
this._duration = {
enter: Number(r.enter),
leave: Number(r.leave)
};
else {
const c = Number(r);
this._duration = {
enter: c,
leave: c
};
}
this._openingSubscribers = new u(), this._openedSubscribers = new u(), this._closingSubscribers = new u(), this._closedSubscribers = new u(), this.alert = new a(i), this._isOpen = k(!1), this.isOpen = A(() => this._isOpen.value);
}
opening() {
async open() {
if (this._isOpen.value)
throw new u("Unable to open the alert. It has already been opened.");
this._isOpen.value = !0;
throw new Error("Unable to open the alert. It has already been opened.");
this._isOpen.value = !0, this._openingSubscribers.call(), await v(this._duration.enter), this._openedSubscribers.call(), this.alert.timeout && (this._timeoutId = setTimeout(this.resolve, this.alert.timeout));
}
opened() {
this.alert.timeout && (this._timeoutId = setTimeout(this.resolver, this.alert.timeout));
onOpening(i) {
this._openingSubscribers.add(i);
}
onOpened(i) {
this._openedSubscribers.add(i);
}
onClosing(i) {
this._closingSubscribers.add(i);
}
onClosed(i) {
this._closedSubscribers.add(i);
}
}
const g = (t) => new Promise((e) => setTimeout(e, t)), G = () => new Promise((t) => F(t)), Y = /* @__PURE__ */ $({
const W = /* @__PURE__ */ F({
__name: "AlertHandler",

@@ -124,4 +149,4 @@ props: {

duration: {
default: () => _().options.duration,
type: [Number, String, Object],
default: () => g().options.duration,
type: [Number, Object],
validator: (t) => t instanceof Object ? "enter" in t && "leave" in t ? isFinite(Number(t.enter)) && isFinite(Number(t.leave)) : !1 : isFinite(Number(t))

@@ -135,43 +160,32 @@ },

emits: {
opening: (t) => t instanceof l,
opened: (t) => t instanceof l,
closing: (t) => t instanceof l,
closed: (t) => t instanceof l
opening: (t) => t instanceof a,
opened: (t) => t instanceof a,
closing: (t) => t instanceof a,
closed: (t) => t instanceof a
},
setup(t, { emit: e }) {
const s = t, c = _(), o = [], n = E(), T = (r, { resolve: a, reject: h }) => {
const m = new z(r, {
resolve: async (p) => {
await v(m), a(p);
},
reject: async (p) => {
await v(m), h(p);
}
});
o.push(m), o.length === 1 && f();
}, f = async () => {
const r = o[0];
let a;
s.duration instanceof Object ? a = Number(s.duration.enter) : a = Number(s.duration), n.value = r, r.opening(), e("opening", r.alert), await g(a), e("opened", r.alert), r.opened();
}, v = async (r) => {
if (r.alert.id !== o[0].alert.id)
throw new K();
let a;
s.duration instanceof Object ? a = Number(s.duration.leave) : a = Number(s.duration), e("closing", r.alert), await g(a), e("closed", r.alert), o.shift(), n.value = void 0, await G(), o.length > 0 && f();
const i = t, r = g(), o = [], l = I(), m = () => new Promise((n) => B(n)), c = async () => {
const n = o[0];
n.onOpening(() => e("opening", n.alert)), n.onOpened(() => e("opened", n.alert)), n.onClosing(() => e("closing", n.alert)), n.onClosed(async () => {
e("closed", n.alert), o.shift(), l.value = void 0, await m(), o.length > 0 && c();
}), l.value = n, await n.open();
}, O = (n) => {
const b = new M(n, i.duration);
return o.push(b), o.length === 1 && c(), b;
};
let y;
return P(() => {
y = c.subscribe((r) => {
if (s.filter(r))
return new Promise((a, h) => T(r, { resolve: a, reject: h }));
let f;
return N(() => {
f = r.subscribe((n) => {
if (i.filter(n))
return O(n);
});
}), C(() => y()), (r, a) => (D(), U(R(t.is), null, {
default: B(() => [
n.value ? H(r.$slots, "default", {
}), V(() => f()), (n, b) => (U(), $(E(t.is), null, {
default: D(() => [
l.value ? P(n.$slots, "default", {
key: 0,
alert: n.value.alert,
isOpen: n.value.isOpen.value,
resolve: n.value.resolver,
reject: n.value.rejecter
}) : L("", !0)
alert: l.value.alert,
isOpen: l.value.isOpen.value,
resolve: l.value.resolve,
reject: l.value.reject
}) : R("", !0)
]),

@@ -183,10 +197,10 @@ _: 3

export {
x as Action,
l as Alert,
Y as AlertHandler,
z as Context,
X as createVuert,
b as default,
_ as useVuert
S as Action,
a as Alert,
W as AlertHandler,
M as Context,
Q as createVuert,
p as default,
g as useVuert
};
//# sourceMappingURL=vuert.js.map
{
"name": "@byloth/vuert",
"version": "1.1.0",
"version": "1.2.0-rc.3",
"description": "The headless alerts, notifications & popups library for Vue.js craftsmen. ℹ",

@@ -16,3 +16,3 @@ "keywords": [

],
"homepage": "https://github.com/Byloth/vuert#readme",
"homepage": "https://byloth.github.io/vuert/",
"repository": {

@@ -27,3 +27,3 @@ "type": "git",

"name": "Matteo Bilotta",
"email": "me@byloth.net",
"email": "me@byloth.dev",
"url": "https://www.byloth.dev/"

@@ -65,21 +65,22 @@ },

"dependencies": {
"@byloth/exceptions": "^2.0.3",
"@byloth/core": "^1.1.4",
"@byloth/exceptions": "^2.1.0",
"vue": "^3.3.4"
},
"devDependencies": {
"@byloth/eslint-config-typescript": "^2.6.0",
"@byloth/eslint-config-vue": "^2.6.0",
"@fortawesome/fontawesome-free": "^6.4.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-vue": "^4.2.3",
"eslint": "^8.45.0",
"eslint-plugin-vue": "^9.15.1",
"sass": "^1.63.6",
"typescript": "^5.1.6",
"vite": "^4.4.4",
"vitepress": "^1.0.0-beta.5",
"@byloth/eslint-config-typescript": "^2.6.5",
"@byloth/eslint-config-vue": "^2.6.5",
"@fortawesome/fontawesome-free": "^6.4.2",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"@vitejs/plugin-vue": "^4.4.0",
"eslint": "^8.50.0",
"eslint-plugin-vue": "^9.17.0",
"sass": "^1.68.0",
"typescript": "^5.2.2",
"vite": "^4.4.10",
"vitepress": "^1.0.0-rc.20",
"vue-eslint-parser": "^9.3.1",
"vue-tsc": "^1.8.5"
"vue-tsc": "^1.8.15"
}
}
# Vuert ℹ
[![NPM release](https://github.com/Byloth/vuert/actions/workflows/release-npm.yml/badge.svg)](https://github.com/Byloth/vuert/actions/workflows/release-npm.yml)
[![GPR release](https://github.com/Byloth/vuert/actions/workflows/release-gpr.yml/badge.svg)](https://github.com/Byloth/vuert/actions/workflows/release-gpr.yml)
The headless alerts, notifications & popups library for Vue.js craftsmen.
## 📝 Documentation
[![Docs deploy](https://github.com/Byloth/vuert/actions/workflows/docs-deploy.yml/badge.svg)](https://github.com/Byloth/vuert/actions/workflows/docs-deploy.yml)
**[https://byloth.github.io/vuert/](https://byloth.github.io/vuert/)**
> **Note:**
>
> The documentation is still a work in progress.
> Feel free to contribute by opening an issue or a pull request.

@@ -1,3 +0,4 @@

import type { PropType } from "vue";
import type { Component, PropType } from "vue";
import { Alert } from "../models/index.js";
import type { Duration } from "../types/index.js";
import type { AlertOptions } from "../types/alert/index.js";

@@ -7,10 +8,7 @@ declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<{

default: string;
type: (StringConstructor | ObjectConstructor)[];
type: PropType<string | Component>;
};
duration: {
default: () => string | number | {
enter: string | number;
leave: string | number;
};
type: (StringConstructor | ObjectConstructor | NumberConstructor)[];
default: () => number | Duration;
type: PropType<number | Duration>;
validator: (value: unknown) => boolean;

@@ -23,17 +21,14 @@ };

}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
opening: (alert: Alert<unknown>) => boolean;
opened: (alert: Alert<unknown>) => boolean;
closing: (alert: Alert<unknown>) => boolean;
closed: (alert: Alert<unknown>) => boolean;
opening: (alert: Alert<unknown>) => void;
opened: (alert: Alert<unknown>) => void;
closing: (alert: Alert<unknown>) => void;
closed: (alert: Alert<unknown>) => void;
}, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
is: {
default: string;
type: (StringConstructor | ObjectConstructor)[];
type: PropType<string | Component>;
};
duration: {
default: () => string | number | {
enter: string | number;
leave: string | number;
};
type: (StringConstructor | ObjectConstructor | NumberConstructor)[];
default: () => number | Duration;
type: PropType<number | Duration>;
validator: (value: unknown) => boolean;

@@ -52,4 +47,4 @@ };

filter: (options: AlertOptions<unknown>) => boolean;
is: string | Record<string, any>;
duration: string | number | Record<string, any>;
is: string | Component;
duration: number | Duration;
}, {}>, {

@@ -59,4 +54,4 @@ default?(_: {

isOpen: boolean;
resolve: (result?: any) => void;
reject: (error: Error) => void;
resolve: import("@byloth/core").PromiseResolver<any>;
reject: import("@byloth/core").PromiseRejecter<unknown>;
}): any;

@@ -63,0 +58,0 @@ }>;

@@ -7,6 +7,6 @@ import AlertHandler from "./components/AlertHandler.vue";

export type { VuertOptions } from "./vuert.js";
export type { VuertOptions, VuertSubscriber } from "./vuert.js";
export type { IAction, ActionCallback, ActionOptions } from "./types/action.js";
export type { IAlert, AlertOptions, AlertSubscriber } from "./types/alert/index.js";
export type { IAlert, AlertOptions } from "./types/alert/index.js";
export type { SimpleAlert, BlockingAlert, DismissibleAlert } from "./types/alert/simple.js";

@@ -13,0 +13,0 @@ export type { CustomAlert, BlockingCustomAlert, DismissibleCustomAlert } from "./types/alert/custom.js";

import { computed, ref } from "vue";
import type { ComputedRef, Ref } from "vue";
import { RuntimeException } from "@byloth/exceptions";
import { delay, DeferredPromise, Subscribers } from "@byloth/core";
import type { MaybePromise } from "@byloth/core";
import type { Awaitable, PromiseClosures } from "../types/index.js";
import type { Duration } from "../types/index.js";
import type { ActionCallback } from "../types/action.js";

@@ -13,27 +14,30 @@ import type { AlertOptions } from "../types/alert/index.js";

export type ContextResult<R> = Action<R> | ActionCallback<R | undefined> | Awaitable<R | undefined>;
export type ContextResult<R> = Action<R> | ActionCallback<R | undefined> | MaybePromise<R | undefined>;
export default class Context<R = void>
export default class Context<T = void> extends DeferredPromise<T>
{
protected _timeoutId: number | undefined;
protected _duration: Duration;
protected _timeoutId?: number;
protected _openingSubscribers: Subscribers;
protected _openedSubscribers: Subscribers;
protected _closingSubscribers: Subscribers;
protected _closedSubscribers: Subscribers;
protected readonly _isOpen: Ref<boolean>;
public readonly alert: Alert<R>;
public readonly alert: Alert<T>;
public readonly isOpen: ComputedRef<boolean>;
public readonly resolver: (result?: ContextResult<R>) => void;
public readonly rejecter: (error: Error) => void;
public constructor(options: AlertOptions<R>, { resolve, reject }: PromiseClosures<R, Error>)
public constructor(options: AlertOptions<T>, duration: number | Duration)
{
this.alert = new Alert<R>(options);
const _close = () =>
const _close = async (): Promise<void> =>
{
if (!this._isOpen.value)
{
throw new RuntimeException("Unable to close the alert. It has already been closed or not even opened.");
throw new Error("Unable to close the alert. It has already been closed or not even opened yet.");
}
this._isOpen.value = false;
if (this._timeoutId !== undefined)

@@ -46,6 +50,8 @@ {

this._isOpen.value = false;
this._closingSubscribers.call();
await delay(this._duration.leave);
this._closedSubscribers.call();
};
this.resolver = (result?: ContextResult<R>): void =>
const _onFulfilled = (result?: MaybePromise<ContextResult<T>>): T =>
{

@@ -56,20 +62,45 @@ _close();

{
resolve(result.callback() as R);
return result.callback() as T;
}
else if (result instanceof Function)
{
resolve(result() as R);
return result() as T;
}
else
{
resolve(result as R);
return result as T;
}
};
this.rejecter = (error: Error): void =>
const _onRejected = (reason: unknown): never =>
{
_close();
reject(error);
throw reason;
};
super(_onFulfilled, _onRejected);
if (typeof duration === "object")
{
this._duration = {
enter: Number(duration.enter),
leave: Number(duration.leave)
};
}
else
{
const _duration = Number(duration);
this._duration = {
enter: _duration,
leave: _duration
};
}
this._openingSubscribers = new Subscribers();
this._openedSubscribers = new Subscribers();
this._closingSubscribers = new Subscribers();
this._closedSubscribers = new Subscribers();
this.alert = new Alert<T>(options);
this._isOpen = ref(false);

@@ -79,18 +110,37 @@ this.isOpen = computed((): boolean => this._isOpen.value);

public opening(): void
public async open(): Promise<void>
{
if (this._isOpen.value)
{
throw new RuntimeException("Unable to open the alert. It has already been opened.");
throw new Error("Unable to open the alert. It has already been opened.");
}
this._isOpen.value = true;
}
public opened(): void
{
this._openingSubscribers.call();
await delay(this._duration.enter);
this._openedSubscribers.call();
if (this.alert.timeout)
{
this._timeoutId = setTimeout(this.resolver, this.alert.timeout);
this._timeoutId = setTimeout(this.resolve, this.alert.timeout);
}
}
public onOpening(subscriber: () => void): void
{
this._openingSubscribers.add(subscriber);
}
public onOpened(subscriber: () => void): void
{
this._openedSubscribers.add(subscriber);
}
public onClosing(subscriber: () => void): void
{
this._closingSubscribers.add(subscriber);
}
public onClosed(subscriber: () => void): void
{
this._closedSubscribers.add(subscriber);
}
}

@@ -1,4 +0,4 @@

import type { Awaitable } from "./index.js";
import type { MaybePromise } from "@byloth/core";
export type ActionCallback<T> = () => Awaitable<T>;
export type ActionCallback<T> = () => MaybePromise<T>;

@@ -5,0 +5,0 @@ export interface IAction<R>

@@ -7,2 +7,1 @@ import type { SimpleAlert } from "./simple.js";

export type AlertOptions<R = void> = SimpleAlert<R> | CustomAlert<R>;
export type AlertSubscriber<R = void> = (alert: AlertOptions<R>) => Promise<R> | undefined;

@@ -1,10 +0,5 @@

export type Awaitable<T> = T | PromiseLike<T>;
export type PromiseResolver<T = void> = (result: Awaitable<T>) => void;
export type PromiseRejecter<E = unknown> = (error: E) => void;
export interface PromiseClosures<T = void, E = unknown>
export interface Duration
{
resolve: PromiseResolver<T>;
reject: PromiseRejecter<E>
enter: number;
leave: number;
}

@@ -5,3 +5,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */

import type { AlertOptions, AlertSubscriber } from "./types/alert/index.js";
import type { Context } from "./models/index.js";
import type { Duration } from "./types/index.js";
import type { AlertOptions } from "./types/alert/index.js";
import type { BlockingAlert, DismissibleAlert } from "./types/alert/simple.js";

@@ -12,8 +15,9 @@ import type { BlockingCustomAlert, DismissibleCustomAlert } from "./types/alert/custom.js";

{
duration: number | string | { enter: number | string; leave: number | string; };
duration: number | Duration;
}
export type VuertSubscriber<R = void> = (alert: AlertOptions<R>) => Context<R> | void;
export default class Vuert
{
public static readonly VERSION: string = "1.1.0";
public static readonly VERSION: string = "1.2.0-rc.3";

@@ -25,3 +29,3 @@ public static get DEFAULT_OPTS(): VuertOptions

protected _subscribers: AlertSubscriber<any>[];
protected _subscribers: VuertSubscriber<any>[];

@@ -41,12 +45,12 @@ protected _options: VuertOptions;

public emit<R = void>(alert: BlockingAlert<R>): Promise<R>;
public emit<R = void>(alert: DismissibleAlert<R>): Promise<R | void>;
public emit<R = void>(alert: BlockingCustomAlert<R>): Promise<R>;
public emit<R = void>(alert: DismissibleCustomAlert<R>): Promise<R | void>;
public emit<R = void>(alert: AlertOptions<R>): Promise<R | void>;
public emit<R = void>(alert: AlertOptions<R>): Promise<R | void>
public emit<R = void>(alert: BlockingAlert<R>): Context<R>;
public emit<R = void>(alert: DismissibleAlert<R>): Context<R | void>;
public emit<R = void>(alert: BlockingCustomAlert<R>): Context<R>;
public emit<R = void>(alert: DismissibleCustomAlert<R>): Context<R | void>;
public emit<R = void>(alert: AlertOptions<R>): Context<R | void>;
public emit<R = void>(alert: AlertOptions<R>): Context<R | void>
{
const subscribers = this._subscribers.slice();
const promises = subscribers.map((subscriber) => subscriber(alert));
const results = promises.filter((element) => !!(element)) as Promise<any>[];
const contexts = subscribers.map((subscriber) => subscriber(alert));
const results = contexts.filter((context) => !!(context)) as Context<any>[];

@@ -58,11 +62,16 @@ if (!results.length)

}
if (results.length > 1)
{
throw new RuntimeException("Unable to handle the emitted alert properly. " +
"There were found too many supported subscribers.");
}
return Promise.any(results);
return results[0];
}
public subscribe<R>(subscriber: AlertSubscriber<R>): () => AlertSubscriber<R>
public subscribe<R>(subscriber: VuertSubscriber<R>): () => VuertSubscriber<R>
{
this._subscribers.push(subscriber);
return (): AlertSubscriber<R> =>
return (): VuertSubscriber<R> =>
{

@@ -69,0 +78,0 @@ const index = this._subscribers.indexOf(subscriber);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc