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

cheap-di-react

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cheap-di-react - npm Package Compare versions

Comparing version 4.1.0 to 4.1.1

@@ -5,3 +5,3 @@ "use strict";

const react_1 = require("react");
exports.DiContext = (0, react_1.createContext)({ container: undefined });
exports.DiContext = (0, react_1.createContext)(null);
//# sourceMappingURL=DiContext.js.map

@@ -9,3 +9,3 @@ "use strict";

const { logger = console } = params;
const parentContainer = (0, react_1.useContext)(DiContext_js_1.DiContext).container;
const parentContainer = (0, react_1.useContext)(DiContext_js_1.DiContext)?.container;
const [contextValue, setContextValue] = (0, react_1.useState)({ container: undefined });

@@ -12,0 +12,0 @@ (0, react_1.useEffect)(() => {

{
"type": "commonjs",
"version": "4.1.0"
"version": "4.1.1"
}

@@ -30,9 +30,9 @@ "use strict";

for (const [type] of reactContainer.getDependencies()) {
const constructor = reactContainer.localScope((container) => container.getImplementation(type));
if (!constructor) {
return;
const implementation = reactContainer.localScope((container) => container.getImplementation(type));
if (!implementation) {
continue;
}
if ((0, cheap_di_1.isSingleton)(constructor)) {
logger.log('singleton', constructor, 'founded');
// resolve type to get and register its instance
if ((0, cheap_di_1.isSingleton)(implementation)) {
logger.log('singleton', implementation, 'founded');
// instantiate singleton in local scope (it may use local scope dependencies)
reactContainer.resolve(type);

@@ -45,3 +45,3 @@ }

timerRef.current = setTimeout(() => {
reactContainer.rootContainer.rerender();
reactContainer.rootReactContainer.rerender();
});

@@ -48,0 +48,0 @@ }

@@ -20,2 +20,5 @@ "use strict";

}
get rootReactContainer() {
return this.findReactContainerContainer();
}
sameParent(parentContainer) {

@@ -67,7 +70,14 @@ return this.parentContainer === parentContainer;

}
return this.parentContainer;
}
return this;
}
findReactContainerContainer() {
if (this.parentContainer instanceof ReactContainer) {
return this.parentContainer.findReactContainerContainer();
}
return this;
}
}
exports.ReactContainer = ReactContainer;
//# sourceMappingURL=ReactContainer.js.map
import { createContext } from 'react';
export const DiContext = createContext({ container: undefined });
export const DiContext = createContext(null);
//# sourceMappingURL=DiContext.js.map
import { useContext, useEffect, useState } from 'react';
import { DiContext } from '../DiContext.js';
import { ReactContainer } from '../ReactContainer.js';
function useDiContext(params = {}) {
export function useDiContext(params = {}) {
const { logger = console } = params;
const parentContainer = useContext(DiContext).container;
const parentContainer = useContext(DiContext)?.container;
const [contextValue, setContextValue] = useState({ container: undefined });

@@ -32,3 +32,2 @@ useEffect(() => {

}
export { useDiContext };
//# sourceMappingURL=useDiContext.js.map
{
"type": "module",
"version": "4.1.0"
"version": "4.1.1"
}

@@ -27,9 +27,9 @@ import { jsx as _jsx } from "react/jsx-runtime";

for (const [type] of reactContainer.getDependencies()) {
const constructor = reactContainer.localScope((container) => container.getImplementation(type));
if (!constructor) {
return;
const implementation = reactContainer.localScope((container) => container.getImplementation(type));
if (!implementation) {
continue;
}
if (isSingleton(constructor)) {
logger.log('singleton', constructor, 'founded');
// resolve type to get and register its instance
if (isSingleton(implementation)) {
logger.log('singleton', implementation, 'founded');
// instantiate singleton in local scope (it may use local scope dependencies)
reactContainer.resolve(type);

@@ -42,3 +42,3 @@ }

timerRef.current = setTimeout(() => {
reactContainer.rootContainer.rerender();
reactContainer.rootReactContainer.rerender();
});

@@ -45,0 +45,0 @@ }

@@ -17,2 +17,5 @@ import { ContainerImpl } from 'cheap-di';

}
get rootReactContainer() {
return this.findReactContainerContainer();
}
sameParent(parentContainer) {

@@ -64,6 +67,13 @@ return this.parentContainer === parentContainer;

}
return this.parentContainer;
}
return this;
}
findReactContainerContainer() {
if (this.parentContainer instanceof ReactContainer) {
return this.parentContainer.findReactContainerContainer();
}
return this;
}
}
//# sourceMappingURL=ReactContainer.js.map
{
"name": "cheap-di-react",
"version": "4.1.0",
"version": "4.1.1",
"description": "Dependency injection based on cheap-di for using in React components with React Context",

@@ -5,0 +5,0 @@ "peerDependencies": {

@@ -6,2 +6,2 @@ /// <reference types="react" />

};
export declare const DiContext: import("react").Context<DiContextType>;
export declare const DiContext: import("react").Context<DiContextType | null>;

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

import { Constructor, AbstractConstructor } from 'cheap-di';
import { AbstractConstructor, Constructor } from 'cheap-di';
export declare function use<TInstance>(type: Constructor<TInstance> | AbstractConstructor<TInstance>, ...args: any[]): TInstance;
export { use as useDi };

@@ -9,3 +9,3 @@ import { Container } from 'cheap-di';

};
declare function useDiContext(params?: HookParams): DiContextType;
export { useDiContext };
export declare function useDiContext(params?: HookParams): DiContextType;
export {};

@@ -8,5 +8,6 @@ import { AbstractConstructor, Constructor, ContainerImpl, ImplementationType } from 'cheap-di';

constructor(parentContainer?: ContainerImpl | undefined);
get rootContainer(): ReactContainer;
get rootContainer(): ContainerImpl;
get rootReactContainer(): ReactContainer;
sameParent(parentContainer?: ContainerImpl): boolean;
getDependencies(): Map<import("cheap-di/src/types").RegistrationType<any>, object | ImplementationType<any>>;
getDependencies(): Map<import("cheap-di/types/types").RegistrationType<any>, object | ImplementationType<any>>;
localScope<Callback extends (container: ReactContainer) => any>(callback: Callback): Callback extends (container: ReactContainer) => infer Result ? Result : void;

@@ -18,2 +19,3 @@ skipParentInstanceResolvingOnce(): void;

private findRootContainer;
private findReactContainerContainer;
}

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

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet