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

react-singleton-hook

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-singleton-hook - npm Package Compare versions

Comparing version 1.0.12 to 2.0.14

es/components/SingletonHooksContainer.js

28

dist/react-singleton-hook.js

@@ -61,9 +61,9 @@ (function (global, factory) {

} else {
warning('Can not mount SingletonContainer on server side. ' + 'Did you manage to run useEffect on server? ' + 'Please mount SingletonContainer into your components tree manually.');
warning('Can not mount SingletonHooksContainer on server side. ' + 'Did you manage to run useEffect on server? ' + 'Please mount SingletonHooksContainer into your components tree manually.');
}
};
var singletonContainerMounted = false;
var singletonContainerRendered = false;
var singletonContainerMountedAutomatically = false;
var SingletonHooksContainerMounted = false;
var SingletonHooksContainerRendered = false;
var SingletonHooksContainerMountedAutomatically = false;
var mountQueue = [];

@@ -76,12 +76,12 @@

var mountIntoContainer = mountIntoContainerDefault;
var SingletonContainer = function SingletonContainer() {
singletonContainerRendered = true;
var SingletonHooksContainer = function SingletonHooksContainer() {
SingletonHooksContainerRendered = true;
React.useEffect(function () {
if (singletonContainerMounted) {
warning('SingletonContainer is mounted second time. ' + 'You should mount SingletonContainer before any other component and never unmount it.' + 'Alternatively, dont use SingletonContainer it at all, we will handle that for you.');
if (SingletonHooksContainerMounted) {
warning('SingletonHooksContainer is mounted second time. ' + 'You should mount SingletonHooksContainer before any other component and never unmount it.' + 'Alternatively, dont use SingletonHooksContainer it at all, we will handle that for you.');
}
singletonContainerMounted = true;
SingletonHooksContainerMounted = true;
return function () {
return warning('SingletonContainer is removed from DOM. its not supported, singleton hooks will stop updating.');
return warning('SingletonHooksContainer is removed from DOM. its not supported, singleton hooks will stop updating.');
};

@@ -110,5 +110,5 @@ }, []);

var addHook = function addHook(hook) {
if (!singletonContainerRendered && !singletonContainerMountedAutomatically) {
singletonContainerMountedAutomatically = true;
mount(SingletonContainer);
if (!SingletonHooksContainerRendered && !SingletonHooksContainerMountedAutomatically) {
SingletonHooksContainerMountedAutomatically = true;
mount(SingletonHooksContainer);
}

@@ -162,3 +162,3 @@

exports.SingletonContainer = SingletonContainer;
exports.SingletonHooksContainer = SingletonHooksContainer;
exports.singletonHook = singletonHook;

@@ -165,0 +165,0 @@

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

!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-dom"],e):e((n=n||self).ReactSingletonHook={},n.React,n.ReactDOM)}(this,(function(n,e,t){"use strict";var o="default"in e?e.default:e;function r(){return(r=Object.assign||function(n){for(var e=1;arguments.length>e;e++){var t=arguments[e];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o])}return n}).apply(this,arguments)}var u=function(n){var t=n.useHookBody,o=n.applyStateChange,r=e.useRef(n.initValue);if("function"!=typeof t)throw Error("function expected as hook body parameter. got "+typeof t);var u=t();return e.useLayoutEffect((function(){r.current!==u&&(r.current=u,o(u))}),[o,u]),null},i=function(n){console&&console.warn&&console.warn(n)},a=!1,c=!1,f=!1,l=[],s=function(n){l.push(n)},d=function(){c=!0,e.useEffect((function(){return a&&i("SingletonContainer is mounted second time. You should mount SingletonContainer before any other component and never unmount it.Alternatively, dont use SingletonContainer it at all, we will handle that for you."),a=!0,function(){return i("SingletonContainer is removed from DOM. its not supported, singleton hooks will stop updating.")}}),[]);var n=e.useState([]),t=n[0],f=n[1];return e.useEffect((function(){s=function(n){return f((function(e){return[].concat(e,[n])}))},f(l)}),[]),o.createElement(o.Fragment,null,t.map((function(n,e){return o.createElement(u,r({},n,{key:e}))})))},p=function(n){var e;c||f||(f=!0,e=d,window&&window.document?t.render(o.createElement(e,null),window.document.createElement("div")):i("Can not mount SingletonContainer on server side. Did you manage to run useEffect on server? Please mount SingletonContainer into your components tree manually.")),s(n)};n.SingletonContainer=d,n.singletonHook=function(n,o){var r=!1,u=n,i=[],a=function(n){u=n,t.unstable_batchedUpdates((function(){return i.forEach((function(e){return e(n)}))}))};return function(){var t=e.useState(u),c=t[0],f=t[1];return r||(r=!0,p({initValue:n,useHookBody:o,applyStateChange:a})),e.useEffect((function(){return i.push(f),u!==c&&f(u),function(){i.splice(i.indexOf(f),1)}}),[]),c}},Object.defineProperty(n,"__esModule",{value:!0})}));
!function(n,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("react-dom")):"function"==typeof define&&define.amd?define(["exports","react","react-dom"],e):e((n=n||self).ReactSingletonHook={},n.React,n.ReactDOM)}(this,(function(n,e,t){"use strict";var o="default"in e?e.default:e;function r(){return(r=Object.assign||function(n){for(var e=1;arguments.length>e;e++){var t=arguments[e];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(n[o]=t[o])}return n}).apply(this,arguments)}var u=function(n){var t=n.useHookBody,o=n.applyStateChange,r=e.useRef(n.initValue);if("function"!=typeof t)throw Error("function expected as hook body parameter. got "+typeof t);var u=t();return e.useLayoutEffect((function(){r.current!==u&&(r.current=u,o(u))}),[o,u]),null},i=function(n){console&&console.warn&&console.warn(n)},a=!1,c=!1,f=!1,s=[],l=function(n){s.push(n)},d=function(){c=!0,e.useEffect((function(){return a&&i("SingletonHooksContainer is mounted second time. You should mount SingletonHooksContainer before any other component and never unmount it.Alternatively, dont use SingletonHooksContainer it at all, we will handle that for you."),a=!0,function(){return i("SingletonHooksContainer is removed from DOM. its not supported, singleton hooks will stop updating.")}}),[]);var n=e.useState([]),t=n[0],f=n[1];return e.useEffect((function(){l=function(n){return f((function(e){return[].concat(e,[n])}))},f(s)}),[]),o.createElement(o.Fragment,null,t.map((function(n,e){return o.createElement(u,r({},n,{key:e}))})))},p=function(n){var e;c||f||(f=!0,e=d,window&&window.document?t.render(o.createElement(e,null),window.document.createElement("div")):i("Can not mount SingletonHooksContainer on server side. Did you manage to run useEffect on server? Please mount SingletonHooksContainer into your components tree manually.")),l(n)};n.SingletonHooksContainer=d,n.singletonHook=function(n,o){var r=!1,u=n,i=[],a=function(n){u=n,t.unstable_batchedUpdates((function(){return i.forEach((function(e){return e(n)}))}))};return function(){var t=e.useState(u),c=t[0],f=t[1];return r||(r=!0,p({initValue:n,useHookBody:o,applyStateChange:a})),e.useEffect((function(){return i.push(f),u!==c&&f(u),function(){i.splice(i.indexOf(f),1)}}),[]),c}},Object.defineProperty(n,"__esModule",{value:!0})}));
import { singletonHook } from './singletonHook';
import { SingletonContainer } from './components/SingletonContainer';
export { singletonHook, SingletonContainer };
import { SingletonHooksContainer } from './components/SingletonHooksContainer';
export { singletonHook, SingletonHooksContainer };
import { useEffect, useState } from 'react';
import { addHook } from './components/SingletonContainer';
import { addHook } from './components/SingletonHooksContainer';
import { batch } from './utils/env';

@@ -4,0 +4,0 @@ export var singletonHook = function singletonHook(initValue, useHookBody) {

@@ -13,4 +13,4 @@ import React from 'react';

} else {
warning('Can not mount SingletonContainer on server side. ' + 'Did you manage to run useEffect on server? ' + 'Please mount SingletonContainer into your components tree manually.');
warning('Can not mount SingletonHooksContainer on server side. ' + 'Did you manage to run useEffect on server? ' + 'Please mount SingletonHooksContainer into your components tree manually.');
}
};

@@ -8,3 +8,3 @@ /* eslint-disable import/no-unresolved */

export var mount = function mount(C) {
warning('Can not mount SingletonContainer with react native.' + 'Please mount SingletonContainer into your components tree manually.');
warning('Can not mount SingletonHooksContainer with react native.' + 'Please mount SingletonHooksContainer into your components tree manually.');
};

@@ -9,4 +9,4 @@ "use strict";

var _SingletonContainer = require("./components/SingletonContainer");
var _SingletonHooksContainer = require("./components/SingletonHooksContainer");
exports.SingletonContainer = _SingletonContainer.SingletonContainer;
exports.SingletonHooksContainer = _SingletonHooksContainer.SingletonHooksContainer;

@@ -8,3 +8,3 @@ "use strict";

var _SingletonContainer = require("./components/SingletonContainer");
var _SingletonHooksContainer = require("./components/SingletonHooksContainer");

@@ -34,3 +34,3 @@ var _env = require("./utils/env");

mounted = true;
(0, _SingletonContainer.addHook)({
(0, _SingletonHooksContainer.addHook)({
initValue: initValue,

@@ -37,0 +37,0 @@ useHookBody: useHookBody,

@@ -25,3 +25,3 @@ "use strict";

} else {
(0, _warning.warning)('Can not mount SingletonContainer on server side. ' + 'Did you manage to run useEffect on server? ' + 'Please mount SingletonContainer into your components tree manually.');
(0, _warning.warning)('Can not mount SingletonHooksContainer on server side. ' + 'Did you manage to run useEffect on server? ' + 'Please mount SingletonHooksContainer into your components tree manually.');
}

@@ -28,0 +28,0 @@ };

@@ -18,5 +18,5 @@ "use strict";

var mount = function mount(C) {
(0, _warning.warning)('Can not mount SingletonContainer with react native.' + 'Please mount SingletonContainer into your components tree manually.');
(0, _warning.warning)('Can not mount SingletonHooksContainer with react native.' + 'Please mount SingletonHooksContainer into your components tree manually.');
};
exports.mount = mount;
{
"name": "react-singleton-hook",
"version": "1.0.12",
"version": "2.0.14",
"description": "Share custom hook state across all components",

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

import { singletonHook } from './singletonHook';
import { SingletonContainer } from './components/SingletonContainer';
import { SingletonHooksContainer } from './components/SingletonHooksContainer';
export {
singletonHook,
SingletonContainer
SingletonHooksContainer
};
import { useEffect, useState } from 'react';
import { addHook } from './components/SingletonContainer';
import { addHook } from './components/SingletonHooksContainer';
import { batch } from './utils/env';

@@ -4,0 +4,0 @@

@@ -11,6 +11,6 @@ import React from 'react';

} else {
warning('Can not mount SingletonContainer on server side. '
warning('Can not mount SingletonHooksContainer on server side. '
+ 'Did you manage to run useEffect on server? '
+ 'Please mount SingletonContainer into your components tree manually.');
+ 'Please mount SingletonHooksContainer into your components tree manually.');
}
};

@@ -7,4 +7,4 @@ /* eslint-disable import/no-unresolved */

export const mount = C => {
warning('Can not mount SingletonContainer with react native.'
+ 'Please mount SingletonContainer into your components tree manually.');
warning('Can not mount SingletonHooksContainer with react native.'
+ 'Please mount SingletonHooksContainer into your components tree manually.');
};
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