@stated-library/react
Version:
React bindings for [`Stated Libraries`](https://github.com/bradfordlemley/stated-library)
3 lines (2 loc) • 3.52 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("@stated-library/core");function n(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function r(t){return(r="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})(t)}function o(t){return(o="function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?function(t){return r(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":r(t)})(t)}function u(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function f(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function a(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),r.forEach(function(e){f(t,e,n[e])})}return t}function l(t,n){var r,o=t,u=e.getValue(n);return o.state=a({},o.state||{},u),{connect:function(){r=n.subscribe(function(t){Object.is(t,u)||(u=t,o.setState(a({},t)))})},disconnect:function(){r.unsubscribe(),o=null}}}function s(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=[],r=!0,o=!1,u=void 0;try{for(var c,i=t[Symbol.iterator]();!(r=(c=i.next()).done)&&(n.push(c.value),!e||n.length!==e);r=!0);}catch(t){o=!0,u=t}finally{try{r||null==i.return||i.return()}finally{if(o)throw u}}return n}(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}exports.connect=function(e){return function(r){var f,a,s;return a=f=function(f){function a(t){var n,r,i;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,a),r=this,(n=!(i=c(a).call(this,t))||"object"!==o(i)&&"function"!=typeof i?u(r):i).link=void 0,n.state=void 0,n.link=l(u(n),e),n}var s,y,b;return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&i(t,e)}(a,t.Component),s=a,(y=[{key:"componentDidMount",value:function(){this.link.connect()}},{key:"componentWillUnmount",value:function(){this.link.disconnect()}},{key:"render",value:function(){return t.createElement(r,Object.assign({},this.props,this.state))}}])&&n(s.prototype,y),b&&n(s,b),a}(),f.displayName="connect-sl(".concat((s=r).displayName||s.name||"Component",")"),a}},exports.link=l,exports.use=function(n){var r=t.useRef(void 0);if(void 0===r.current&&(r.current="function"==typeof n?n():n,!r.current))throw new Error("Invalid value$: ".concat(r.current));var o=r.current,u=s(t.useState(function(){return e.getValue(o)}),2),c=u[0],i=u[1];return t.useEffect(function(){var t=o.subscribe(i);return function(){return t.unsubscribe()}},[o]),c};
//# sourceMappingURL=index.production.js.map