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

toasterhea

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

toasterhea - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

10

index.d.ts
import * as react from 'react';
import { HTMLAttributes, FC, ComponentProps } from 'react';
import { FC, ComponentProps, HTMLAttributes } from 'react';

@@ -10,5 +10,7 @@ declare const Reason: {

declare function useDiscardableEffect(fn?: (discard: () => void | Promise<void>) => void): void;
declare function Container({ id, ...props }: Omit<HTMLAttributes<HTMLDivElement>, 'id' | 'children'> & {
interface ContainerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'id' | 'children'> {
id: string;
}): react.ReactPortal;
}
declare function InlineContainer({ id: idProp, ...props }: ContainerProps): JSX.Element;
declare function Container(props: ContainerProps): react.ReactPortal | null;
type SettlerReturnValue<T extends FC, K extends 'onResolve' | 'onReject'> = ComponentProps<T> extends Partial<Record<K, (value: infer R) => void>> ? R : void;

@@ -21,2 +23,2 @@ interface Toaster<T extends FC<any>> {

export { Container, Reason, Toaster, toaster, useDiscardableEffect };
export { Container, InlineContainer, Reason, Toaster, toaster, useDiscardableEffect };

55

index.js
import EventEmitter from 'eventemitter3';
import uniqueId from 'lodash/uniqueId';
import { createContext, useRef, useEffect, useContext, useState } from 'react';
import { createContext, useRef, useEffect, useContext, useState, useMemo } from 'react';
import { createPortal } from 'react-dom';

@@ -57,3 +57,2 @@ import { jsx } from 'react/jsx-runtime';

let emitter;
const containers = {};
function getEmitter() {

@@ -65,22 +64,10 @@ if (!emitter) {

}
function Container({
id,
function InlineContainer({
id: idProp,
...props
}) {
const containerRef = useRef(document.createElement("div"));
containerRef.current.id = id;
const [metadatas, setMetadatas] = useState({});
const id = useMemo(() => uniqueId(idProp), [idProp]);
useEffect(() => {
let mounted = true;
const {
current: container
} = containerRef;
const {
id: id2
} = container;
if (Object.prototype.hasOwnProperty.call(containers, id2) && containers[id2]) {
throw new Error("Container id already taken");
}
containers[id2] = true;
document.body.appendChild(container);
let cache = {};

@@ -115,9 +102,7 @@ async function onEvent(metadata) {

}
const en = eventName(id2);
const en = eventName(idProp);
getEmitter().on(en, onEvent);
return () => {
mounted = false;
document.body.removeChild(container);
getEmitter().off(en, onEvent);
delete containers[id2];
for (const key in cache) {

@@ -132,5 +117,6 @@ if (!Object.prototype.hasOwnProperty.call(cache, key)) {

};
}, []);
return /*#__PURE__*/createPortal( /*#__PURE__*/jsx("div", {
}, [idProp]);
return /*#__PURE__*/jsx("div", {
...props,
id: id,
children: Object.entries(metadatas).map(([key, {

@@ -162,4 +148,25 @@ component: C,

})
}), containerRef.current);
});
}
function Container(props) {
const containerRef = useRef(typeof document === "undefined" ? void 0 : document.createElement("div"));
useEffect(() => {
const {
current: container
} = containerRef;
if (!container) {
return () => void 0;
}
document.body.appendChild(container);
return () => {
document.body.removeChild(container);
};
}, []);
if (containerRef.current) {
return /*#__PURE__*/createPortal( /*#__PURE__*/jsx(InlineContainer, {
...props
}), containerRef.current);
}
return null;
}
function toaster(component, id) {

@@ -205,2 +212,2 @@ let metadata;

export { Container, Reason, toaster, useDiscardableEffect };
export { Container, InlineContainer, Reason, toaster, useDiscardableEffect };
{
"name": "toasterhea",
"version": "1.0.1",
"version": "1.0.2",
"description": "Promise-driven toast poppin' library.",

@@ -5,0 +5,0 @@ "main": "index.js",

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