Socket
Socket
Sign inDemoInstall

react-hookstore

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hookstore - npm Package Compare versions

Comparing version 1.4.1 to 1.4.2

15

dist/react-hookstore.js

@@ -209,2 +209,7 @@ (function webpackUniversalModuleDefinition(root, factory) {

var name = identifier instanceof StoreInterface ? identifier.name : identifier;
if (!stores[name]) {
throw "Store with name ".concat(name, " does not exist");
}
return stores[name];

@@ -231,7 +236,7 @@ }

if (typeof name !== 'string') {
throw 'store name must be a string';
throw 'Store name must be a string';
}
if (stores[name]) {
throw 'store already exists';
throw "Store with name ".concat(name, " already exists");
}

@@ -276,3 +281,3 @@

} catch (e) {
throw 'store does not exist';
throw "Store with name ".concat(name, " does not exist");
}

@@ -289,6 +294,2 @@ }

if (!store) {
throw 'store does not exist';
}
var _useState = Object(react__WEBPACK_IMPORTED_MODULE_0__["useState"])(store.state),

@@ -295,0 +296,0 @@ _useState2 = _slicedToArray(_useState, 2),

@@ -1,1 +0,1 @@

!function(t){var e={};function s(r){if(e[r])return e[r].exports;var n=e[r]={i:r,l:!1,exports:{}};return t[r].call(n.exports,n,n.exports,s),n.l=!0,n.exports}s.m=t,s.c=e,s.d=function(t,e,r){s.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(t,e){if(1&e&&(t=s(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(s.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)s.d(r,n,function(e){return t[e]}.bind(null,n));return r},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="",s(s.s=1)}([function(t,e){t.exports=void 0},function(t,e,s){"use strict";s.r(e),s.d(e,"createStore",function(){return u}),s.d(e,"getStoreByName",function(){return c}),s.d(e,"useStore",function(){return f});var r=s(0);let n={},o={};const i=(t,e)=>e;class a{constructor(t,e,s){this.name=t,s?this.dispatch=e.setState:this.setState=e.setState,this.getState=(()=>e.state),this.subscribe=this.subscribe.bind(this)}subscribe(t){if(!t||"function"!=typeof t)throw`store.subscribe callback argument must be a function. got '${typeof t}' instead.`;if(!o[this.name].find(e=>e===t))return o[this.name].push(t),()=>{o[this.name]=o[this.name].filter(e=>e!==t)};console.warn("This callback is already subscribed to this store. skipping subscription")}setState(){console.warn(`[React Hookstore] Store ${this.name} uses a reducer to handle its state updates. use dispatch instead of setState`)}dispatch(){console.warn(`[React Hookstore] Store ${this.name} does not use a reducer to handle state updates. use setState instead of dispatch`)}}function u(t,e={},s=i){if("string"!=typeof t)throw"store name must be a string";if(n[t])throw"store already exists";const r={state:e,reducer:s,setState(e,s){this.state=this.reducer(this.state,e),this.setters.forEach(t=>t(this.state)),o[t].length&&o[t].forEach(t=>t(this.state,e)),"function"==typeof s&&s(this.state)},setters:[]};return r.setState=r.setState.bind(r),o[t]=[],r.public=new a(t,r,s!==i),n=Object.assign({},n,{[t]:r}),r.public}function c(t){try{return n[t].public}catch(t){throw"store does not exist"}}function f(t){const e=function(t){const e=t instanceof a?t.name:t;return n[e]}(t);if(!e)throw"store does not exist";const[s,o]=Object(r.useState)(e.state);return Object(r.useEffect)(()=>(e.setters.includes(o)||e.setters.push(o),()=>{e.setters=e.setters.filter(t=>t!==o)}),[]),[s,e.setState]}}]);
!function(t){var e={};function s(n){if(e[n])return e[n].exports;var r=e[n]={i:n,l:!1,exports:{}};return t[n].call(r.exports,r,r.exports,s),r.l=!0,r.exports}s.m=t,s.c=e,s.d=function(t,e,n){s.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(t,e){if(1&e&&(t=s(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(s.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)s.d(n,r,function(e){return t[e]}.bind(null,r));return n},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="",s(s.s=1)}([function(t,e){t.exports=void 0},function(t,e,s){"use strict";s.r(e),s.d(e,"createStore",function(){return u}),s.d(e,"getStoreByName",function(){return c}),s.d(e,"useStore",function(){return f});var n=s(0);let r={},o={};const i=(t,e)=>e;class a{constructor(t,e,s){this.name=t,s?this.dispatch=e.setState:this.setState=e.setState,this.getState=(()=>e.state),this.subscribe=this.subscribe.bind(this)}subscribe(t){if(!t||"function"!=typeof t)throw`store.subscribe callback argument must be a function. got '${typeof t}' instead.`;if(!o[this.name].find(e=>e===t))return o[this.name].push(t),()=>{o[this.name]=o[this.name].filter(e=>e!==t)};console.warn("This callback is already subscribed to this store. skipping subscription")}setState(){console.warn(`[React Hookstore] Store ${this.name} uses a reducer to handle its state updates. use dispatch instead of setState`)}dispatch(){console.warn(`[React Hookstore] Store ${this.name} does not use a reducer to handle state updates. use setState instead of dispatch`)}}function u(t,e={},s=i){if("string"!=typeof t)throw"Store name must be a string";if(r[t])throw`Store with name ${t} already exists`;const n={state:e,reducer:s,setState(e,s){this.state=this.reducer(this.state,e),this.setters.forEach(t=>t(this.state)),o[t].length&&o[t].forEach(t=>t(this.state,e)),"function"==typeof s&&s(this.state)},setters:[]};return n.setState=n.setState.bind(n),o[t]=[],n.public=new a(t,n,s!==i),r=Object.assign({},r,{[t]:n}),n.public}function c(t){try{return r[t].public}catch(e){throw`Store with name ${t} does not exist`}}function f(t){const e=function(t){const e=t instanceof a?t.name:t;if(!r[e])throw`Store with name ${e} does not exist`;return r[e]}(t),[s,o]=Object(n.useState)(e.state);return Object(n.useEffect)(()=>(e.setters.includes(o)||e.setters.push(o),()=>{e.setters=e.setters.filter(t=>t!==o)}),[]),[s,e.setState]}}]);
{
"name": "react-hookstore",
"version": "1.4.1",
"version": "1.4.2",
"description": "A state management library for react using the bleeding edge hooks feature",

@@ -5,0 +5,0 @@ "main": "dist/react-hookstore.js",

@@ -53,2 +53,5 @@ import { useState, useEffect } from 'react';

const name = identifier instanceof StoreInterface ? identifier.name : identifier;
if (!stores[name]) {
throw `Store with name ${name} does not exist`;
}
return stores[name];

@@ -71,6 +74,6 @@ }

if (typeof name !== 'string') {
throw 'store name must be a string';
throw 'Store name must be a string';
}
if (stores[name]) {
throw 'store already exists'
throw `Store with name ${name} already exists`;
}

@@ -109,3 +112,3 @@

} catch(e) {
throw 'store does not exist';
throw `Store with name ${name} does not exist`;
}

@@ -121,5 +124,2 @@ }

const store = getStoreByIdentifier(identifier);
if (!store) {
throw 'store does not exist';
}

@@ -126,0 +126,0 @@ const [ state, set ] = useState(store.state);

@@ -5,3 +5,3 @@

type ReducerType<TState> = (state: TState, payload: any) => TState;
type ReducerType<TState, TPayload = any> = (state: TState, payload: TPayload) => TState;

@@ -26,2 +26,4 @@ type SetStateType<TState> = (state: TState, callback?: StateCallback<TState>) => void;

export interface StateStoreInterface<TState> {
readonly name: string;
getState(): TState;
setState(state: TState, callback?: StateCallback<TState>): void;

@@ -45,2 +47,2 @@ }

export function useStore<TState>(store: ReducerStoreInterface<TState>): StoreDispatchHookType<TState>;
}
}

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