Socket
Socket
Sign inDemoInstall

reusable

Package Overview
Dependencies
42
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0-alpha.10 to 1.0.0-alpha.11

2

dist/index.js

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

var t,e=require("react"),r=(t=e)&&"object"==typeof t&&"default"in t?t.default:t,n=function(t){this.fn=t,this.subscribers=[],this.cachedValue=null};n.prototype.getValue=function(){return this.cachedValue},n.prototype.run=function(){return this.cachedValue=this.fn(),this.cachedValue},n.prototype.subscribe=function(t){var e=this;return this.subscribers=this.subscribers.concat([t]),function(){e.subscribers=e.subscribers.filter(function(e){return e!==t})}},n.prototype.notify=function(){var t=this;this.subscribers.forEach(function(e){return e(t.cachedValue)})};var u=function(){this.units=new Map,this.subscribers=[]};u.prototype.onUnitsChanged=function(t){var e=this;return this.subscribers=this.subscribers.concat([t]),function(){e.subscribers=e.subscribers.filter(function(e){return e!==t})}},u.prototype.createUnit=function(t){if(this.units.has(t))throw new Error("Unit already exist");var e=new n(t);this.units.set(t,e),this.notifyUnitsChanged()},u.prototype.getUnit=function(t){if(!this.units.has(t))throw new Error("Unit doesn't exist");return this.units.get(t)},u.prototype.notifyUnitsChanged=function(){this.subscribers.forEach(function(t){return t()})},u.prototype.getUnitsArray=function(){var t=[];return this.units.forEach(function(e){t.push(e)}),t};var i=new u,o=function(){return i},s=Object.prototype.hasOwnProperty;function c(t,e){return t===e?0!==t||0!==e||1/t==1/e:t!=t&&e!=e}function a(t,e){if(c(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(var u=0;u<r.length;u++)if(!s.call(e,r[u])||!c(t[r[u]],e[r[u]]))return!1;return!0}var f=r.createContext(o()),h=function(t){var r=t.unit;return r.run(),e.useEffect(function(){return r.notify()},[r.cachedValue]),null},l=function(){var t=e.useContext(f);if(void 0===t)throw new Error("Are you trying to use Reusable without a ReusableProvider?");return t},b=function(){var t=l(),n=e.useState(function(){return t.getUnitsArray()}),u=n[0],i=n[1];return e.useEffect(function(){return t.onUnitsChanged(function(){i(t.getUnitsArray())})},[]),r.createElement(r.Fragment,null,u.map(function(t,e){return r.createElement(h,{key:e,unit:t})}))},p=function(t){return t};exports.Unit=n,exports.Store=u,exports.createStore=function(){return new u},exports.getStore=o,exports.replaceStore=function(t){return i=t},exports.ReusableProvider=function(t){var e=t.children;return r.createElement(f.Provider,{value:o()},r.createElement(r.Fragment,null,r.createElement(b,null),e))},exports.reusable=function(t){return o().createUnit(t),function(r,n){return function(t,r,n){void 0===r&&(r=p),void 0===n&&(n=a);var u=l().getUnit(t),i=e.useState(function(){return r(u.getValue())}),o=i[0],s=i[1];return e.useEffect(function(){return u.subscribe(function(t){var e=r(t);n(e,o)||s(e)})},[u,o,r,n]),o}(t,r,n)}};
var t=require("react"),e=function(t){this.fn=t,this.subscribers=[],this.cachedValue=null};e.prototype.getValue=function(){return this.cachedValue},e.prototype.run=function(){return this.cachedValue=this.fn(),this.cachedValue},e.prototype.subscribe=function(t){var e=this;return this.subscribers=this.subscribers.concat([t]),function(){e.subscribers=e.subscribers.filter(function(e){return e!==t})}},e.prototype.notify=function(){var t=this;this.subscribers.forEach(function(e){return e(t.cachedValue)})};var r=function(){this.units=new Map,this.subscribers=[]};r.prototype.onUnitsChanged=function(t){var e=this;return this.subscribers=this.subscribers.concat([t]),function(){e.subscribers=e.subscribers.filter(function(e){return e!==t})}},r.prototype.createUnit=function(t){if(this.units.has(t))throw new Error("Unit already exist");var r=new e(t);this.units.set(t,r),this.notifyUnitsChanged()},r.prototype.getUnit=function(t){if(!this.units.has(t))throw new Error("Unit doesn't exist");return this.units.get(t)},r.prototype.notifyUnitsChanged=function(){this.subscribers.forEach(function(t){return t()})},r.prototype.getUnitsArray=function(){var t=[];return this.units.forEach(function(e){t.push(e)}),t};var n=new r,u=function(){return n},i=Object.prototype.hasOwnProperty;function o(t,e){return t===e?0!==t||0!==e||1/t==1/e:t!=t&&e!=e}function s(t,e){if(o(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var r=Object.keys(t),n=Object.keys(e);if(r.length!==n.length)return!1;for(var u=0;u<r.length;u++)if(!i.call(e,r[u])||!o(t[r[u]],e[r[u]]))return!1;return!0}var c=t.createContext(null),a=function(e){var r=e.unit;return r.run(),t.useEffect(function(){return r.notify()},[r.cachedValue]),null},f=function(){var e=t.useContext(c);if(null===e)throw new Error("Are you trying to use Reusable without a ReusableProvider?");return e},h=function(){var e=f(),r=t.useState(function(){return e.getUnitsArray()}),n=r[0],u=r[1];return t.useEffect(function(){return e.onUnitsChanged(function(){u(e.getUnitsArray())})},[]),t.createElement(t.Fragment,null,n.map(function(e,r){return t.createElement(a,{key:r,unit:e})}))},l=function(t){return t};exports.Unit=e,exports.Store=r,exports.createStore=function(){return new r},exports.getStore=u,exports.replaceStore=function(t){return n=t},exports.ReusableProvider=function(e){var r=e.children;return t.createElement(c.Provider,{value:u()},t.createElement(t.Fragment,null,t.createElement(h,null),r))},exports.reusable=function(e){return u().createUnit(e),function(r,n){return function(e,r,n){void 0===r&&(r=l),void 0===n&&(n=s);var u=f().getUnit(e),i=t.useState(function(){return r(u.getValue())}),o=i[0],c=i[1];return t.useEffect(function(){return u.subscribe(function(t){var e=r(t);n(e,o)||c(function(){return e})})},[u,o,r,n]),o}(e,r,n)}};
//# sourceMappingURL=index.js.map

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

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e(t.reusable={},t.react)}(this,function(t,e){var n="default"in e?e.default:e,r=function(t){this.fn=t,this.subscribers=[],this.cachedValue=null};r.prototype.getValue=function(){return this.cachedValue},r.prototype.run=function(){return this.cachedValue=this.fn(),this.cachedValue},r.prototype.subscribe=function(t){var e=this;return this.subscribers=this.subscribers.concat([t]),function(){e.subscribers=e.subscribers.filter(function(e){return e!==t})}},r.prototype.notify=function(){var t=this;this.subscribers.forEach(function(e){return e(t.cachedValue)})};var u=function(){this.units=new Map,this.subscribers=[]};u.prototype.onUnitsChanged=function(t){var e=this;return this.subscribers=this.subscribers.concat([t]),function(){e.subscribers=e.subscribers.filter(function(e){return e!==t})}},u.prototype.createUnit=function(t){if(this.units.has(t))throw new Error("Unit already exist");var e=new r(t);this.units.set(t,e),this.notifyUnitsChanged()},u.prototype.getUnit=function(t){if(!this.units.has(t))throw new Error("Unit doesn't exist");return this.units.get(t)},u.prototype.notifyUnitsChanged=function(){this.subscribers.forEach(function(t){return t()})},u.prototype.getUnitsArray=function(){var t=[];return this.units.forEach(function(e){t.push(e)}),t};var i=new u,o=function(){return i},s=Object.prototype.hasOwnProperty;function c(t,e){return t===e?0!==t||0!==e||1/t==1/e:t!=t&&e!=e}function a(t,e){if(c(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(var u=0;u<n.length;u++)if(!s.call(e,n[u])||!c(t[n[u]],e[n[u]]))return!1;return!0}var f=n.createContext(o()),h=function(t){var n=t.unit;return n.run(),e.useEffect(function(){return n.notify()},[n.cachedValue]),null},l=function(){var t=e.useContext(f);if(void 0===t)throw new Error("Are you trying to use Reusable without a ReusableProvider?");return t},b=function(){var t=l(),r=e.useState(function(){return t.getUnitsArray()}),u=r[0],i=r[1];return e.useEffect(function(){return t.onUnitsChanged(function(){i(t.getUnitsArray())})},[]),n.createElement(n.Fragment,null,u.map(function(t,e){return n.createElement(h,{key:e,unit:t})}))},p=function(t){return t};t.Unit=r,t.Store=u,t.createStore=function(){return new u},t.getStore=o,t.replaceStore=function(t){return i=t},t.ReusableProvider=function(t){var e=t.children;return n.createElement(f.Provider,{value:o()},n.createElement(n.Fragment,null,n.createElement(b,null),e))},t.reusable=function(t){return o().createUnit(t),function(n,r){return function(t,n,r){void 0===n&&(n=p),void 0===r&&(r=a);var u=l().getUnit(t),i=e.useState(function(){return n(u.getValue())}),o=i[0],s=i[1];return e.useEffect(function(){return u.subscribe(function(t){var e=n(t);r(e,o)||s(e)})},[u,o,n,r]),o}(t,n,r)}}});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e(t.reusable={},t.react)}(this,function(t,e){var n=function(t){this.fn=t,this.subscribers=[],this.cachedValue=null};n.prototype.getValue=function(){return this.cachedValue},n.prototype.run=function(){return this.cachedValue=this.fn(),this.cachedValue},n.prototype.subscribe=function(t){var e=this;return this.subscribers=this.subscribers.concat([t]),function(){e.subscribers=e.subscribers.filter(function(e){return e!==t})}},n.prototype.notify=function(){var t=this;this.subscribers.forEach(function(e){return e(t.cachedValue)})};var r=function(){this.units=new Map,this.subscribers=[]};r.prototype.onUnitsChanged=function(t){var e=this;return this.subscribers=this.subscribers.concat([t]),function(){e.subscribers=e.subscribers.filter(function(e){return e!==t})}},r.prototype.createUnit=function(t){if(this.units.has(t))throw new Error("Unit already exist");var e=new n(t);this.units.set(t,e),this.notifyUnitsChanged()},r.prototype.getUnit=function(t){if(!this.units.has(t))throw new Error("Unit doesn't exist");return this.units.get(t)},r.prototype.notifyUnitsChanged=function(){this.subscribers.forEach(function(t){return t()})},r.prototype.getUnitsArray=function(){var t=[];return this.units.forEach(function(e){t.push(e)}),t};var u=new r,i=function(){return u},o=Object.prototype.hasOwnProperty;function s(t,e){return t===e?0!==t||0!==e||1/t==1/e:t!=t&&e!=e}function c(t,e){if(s(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;var n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(var u=0;u<n.length;u++)if(!o.call(e,n[u])||!s(t[n[u]],e[n[u]]))return!1;return!0}var f=e.createContext(null),a=function(t){var n=t.unit;return n.run(),e.useEffect(function(){return n.notify()},[n.cachedValue]),null},h=function(){var t=e.useContext(f);if(null===t)throw new Error("Are you trying to use Reusable without a ReusableProvider?");return t},l=function(){var t=h(),n=e.useState(function(){return t.getUnitsArray()}),r=n[0],u=n[1];return e.useEffect(function(){return t.onUnitsChanged(function(){u(t.getUnitsArray())})},[]),e.createElement(e.Fragment,null,r.map(function(t,n){return e.createElement(a,{key:n,unit:t})}))},b=function(t){return t};t.Unit=n,t.Store=r,t.createStore=function(){return new r},t.getStore=i,t.replaceStore=function(t){return u=t},t.ReusableProvider=function(t){var n=t.children;return e.createElement(f.Provider,{value:i()},e.createElement(e.Fragment,null,e.createElement(l,null),n))},t.reusable=function(t){return i().createUnit(t),function(n,r){return function(t,n,r){void 0===n&&(n=b),void 0===r&&(r=c);var u=h().getUnit(t),i=e.useState(function(){return n(u.getValue())}),o=i[0],s=i[1];return e.useEffect(function(){return u.subscribe(function(t){var e=n(t);r(e,o)||s(function(){return e})})},[u,o,n,r]),o}(t,n,r)}}});
//# sourceMappingURL=index.umd.js.map
{
"name": "reusable",
"version": "1.0.0-alpha.10",
"version": "1.0.0-alpha.11",
"description": "",
"keywords": [],
"main": "dist/reusable.js",
"source": "src/index.js",
"main": "dist/index.js",
"source": "src/index.ts",
"unpkg": "dist/reusable.umd.js",
"types": "dist/index.d.ts",
"dependencies": {
"@babel/helper-module-imports": "^7.0.0",
"@types/react": "^16.8.19",
"babel-plugin-reusable": "^1.0.0-alpha.5"

@@ -22,6 +24,8 @@ },

"@babel/preset-react": "^7.0.0",
"@types/jest": "^24.0.13",
"@types/node": "^12.0.3",
"babel-plugin-macros": "^2.5.1",
"babel-plugin-tester": "^6.0.1",
"concurrently": "^4.1.0",
"jest": "^24.5.0",
"jest": "^24.8.0",
"lodash": "^4.17.11",

@@ -34,8 +38,9 @@ "microbundle": "^0.11.0",

"react-hooks-testing-library": "^0.5.0",
"react-test-renderer": "^16.8.6"
"react-test-renderer": "^16.8.6",
"ts-jest": "^24.0.2"
},
"scripts": {
"example": "parcel ./example/index.html --out-dir exampleDist",
"build": "microbundle --external all --jsx React.createElement",
"build:dev": "microbundle watch --external all --jsx React.createElement",
"build": "microbundle --external all --jsx react",
"build:dev": "microbundle watch --external all --jsx react",
"sandbox": "cd sandbox && npm start",

@@ -42,0 +47,0 @@ "dev": "concurrently 'npm run build:dev' 'npm run sandbox'",

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

[![Build Status](https://circleci.com/gh/reusablejs/reusable.svg?style=svg)](https://circleci.com/gh/reusablejs/reusable)
[![npm version](https://badge.fury.io/js/reusable.svg)](https://badge.fury.io/js/reusable)
Go here:

@@ -5,2 +8,5 @@ [https://reusablejs.github.io/reusable](https://reusablejs.github.io/reusable)

# tl;dr
Reusable is a library for sharing state and side-effects between components using hooks.
Just wrap your custom hooks with `reusable` and you're good to go.
```javascript

@@ -25,1 +31,7 @@ const useSomething = reusable(() => {

```
# What about hooks+Context
Using plain context has some drawbacks, that led us to write this library:
- When managing global state using Context in a large app, you will probably have many small, single-purpose providers. Soon enough you'll find a Provider wrapper hell.
- When you order the providers vertically, you can’t dynamically choose to depend on each other without changing the order, which might break things.
- Context doesn't support selectors, render bailout, or debouncing

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc