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

realar

Package Overview
Dependencies
Maintainers
1
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

realar - npm Package Compare versions

Comparing version 0.3.9 to 0.3.10

25

build/index.js

@@ -91,4 +91,23 @@ "use strict";

exports.observe = observe;
function use(Class, deps) {
return react_1.useMemo(() => (deps ? new Class(...deps) : new Class()), deps || []);
function use(Class, deps = []) {
if (!Array.isArray(deps)) {
throw 'TypeError: deps argument should be an array';
}
const [inst, effect] = react_1.useMemo(() => {
const inst = new Class(...deps);
const effect = () => {
const un = inst.effect && inst.effect();
return () => {
try {
un && un();
}
finally {
inst.free && inst.free();
}
};
};
return [inst, effect];
}, deps);
react_1.useEffect(effect, [inst]);
return inst;
}

@@ -99,3 +118,3 @@ exports.use = use;

shareds.forEach(instance => {
instance.destructor && instance.destructor();
instance.free && instance.free();
});

@@ -102,0 +121,0 @@ }

9

package.json
{
"name": "realar",
"version": "0.3.9",
"version": "0.3.10",
"description": "React state manager",

@@ -24,2 +24,3 @@ "repository": {

"test": "jest",
"jest:clear-cache": "jest --clearCache",
"publish": "npm run clear && npm run build && lerna publish",

@@ -53,4 +54,4 @@ "format": "prettier --write src tests jest",

"prettier": "2.2.1",
"react": "17.0.1",
"react-dom": "17.0.1",
"react": "16.14.0",
"react-dom": "16.14.0",
"rimraf": "3.0.2",

@@ -92,3 +93,3 @@ "typescript": "4.1.3"

},
"gitHead": "1c1fb3266f8e9942b37099f61daa5bfa7fd897be"
"gitHead": "d7aa04620279cf4556da90dc51520fd0cf9097b3"
}

@@ -105,4 +105,22 @@ import { useRef, useReducer, useEffect, useMemo, FC, memo } from 'react';

function use<T extends unknown[], M>(Class: new (...args: T) => M, deps?: T): M {
return useMemo(() => (deps ? new Class(...deps) : new (Class as any)()), deps || []);
function use<T extends unknown[], M>(Class: new (...args: T) => M, deps = [] as T): M {
if (!Array.isArray(deps)) {
throw 'TypeError: deps argument should be an array';
}
const [inst, effect] = useMemo(() => {
const inst = new Class(...(deps as any)) as any;
const effect = () => {
const un = inst.effect && inst.effect();
return () => {
try {
un && un();
} finally {
inst.free && inst.free();
}
};
};
return [inst, effect];
}, deps);
useEffect(effect, [inst]);
return inst;
}

@@ -113,3 +131,3 @@

shareds.forEach(instance => {
instance.destructor && instance.destructor();
instance.free && instance.free();
});

@@ -116,0 +134,0 @@ } finally {

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