nice-ui
Version:
React design system, components, and utilities
33 lines (32 loc) • 1.13 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToastItem = void 0;
const rxjs_1 = require("rxjs");
class ToastItem {
constructor(stack, opts) {
this.stack = stack;
this.opts = opts;
this.durationConsumed$ = new rxjs_1.BehaviorSubject(0);
this.softDeletedTime$ = new rxjs_1.BehaviorSubject(0);
this.remove = () => {
const { softDeletedTime$ } = this;
if (!softDeletedTime$.getValue()) {
this.softDeletedTime$.next(Date.now());
setTimeout(() => {
this.hardRemove();
}, 2000);
}
};
this.hardRemove = () => {
this.stack.remove(this);
};
this.consume = (time) => {
const newValue = this.durationConsumed$.getValue() + time;
this.durationConsumed$.next(newValue);
if (this.opts.duration && newValue >= this.opts.duration)
this.remove();
};
opts.id ?? (opts.id = Math.random().toString(36).slice(2));
}
}
exports.ToastItem = ToastItem;