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 3.0.206 to 3.1.1

14

dist/react-singleton-hook.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom')) :
typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom'], factory) :
(global = global || self, factory(global.ReactSingletonHook = {}, global.React, global.ReactDOM));
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactSingletonHook = {}, global.React, global.ReactDOM));
}(this, (function (exports, React, reactDom) { 'use strict';
var React__default = 'default' in React ? React['default'] : React;
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
function _extends() {

@@ -59,3 +61,3 @@ _extends = Object.assign || function (target) {

if (window && window.document) {
reactDom.render( /*#__PURE__*/React__default.createElement(C, null), window.document.createElement('div'));
reactDom.render( /*#__PURE__*/React__default['default'].createElement(C, null), window.document.createElement('div'));
} else {

@@ -85,3 +87,3 @@ warning('Can not mount SingletonHooksContainer on server side. ' + 'Did you manage to run useEffect on server? ' + 'Please mount SingletonHooksContainer into your components tree manually.');

return function () {
return warning('SingletonHooksContainer 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.');
};

@@ -103,4 +105,4 @@ }, []);

}, []);
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, hooks.map(function (h, i) {
return /*#__PURE__*/React__default.createElement(SingleItemContainer, _extends({}, h, {
return /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, null, hooks.map(function (h, i) {
return /*#__PURE__*/React__default['default'].createElement(SingleItemContainer, _extends({}, h, {
key: i

@@ -107,0 +109,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,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)},m=function(n,o){var r=!1,u=!1,i=void 0,a=[],c=function(n){i=n,t.unstable_batchedUpdates((function(){return a.forEach((function(e){return e(n)}))}))},f=function(){return u||(i="function"==typeof n?n():n,u=!0),i};return function(){var t=e.useState(f),u=t[0],s=t[1];return e.useEffect((function(){return r||(r=!0,p({initValue:n,useHookBody:o,applyStateChange:c})),a.push(s),i!==u&&s(i),function(){a.splice(a.indexOf(s),1)}}),[]),u}},y={singletonHook:m,SingletonHooksContainer:d};n.SingletonHooksContainer=d,n.default=y,n.singletonHook=m,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="undefined"!=typeof globalThis?globalThis:n||self).ReactSingletonHook={},n.React,n.ReactDOM)}(this,(function(n,e,t){"use strict";function o(n){return n&&"object"==typeof n&&"default"in n?n:{default:n}}var r=o(e);function u(){return(u=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 i=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},a=function(n){console&&console.warn&&console.warn(n)},f=!1,c=!1,l=!1,s=[],d=function(n){s.push(n)},p=function(){c=!0,e.useEffect((function(){return f&&a("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."),f=!0,function(){return a("SingletonHooksContainer is removed from DOM. its not supported, singleton hooks will stop updating.")}}),[]);var n=e.useState([]),t=n[0],o=n[1];return e.useEffect((function(){d=function(n){return o((function(e){return[].concat(e,[n])}))},o(s)}),[]),r.default.createElement(r.default.Fragment,null,t.map((function(n,e){return r.default.createElement(i,u({},n,{key:e}))})))},m=function(n){var e;c||l||(l=!0,e=p,window&&window.document?t.render(r.default.createElement(e,null),window.document.createElement("div")):a("Can not mount SingletonHooksContainer on server side. Did you manage to run useEffect on server? Please mount SingletonHooksContainer into your components tree manually.")),d(n)},y=function(n,o){var r=!1,u=!1,i=void 0,a=[],f=function(n){i=n,t.unstable_batchedUpdates((function(){return a.forEach((function(e){return e(n)}))}))},c=function(){return u||(i="function"==typeof n?n():n,u=!0),i};return function(){var t=e.useState(c),u=t[0],l=t[1];return e.useEffect((function(){return r||(r=!0,m({initValue:n,useHookBody:o,applyStateChange:f})),a.push(l),i!==u&&l(i),function(){a.splice(a.indexOf(l),1)}}),[]),u}},g={singletonHook:y,SingletonHooksContainer:p};n.SingletonHooksContainer=p,n.default=g,n.singletonHook=y,Object.defineProperty(n,"__esModule",{value:!0})}));
{
"name": "react-singleton-hook",
"version": "3.0.206",
"version": "3.1.1",
"description": "Share custom hook state across all components",

@@ -37,3 +37,3 @@ "keywords": [

"peerDependencies": {
"react": "^16.13.1"
"react": "15 - 17"
},

@@ -50,34 +50,34 @@ "peerDependenciesMeta": {

"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.6",
"@babel/plugin-proposal-object-rest-spread": "^7.9.6",
"@babel/plugin-transform-react-display-name": "^7.8.3",
"@babel/plugin-transform-react-jsx": "^7.9.4",
"@babel/preset-env": "^7.9.6",
"@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-replace": "^2.3.2",
"@testing-library/jest-dom": "^5.7.0",
"@testing-library/jest-native": "^3.1.0",
"@testing-library/react": "^10.0.4",
"@testing-library/react-hooks": "^3.2.1",
"@testing-library/react-native": "^5.0.3",
"@babel/cli": "^7.13.0",
"@babel/core": "^7.13.1",
"@babel/plugin-proposal-object-rest-spread": "^7.13.0",
"@babel/plugin-transform-react-display-name": "^7.12.13",
"@babel/plugin-transform-react-jsx": "^7.12.17",
"@babel/preset-env": "^7.13.5",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.2.0",
"@rollup/plugin-replace": "^2.4.1",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/jest-native": "^3.4.3",
"@testing-library/react": "^11.2.5",
"@testing-library/react-hooks": "^5.0.3",
"@testing-library/react-native": "^7.1.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.0.1",
"cross-env": "^7.0.2",
"babel-jest": "^26.6.3",
"cross-env": "^7.0.3",
"es3ify": "^0.2.2",
"eslint": "^7.0.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-react": "^7.19.0",
"eslint-plugin-react-hooks": "^4.0.0",
"eslint": "^7.20.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"glob": "^7.1.6",
"jest": "^26.0.1",
"jest": "^26.6.3",
"react": "^16.8.6",
"react-dom": "^16.13.1",
"react-native": "^0.62.2",
"react-test-renderer": "^16.13.1",
"react-dom": "^17.0.1",
"react-native": "^0.63.4",
"react-test-renderer": "^17.0.1",
"rimraf": "^3.0.2",
"rollup": "^2.8.2",
"rollup": "^2.39.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-terser": "^5.3.0"
"rollup-plugin-terser": "^7.0.2"
},

@@ -84,0 +84,0 @@ "browserify": {

@@ -28,7 +28,7 @@ React Singleton Hook

## What is a singleton hook
- Singleton hooks very similar to React Context in terms of functionality. Each singleton hook has s body,
- Singleton hooks very similar to React Context in terms of functionality. Each singleton hook has a body,
you might think of it as of Context Provider body. Hook has a return value, it's similar to the value provided by context.
Using a singleton hook from a component is like consuming a context.
- Singleton hooks are lazy. the body is not executed until the hook is called by some component or other hook.
- Singleton hooks are lazy. The body is not executed until the hook is called by some component or other hook.
Once loaded, the hook body remains loaded forever.

@@ -258,3 +258,3 @@ If you want to eager-load some Singleton hooks, use them at the top-level component of your App.

#### example: subscribe components to pre-existing get/set data module
#### example: subscribe components to pre-existing get/set data module

@@ -261,0 +261,0 @@ ```javascript

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