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

simpler-state

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simpler-state - npm Package Compare versions

Comparing version 1.0.0-beta.3 to 1.0.0-beta.4

18

es/useEntity.js
import { useState, useCallback, useEffect } from 'react';
import { strictEqual } from './utils';
export var useEntity = function useEntity(entity, _temp) {
var _ref = _temp === void 0 ? {} : _temp,
_ref$transform = _ref.transform,
transform = _ref$transform === void 0 ? function (v) {
return v;
} : _ref$transform,
_ref$equality = _ref.equality,
equality = _ref$equality === void 0 ? strictEqual : _ref$equality;
export var useEntity = function useEntity(entity, transform, equality) {
if (transform === void 0) {
transform = function transform(v) {
return v;
};
}
if (equality === void 0) {
equality = strictEqual;
}
if (!(entity._subscribers instanceof Array)) throw new Error('Invalid entity.');

@@ -13,0 +15,0 @@ var computed = transform(entity._value);

@@ -0,9 +1,23 @@

/**
* Creates an entity and returns a direct reference
* that provides get() and set() functions
* @param initialValue - required default value
*/
export function entity<T = any>(initialValue: T): Entity<T>
export function useEntity<C extends unknown = T>(
/**
* Binds an entity to the component as a shared state
* @param entity - the entity reference
*/
export function useEntity<T>(entity: Entity<T>): T
/**
* Binds an entity to the component as a shared state
* @param entity - the entity reference
* @param transform - optional data transformation function
* @param equalityFn - optional custom equality function
*/
export function useEntity<T, C>(
entity: Entity<T>,
options?: {
transform?: (value: T) => C
equalityFn?: (a: any, b: any) => boolean
}
transform?: (value: T) => C,
equalityFn?: (a: any, b: any) => boolean
): C

@@ -10,0 +24,0 @@

@@ -10,11 +10,13 @@ "use strict";

var useEntity = function useEntity(entity, _temp) {
var _ref = _temp === void 0 ? {} : _temp,
_ref$transform = _ref.transform,
transform = _ref$transform === void 0 ? function (v) {
return v;
} : _ref$transform,
_ref$equality = _ref.equality,
equality = _ref$equality === void 0 ? _utils.strictEqual : _ref$equality;
var useEntity = function useEntity(entity, transform, equality) {
if (transform === void 0) {
transform = function transform(v) {
return v;
};
}
if (equality === void 0) {
equality = _utils.strictEqual;
}
if (!(entity._subscribers instanceof Array)) throw new Error('Invalid entity.');

@@ -21,0 +23,0 @@ var computed = transform(entity._value);

{
"name": "simpler-state",
"version": "1.0.0-beta.3",
"version": "1.0.0-beta.4",
"description": "The simplest app state management for React",

@@ -5,0 +5,0 @@ "keywords": [

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