🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

use-global-hook

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-global-hook - npm Package Compare versions

Comparing version

to
0.2.4

@@ -16,4 +16,4 @@ 'use strict';

var actions = getMappedActions(store, React, mapActions);
var originalHook = React.useState(Object.create(null))[1];
React.useEffect(newListenerEffect.newListenerEffect(store, mapState, originalHook), []); // eslint-disable-line
var originalHook = React.useState(state)[1];
React.useEffect(newListenerEffect.newListenerEffect(store, state, mapState, originalHook), []); // eslint-disable-line

@@ -20,0 +20,0 @@ return [state, actions];

@@ -7,21 +7,18 @@ 'use strict';

var newListenerEffect = function newListenerEffect(store, mapState, originalHook) {
return function () {
var newListener = {
oldState: {}
};
newListener.run = mapState ? function (newState) {
var mappedState = mapState(newState);
var newListenerEffect = function newListenerEffect(store, oldState, mapState, originalHook) {
var newListener = {
oldState: oldState
};
newListener.run = mapState ? function (newState) {
var mappedState = mapState(newState);
if (mappedState !== newListener.oldState) {
newListener.oldState = mappedState;
originalHook(mappedState);
}
} : originalHook;
newListener.run(store.state);
store.listeners.push(newListener);
return cleanUpListener.cleanUpListener(store, newListener);
};
if (mappedState !== newListener.oldState) {
newListener.oldState = mappedState;
originalHook(mappedState);
}
} : originalHook;
store.listeners.push(newListener);
return cleanUpListener.cleanUpListener(store, newListener);
};
exports.newListenerEffect = newListenerEffect;

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

/** @license UseGlobalHook v0.2.3
/** @license UseGlobalHook v0.2.4
*

@@ -3,0 +3,0 @@ * This source code is licensed under the MIT license found in the

@@ -8,4 +8,4 @@ import { newListenerEffect as newListenerEffect$1 } from './newListenerEffect.js';

const actions = getMappedActions(store, React, mapActions);
const originalHook = React.useState(Object.create(null))[1];
React.useEffect(newListenerEffect$1(store, mapState, originalHook), []); // eslint-disable-line
const originalHook = React.useState(state)[1];
React.useEffect(newListenerEffect$1(store, state, mapState, originalHook), []); // eslint-disable-line

@@ -12,0 +12,0 @@ return [state, actions];

import { cleanUpListener as cleanUpListener$1 } from './cleanUpListener.js';
const newListenerEffect = (store, mapState, originalHook) => () => {
const newListenerEffect = (store, oldState, mapState, originalHook) => {
const newListener = {
oldState: {}
oldState
};

@@ -15,3 +15,2 @@ newListener.run = mapState ? newState => {

} : originalHook;
newListener.run(store.state);
store.listeners.push(newListener);

@@ -18,0 +17,0 @@ return cleanUpListener$1(store, newListener);

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

/** @license UseGlobalHook v0.2.3
/** @license UseGlobalHook v0.2.4
*

@@ -3,0 +3,0 @@ * This source code is licensed under the MIT license found in the

{
"version": "0.2.3",
"version": "0.2.4",
"author": "andregardi",

@@ -4,0 +4,0 @@ "name": "use-global-hook",

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

/** @license UseGlobalHook v0.2.3
/** @license UseGlobalHook v0.2.4
*

@@ -74,19 +74,16 @@ * This source code is licensed under the MIT license found in the

var newListenerEffect = function newListenerEffect(store, mapState, originalHook) {
return function () {
var newListener = {
oldState: {}
};
newListener.run = mapState ? function (newState) {
var mappedState = mapState(newState);
var newListenerEffect = function newListenerEffect(store, oldState, mapState, originalHook) {
var newListener = {
oldState: oldState
};
newListener.run = mapState ? function (newState) {
var mappedState = mapState(newState);
if (mappedState !== newListener.oldState) {
newListener.oldState = mappedState;
originalHook(mappedState);
}
} : originalHook;
newListener.run(store.state);
store.listeners.push(newListener);
return cleanUpListener(store, newListener);
};
if (mappedState !== newListener.oldState) {
newListener.oldState = mappedState;
originalHook(mappedState);
}
} : originalHook;
store.listeners.push(newListener);
return cleanUpListener(store, newListener);
};

@@ -103,4 +100,4 @@

var actions = getMappedActions(store, React, mapActions);
var originalHook = React.useState(Object.create(null))[1];
React.useEffect(newListenerEffect(store, mapState, originalHook), []); // eslint-disable-line
var originalHook = React.useState(state)[1];
React.useEffect(newListenerEffect(store, state, mapState, originalHook), []); // eslint-disable-line

@@ -107,0 +104,0 @@ return [state, actions];

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

/** @license UseGlobalHook v0.2.3
/** @license UseGlobalHook v0.2.4
*

@@ -6,2 +6,2 @@ * This source code is licensed under the MIT license found in the

*/
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).UseGlobalHook=n()}(this,(function(){"use strict";function t(n){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(n)}function n(){return(n=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t}).apply(this,arguments)}function e(t,e,o){t.state=n({},t.state,e),t.runListeners(),o&&o()}function o(t,n,e,o){var r=e?e(t.state):t.state,i=function(t,n,e){return n.useMemo((function(){return e?e(t.actions):t.actions}),[e,t.actions])}(t,n,o),u=n.useState(Object.create(null))[1];return n.useEffect(function(t,n,e){return function(){var o={oldState:{}};return o.run=n?function(t){var r=n(t);r!==o.oldState&&(o.oldState=r,e(r))}:e,o.run(t.state),t.listeners.push(o),function(t,n){return function(){t.listeners=t.listeners.filter((function(t){return t!==n}))}}(t,o)}}(t,e,u),[]),[r,i]}var r=function(t){t.listeners.forEach((function(n){n.run(t.state)}))};var i=function(n,e){var o=e.setState;e.setState=function(t){t instanceof Function?(e.state=n(e.state,t),e.runListeners()):o(t)},function n(e,o){var r={};return Object.keys(o).forEach((function(i){if("function"==typeof o[i]){var u=o[i];o[i]=function(t,n){return function(){var e=n.apply(void 0,arguments);"function"==typeof e&&t.setState(e)}}(e,u)}"object"===t(o[i])&&(r[i]=n(e,o[i]))})),r}(e,e.actions)};return function(n,u,f,c){var s={state:u,listeners:[]};return s.setState=e.bind(null,s),s.runListeners=r.bind(null,s),s.actions=function n(e,o){var r={};return Object.keys(o).forEach((function(i){"function"==typeof o[i]&&(r[i]=o[i].bind(null,e)),"object"===t(o[i])&&(r[i]=n(e,o[i]))})),r}(s,f),function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(n instanceof Function)n(t);else{var e=n.Immer,o=n.initializer;e&&i(e,t),o&&o(t)}}(s,c),o.bind(null,s,n)}}));
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t="undefined"!=typeof globalThis?globalThis:t||self).UseGlobalHook=n()}(this,(function(){"use strict";function t(n){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(n)}function n(){return(n=Object.assign||function(t){for(var n=1;n<arguments.length;n++){var e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t}).apply(this,arguments)}function e(t,e,o){t.state=n({},t.state,e),t.runListeners(),o&&o()}function o(t,n,e,o){var r=e?e(t.state):t.state,i=function(t,n,e){return n.useMemo((function(){return e?e(t.actions):t.actions}),[e,t.actions])}(t,n,o),u=n.useState(r)[1];return n.useEffect(function(t,n,e,o){var r={oldState:n};return r.run=e?function(t){var n=e(t);n!==r.oldState&&(r.oldState=n,o(n))}:o,t.listeners.push(r),function(t,n){return function(){t.listeners=t.listeners.filter((function(t){return t!==n}))}}(t,r)}(t,r,e,u),[]),[r,i]}var r=function(t){t.listeners.forEach((function(n){n.run(t.state)}))};var i=function(n,e){var o=e.setState;e.setState=function(t){t instanceof Function?(e.state=n(e.state,t),e.runListeners()):o(t)},function n(e,o){var r={};return Object.keys(o).forEach((function(i){if("function"==typeof o[i]){var u=o[i];o[i]=function(t,n){return function(){var e=n.apply(void 0,arguments);"function"==typeof e&&t.setState(e)}}(e,u)}"object"===t(o[i])&&(r[i]=n(e,o[i]))})),r}(e,e.actions)};return function(n,u,f,c){var s={state:u,listeners:[]};return s.setState=e.bind(null,s),s.runListeners=r.bind(null,s),s.actions=function n(e,o){var r={};return Object.keys(o).forEach((function(i){"function"==typeof o[i]&&(r[i]=o[i].bind(null,e)),"object"===t(o[i])&&(r[i]=n(e,o[i]))})),r}(s,f),function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(n instanceof Function)n(t);else{var e=n.Immer,o=n.initializer;e&&i(e,t),o&&o(t)}}(s,c),o.bind(null,s,n)}}));