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.7 to 0.3.8

4

build/index.d.ts

@@ -5,9 +5,9 @@ import { FC } from 'react';

declare function sel_decorator(_proto: any, key: any, descriptor: any): any;
declare function reaction<T>(target: () => T, listener: (value: T) => void): () => void;
declare function reaction<T>(target: () => T, listener: (value: T, prev?: T) => void): () => void;
declare function expression(body: () => void): () => void;
declare function initial(data: any): void;
declare function mock<M>(Class: new (init?: any) => M, mocked: M): M;
declare function shared<M>(Class: new (init?: any) => M): M;
declare function shared<M>(Class: (new (init?: any) => M) | ((init?: any) => M)): M;
declare function observe<T extends FC<P>, P>(Component: T): import("react").MemoExoticComponent<(props: P) => import("react").ReactElement<any, any>>;
declare function use<T extends unknown[], M>(Class: new (...args: T) => M, deps?: T): M;
declare function free(): void;

@@ -37,7 +37,9 @@ "use strict";

function reaction(target, listener) {
let value;
const [get] = reactive_box_1.sel(target);
const [run, stop] = reactive_box_1.expr(get, () => {
listener(run());
const prev = value;
listener((value = run()), prev);
});
run();
value = run();
return stop;

@@ -64,3 +66,7 @@ }

if (!instance) {
shareds.set(Class, (instance = new Class(initial_data)));
instance =
typeof Class.prototype === 'undefined'
? Class(initial_data)
: new Class(initial_data);
shareds.set(Class, instance);
}

@@ -74,2 +80,3 @@ return instance;

function observe(Component) {
// Todo: check forwardRef support
return react_1.memo((props) => {

@@ -76,0 +83,0 @@ const forceUpdate = useForceUpdate();

{
"name": "realar",
"version": "0.3.7",
"version": "0.3.8",
"description": "React state manager",

@@ -21,3 +21,3 @@ "repository": {

"scripts": {
"build": "tsc",
"build": "tsc --build tsconfig.build.json",
"build:watch": "tsc -w",

@@ -91,3 +91,3 @@ "test": "jest",

},
"gitHead": "291980f333703a7743084099ebe4a841be879359"
"gitHead": "3212c53542c5ae3ce316fa22fcca1fa40c740b18"
}
# Realar
[![npm version](https://img.shields.io/npm/v/realar?style=flat-square)](https://www.npmjs.com/package/realar) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/realar?style=flat-square)](https://bundlephobia.com/result?p=realar) [![code coverage](https://img.shields.io/coveralls/github/betula/realar?style=flat-square)](https://coveralls.io/github/betula/realar) [![typescript supported](https://img.shields.io/npm/types/typescript?style=flat-square)](./src/index.ts)
[![npm version](https://img.shields.io/npm/v/realar?style=flat-square)](https://www.npmjs.com/package/realar) [![npm bundle size](https://img.shields.io/bundlephobia/minzip/realar?style=flat-square)](https://bundlephobia.com/result?p=realar) [![code coverage](https://img.shields.io/coveralls/github/betula/realar?style=flat-square)](https://coveralls.io/github/betula/realar) [![typescript supported](https://img.shields.io/npm/types/typescript?style=flat-square)](./src/index.ts) [![npm downloads](https://img.shields.io/npm/dt/realar?style=flat-square)](https://www.npmjs.com/package/realar)

@@ -24,3 +24,3 @@ Reactive state manager for React based on [reactive-box](https://github.com/betula/reactive-box).

const CounterView = () => {
const App = () => {
const { value, increment, decrement } = sharedCounter();

@@ -51,3 +51,3 @@ return (

```bash
npm install --save realar
npm install realar
# or

@@ -54,0 +54,0 @@ yarn add realar

@@ -49,8 +49,10 @@ import { useRef, useReducer, useEffect, useMemo, FC, memo } from 'react';

function reaction<T>(target: () => T, listener: (value: T) => void) {
function reaction<T>(target: () => T, listener: (value: T, prev?: T) => void) {
let value: T;
const [get] = sel(target);
const [run, stop] = expr(get, () => {
listener(run());
const prev = value;
listener((value = run()), prev);
});
run();
value = run();
return stop;

@@ -74,6 +76,10 @@ }

function shared<M>(Class: new (init?: any) => M): M {
function shared<M>(Class: (new (init?: any) => M) | ((init?: any) => M)): M {
let instance = shareds.get(Class);
if (!instance) {
shareds.set(Class, (instance = new Class(initial_data)));
instance =
typeof Class.prototype === 'undefined'
? (Class as (init?: any) => M)(initial_data)
: new (Class as new (init?: any) => M)(initial_data);
shareds.set(Class, instance);
}

@@ -88,2 +94,3 @@ return instance;

function observe<T extends FC<P>, P>(Component: T) {
// Todo: check forwardRef support
return memo((props: P) => {

@@ -90,0 +97,0 @@ const forceUpdate = useForceUpdate();

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