simpler-state
Advanced tools
Comparing version 1.0.0-beta.3 to 1.0.0-beta.4
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": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15428
277