react-containerized-state
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,1 +0,1 @@ | ||
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var u=Object.getOwnPropertyDescriptor(t,r);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,u)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});var React=__importStar(require("react")),use_lazy_initialized_value_1=__importDefault(require("./use-lazy-initialized-value")),use_sync_external_store_1=require("./use-sync-external-store"),Container=function(){function e(e){Object.defineProperty(this,"_value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_subscribers",{enumerable:!0,configurable:!0,writable:!0,value:void 0});var t="function"==typeof e?e():e;this._value=t,this._subscribers=new Set}return Object.defineProperty(e.prototype,"subscribe",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this._subscribers.add(e);return function(){t._subscribers.delete(e)}}}),Object.defineProperty(e.prototype,"selectedSubscribe",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r){var i=this,u={type:"SELECTED_SUBSCRIBE_ENTRY",selector:e,subscribeCallback:t,isEqual:r};this._subscribers.add(u);return function(){i._subscribers.delete(u)}}}),Object.defineProperty(e.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._value}}),Object.defineProperty(e.prototype,"updateValue",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this._value;this._value=e,this._subscribers.forEach((function(r){var i;if("type"in r){if("SELECTED_SUBSCRIBE_ENTRY"!==r.type)return;var u=r.selector,n=r.subscribeCallback,a=r.isEqual,l=u(e),o=u(t);if(!!(null!==(i=null==a?void 0:a(o,l))&&void 0!==i?i:Object.is(l,o)))return;n(l)}else{if(Object.is(t,e))return;r(e)}}))}}),Object.defineProperty(e.prototype,"useValue",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this,t=(0,use_lazy_initialized_value_1.default)((function(){return e.subscribe.bind(e)})),r=(0,use_lazy_initialized_value_1.default)((function(){return e.getValue.bind(e)})),i=r;return(0,use_sync_external_store_1.useSyncExternalStore)(t,r,i)}}),Object.defineProperty(e.prototype,"useValueSelector",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this,i=(0,use_lazy_initialized_value_1.default)((function(){return r.subscribe.bind(r)})),u=(0,use_lazy_initialized_value_1.default)((function(){return r.getValue.bind(r)})),n=u;return(0,use_sync_external_store_1.useSyncExternalStoreWithSelector)(i,u,n,e,t)}}),Object.defineProperty(e.prototype,"useUpdateValue",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;return React.useCallback((function(t){var r="function"==typeof t?t(e._value):t;e.updateValue(r)}),[])}}),e}();exports.default=Container; | ||
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r);var u=Object.getOwnPropertyDescriptor(t,r);u&&!("get"in u?!t.__esModule:u.writable||u.configurable)||(u={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,i,u)}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&__createBinding(t,e,r);return __setModuleDefault(t,e),t},__importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});var React=__importStar(require("react")),use_lazy_initialized_value_1=__importDefault(require("./use-lazy-initialized-value")),use_sync_external_store_1=require("./use-sync-external-store"),Container=function(){function e(e){Object.defineProperty(this,"_value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_subscribers",{enumerable:!0,configurable:!0,writable:!0,value:void 0});var t="function"==typeof e?e():e;this._value=t,this._subscribers=new Set}return Object.defineProperty(e.prototype,"subscribe",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this,r={type:"default",subscribeCallback:e};this._subscribers.add(r);return function(){t._subscribers.delete(r)}}}),Object.defineProperty(e.prototype,"selectedSubscribe",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r){var i=this,u={type:"selected",selector:e,subscribeCallback:t,isEqual:r};this._subscribers.add(u);return function(){i._subscribers.delete(u)}}}),Object.defineProperty(e.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._value}}),Object.defineProperty(e.prototype,"updateValue",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this._value;this._value=e,this._subscribers.forEach((function(r){var i;if("default"===r.type){if(Object.is(t,e))return;r.subscribeCallback(e)}else if("selected"===r.type){var u=r.selector,a=r.subscribeCallback,n=r.isEqual,l=u(e),s=u(t);if(!!(null!==(i=null==n?void 0:n(s,l))&&void 0!==i?i:Object.is(l,s)))return;a(l)}}))}}),Object.defineProperty(e.prototype,"useValue",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this,t=(0,use_lazy_initialized_value_1.default)((function(){return e.subscribe.bind(e)})),r=(0,use_lazy_initialized_value_1.default)((function(){return e.getValue.bind(e)})),i=r;return(0,use_sync_external_store_1.useSyncExternalStore)(t,r,i)}}),Object.defineProperty(e.prototype,"useValueSelector",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this,i=(0,use_lazy_initialized_value_1.default)((function(){return r.subscribe.bind(r)})),u=(0,use_lazy_initialized_value_1.default)((function(){return r.getValue.bind(r)})),a=u;return(0,use_sync_external_store_1.useSyncExternalStoreWithSelector)(i,u,a,e,t)}}),Object.defineProperty(e.prototype,"useUpdateValue",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;return React.useCallback((function(t){var r="function"==typeof t?t(e._value):t;e.updateValue(r)}),[])}}),e}();exports.default=Container; |
@@ -1,1 +0,1 @@ | ||
import*as e from"react";import r from"./use-lazy-initialized-value";import{useSyncExternalStore as t,useSyncExternalStoreWithSelector as u}from"./use-sync-external-store";var i=function(){function i(e){Object.defineProperty(this,"_value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_subscribers",{enumerable:!0,configurable:!0,writable:!0,value:void 0});var r="function"==typeof e?e():e;this._value=r,this._subscribers=new Set}return Object.defineProperty(i.prototype,"subscribe",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var r=this;this._subscribers.add(e);return function(){r._subscribers.delete(e)}}}),Object.defineProperty(i.prototype,"selectedSubscribe",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r,t){var u=this,i={type:"SELECTED_SUBSCRIBE_ENTRY",selector:e,subscribeCallback:r,isEqual:t};this._subscribers.add(i);return function(){u._subscribers.delete(i)}}}),Object.defineProperty(i.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._value}}),Object.defineProperty(i.prototype,"updateValue",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var r=this._value;this._value=e,this._subscribers.forEach((function(t){var u;if("type"in t){if("SELECTED_SUBSCRIBE_ENTRY"!==t.type)return;var i=t.selector,n=t.subscribeCallback,a=t.isEqual,l=i(e),b=i(r);if(!!(null!==(u=null==a?void 0:a(b,l))&&void 0!==u?u:Object.is(l,b)))return;n(l)}else{if(Object.is(r,e))return;t(e)}}))}}),Object.defineProperty(i.prototype,"useValue",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this,u=r((function(){return e.subscribe.bind(e)})),i=r((function(){return e.getValue.bind(e)}));return t(u,i,i)}}),Object.defineProperty(i.prototype,"useValueSelector",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var i=this,n=r((function(){return i.subscribe.bind(i)})),a=r((function(){return i.getValue.bind(i)}));return u(n,a,a,e,t)}}),Object.defineProperty(i.prototype,"useUpdateValue",{enumerable:!1,configurable:!0,writable:!0,value:function(){var r=this;return e.useCallback((function(e){var t="function"==typeof e?e(r._value):e;r.updateValue(t)}),[])}}),i}();export default i; | ||
import*as e from"react";import r from"./use-lazy-initialized-value";import{useSyncExternalStore as t,useSyncExternalStoreWithSelector as u}from"./use-sync-external-store";var i=function(){function i(e){Object.defineProperty(this,"_value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_subscribers",{enumerable:!0,configurable:!0,writable:!0,value:void 0});var r="function"==typeof e?e():e;this._value=r,this._subscribers=new Set}return Object.defineProperty(i.prototype,"subscribe",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var r=this,t={type:"default",subscribeCallback:e};this._subscribers.add(t);return function(){r._subscribers.delete(t)}}}),Object.defineProperty(i.prototype,"selectedSubscribe",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r,t){var u=this,i={type:"selected",selector:e,subscribeCallback:r,isEqual:t};this._subscribers.add(i);return function(){u._subscribers.delete(i)}}}),Object.defineProperty(i.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._value}}),Object.defineProperty(i.prototype,"updateValue",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var r=this._value;this._value=e,this._subscribers.forEach((function(t){var u;if("default"===t.type){if(Object.is(r,e))return;t.subscribeCallback(e)}else if("selected"===t.type){var i=t.selector,a=t.subscribeCallback,n=t.isEqual,l=i(e),b=i(r);if(!!(null!==(u=null==n?void 0:n(b,l))&&void 0!==u?u:Object.is(l,b)))return;a(l)}}))}}),Object.defineProperty(i.prototype,"useValue",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this,u=r((function(){return e.subscribe.bind(e)})),i=r((function(){return e.getValue.bind(e)}));return t(u,i,i)}}),Object.defineProperty(i.prototype,"useValueSelector",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var i=this,a=r((function(){return i.subscribe.bind(i)})),n=r((function(){return i.getValue.bind(i)}));return u(a,n,n,e,t)}}),Object.defineProperty(i.prototype,"useUpdateValue",{enumerable:!1,configurable:!0,writable:!0,value:function(){var r=this;return e.useCallback((function(e){var t="function"==typeof e?e(r._value):e;r.updateValue(t)}),[])}}),i}();export default i; |
@@ -7,3 +7,3 @@ export type CallableFunction<TArgs extends any[] = [], TReturn = void> = (...args: TArgs) => TReturn; | ||
export type SelectedSubscribeEntry<T, P> = { | ||
type: "SELECTED_SUBSCRIBE_ENTRY"; | ||
type: "selected"; | ||
subscribeCallback: SubscribeCallback<P>; | ||
@@ -13,2 +13,7 @@ selector: ValueSelector<T, P>; | ||
}; | ||
export type DefaultSubscribeEntry<T> = { | ||
type: "default"; | ||
subscribeCallback: SubscribeCallback<T>; | ||
}; | ||
export type SubscribeEntry<T> = DefaultSubscribeEntry<T> | SelectedSubscribeEntry<T, any>; | ||
export type ContainerInitializer<T> = T | CallableFunction<[], T>; |
@@ -7,3 +7,3 @@ export type CallableFunction<TArgs extends any[] = [], TReturn = void> = (...args: TArgs) => TReturn; | ||
export type SelectedSubscribeEntry<T, P> = { | ||
type: "SELECTED_SUBSCRIBE_ENTRY"; | ||
type: "selected"; | ||
subscribeCallback: SubscribeCallback<P>; | ||
@@ -13,2 +13,7 @@ selector: ValueSelector<T, P>; | ||
}; | ||
export type DefaultSubscribeEntry<T> = { | ||
type: "default"; | ||
subscribeCallback: SubscribeCallback<T>; | ||
}; | ||
export type SubscribeEntry<T> = DefaultSubscribeEntry<T> | SelectedSubscribeEntry<T, any>; | ||
export type ContainerInitializer<T> = T | CallableFunction<[], T>; |
{ | ||
"name": "react-containerized-state", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Fast and minimal state container which can be used and shared across React or non-React components.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -170,2 +170,5 @@ # react-containerized-state | ||
const valueOfB = complexState.useValueSelector(value => value.b); | ||
// Or subscribe to a new computed value | ||
const computedValue = complexState.useValueSelector(value => value.a * 2 + Number(value.b)); | ||
``` | ||
@@ -172,0 +175,0 @@ |
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
26902
177
266