@codescouts/ui
Advanced tools
Comparing version 1.0.15 to 1.0.16
@@ -1,6 +0,6 @@ | ||
import { Handler } from "@codescouts/events"; | ||
import { DomainEvent, Handler } from "@codescouts/events"; | ||
import { Ref } from "@codescouts/di"; | ||
export declare const useEvents: () => { | ||
attach: (...handlers: Ref<Handler<any>>[]) => void; | ||
attach: (...handlers: Ref<Handler<DomainEvent>>[]) => void; | ||
}; | ||
//# sourceMappingURL=useEvent.d.ts.map |
@@ -22,4 +22,6 @@ "use strict"; | ||
var react_1 = require("react"); | ||
var resolvedHandlers = []; | ||
var useEvents = function () { | ||
var _a = __read((0, react_1.useState)([]), 2), _ = _a[0], setHandlers = _a[1]; | ||
var _a = __read((0, react_1.useState)(false), 2), isLoaded = _a[0], setIsLoaded = _a[1]; | ||
var _b = __read((0, react_1.useState)([]), 2), handlers = _b[0], setHandlers = _b[1]; | ||
var attach = function () { | ||
@@ -30,10 +32,18 @@ var handlers = []; | ||
} | ||
var newHandlers = handlers.map(function (h) { | ||
return (0, di_1.useResolve)(h); | ||
setHandlers(handlers); | ||
}; | ||
(0, react_1.useEffect)(function () { | ||
if (!isLoaded) | ||
return; | ||
resolvedHandlers.forEach(function (handler) { return handler.dispose(); }); | ||
resolvedHandlers = handlers.map(function (handler) { | ||
return (0, di_1.useResolve)(handler); | ||
}); | ||
setHandlers(function (prev) { | ||
prev.forEach(function (h) { return h.dispose(); }); | ||
return newHandlers; | ||
}); | ||
}; | ||
}, [handlers, isLoaded]); | ||
(0, react_1.useEffect)(function () { | ||
setIsLoaded(true); | ||
return function () { | ||
resolvedHandlers.forEach(function (handler) { return handler.dispose(); }); | ||
}; | ||
}, []); | ||
return { | ||
@@ -40,0 +50,0 @@ attach: attach, |
{ | ||
"name": "@codescouts/ui", | ||
"version": "1.0.15", | ||
"version": "1.0.16", | ||
"main": "./lib/index.js", | ||
@@ -5,0 +5,0 @@ "types": "./lib/index.d.ts", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
63639
723
4