hermes-io 2.10.81 → 2.11.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
function _array_like_to_array(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=Array(e);t<e;t++)n[t]=r[t];return n}function _extends(){return(_extends=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}function _create_for_of_iterator_helper_loose(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return _array_like_to_array(r,void 0);var t=Object.prototype.toString.call(r).slice(8,-1);if("Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return _array_like_to_array(r,void 0)}}(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var n=0;return function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}}}throw TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}import{useState as r,useRef as
|
|
1
|
+
function _array_like_to_array(r,e){(null==e||e>r.length)&&(e=r.length);for(var t=0,n=Array(e);t<e;t++)n[t]=r[t];return n}function _extends(){return(_extends=Object.assign||function(r){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(r[n]=t[n])}return r}).apply(this,arguments)}function _create_for_of_iterator_helper_loose(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,e){if(r){if("string"==typeof r)return _array_like_to_array(r,void 0);var t=Object.prototype.toString.call(r).slice(8,-1);if("Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return _array_like_to_array(r,void 0)}}(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var n=0;return function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}}}throw TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}import{useState as r,useEffect as e,useRef as t,useCallback as n}from"react";import{useObserver as o}from"./useObserver";import{MicroStore as a}from"../store/store";var randomId=function(){var r,e;return(null==(e=crypto)?void 0:null==(r=e.randomUUID)?void 0:r.call(e))||Math.random().toString(36).substring(2,16)};export var useMutations=function(i){void 0===i&&(i={});var l,u=i.events,s=void 0===u?[]:u,v=i.onChange,c=i.store,d=i.id,f=i.initialState,_=r(randomId()),p=(_[0],_[1]),y=t({id:Error().stack,state:_extends({},void 0===f?{}:f),events:[],onEvent:function(r,e){var t=y.current.events;t.some(function(e){return e.event===r})||t.push({event:r,onChange:e})}}),m=function(r){return i.noUpdate=r},h=function(r,e,t,n){var o=!r,a=!1;if(null==r||null==(l=r.forEach)||l.call(r,function(r){if(r===i.id){a=!0;var o,l=null!=(o=null==n?void 0:n(e,t,m,y.current.state))?o:{};i.noUpdate&&(l={}),y.current.state=_extends({},y.current.state,l)}}),o){var l,u,s=null!=(u=null==n?void 0:n(e,t,m,y.current.state))?u:{};i.noUpdate&&(s={}),y.current.state=_extends({},y.current.state,s)}!0!==i.noUpdate&&!1!==a&&p(randomId())},b=n(function(r,e){var t=null==(i=r.value)?void 0:null==(a=i.payload)?void 0:a.value,n=null==(l=r.value)?void 0:l.targets,o=null==(u=y.current)?void 0:u.events;if(o.length>0){for(var a,i,l,u,c,d=_create_for_of_iterator_helper_loose(o);!(c=d()).done;){var f=c.value;r.value.type===f.event&&h(n,t,e,f.onChange)}return}for(var _,p=_create_for_of_iterator_helper_loose(s);!(_=p()).done;){var m=_.value;r.value.type===m&&h(n,t,e,v)}},[s,null==(l=y.current)?void 0:l.events]);return e(function(){var r=null!=a&&"undefined"!=typeof Symbol&&a[Symbol.hasInstance]?!!a[Symbol.hasInstance](c):c instanceof a;if(r){var e=y.current.id;b.id=e;var t=c.has(d);c.hasListener(e)||c.registerListener(d,b),t&&!c.get(d).observer.has(e)&&c.subscribeStore(d,c.get(d))}return function(){r&&c.remove(d,y.current.id)}},[]),o({store:c,listener:b,contexts:[null==c?void 0:c.context],observer:null==c?void 0:c.observer}),y.current};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{useEffect as r}from"react";import{useStore as e}from"./useStore";import{Context as o}from"../context/context";import{Observer as t}from"../observer/observer";import{Store as n}from"../store/store";export var useObservableStore=function(m,s,a,c){var i=e({microStore:c,store:new n({id:m,context:new o("Context_"+m),observer:new t}),reducer:a,data:s}).store;return r(function(){var r;null==c||null==(r=c.add)||r.call(c,m,i)},[c,i,m]),{store:i}};
|
package/lib/hooks/useObserver.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEffect as
|
|
1
|
+
import{useEffect as n}from"react";import{Store as l}from"../store/store";export var hasValidList=function(n,l){var e;return void 0===n&&(n=[]),null==n?void 0:null==(e=n.find)?void 0:e.call(n,function(n){var e;return n.id===(null==l?void 0:null==(e=l.context)?void 0:e.id)})};export var useObserver=function(e){n(function(){var n,r,t=function(n,l){var e;hasValidList(u,n)&&(null==n||null==(e=n.context)||e.update({value:n,listener:o}),null==o||o(n,l))},o=e.listener,i=e.observer,u=e.contexts,s=(n=e.store,null!=l&&"undefined"!=typeof Symbol&&l[Symbol.hasInstance]?!!l[Symbol.hasInstance](n):n instanceof l);return s&&(null==i||null==(r=i.subscribe)||r.call(i,t)),function(){var n;return s&&(null==i?void 0:null==(n=i.unsubscribe)?void 0:n.call(i,t))}},[e.listener,e.observer,e.contexts])};
|
package/lib/hooks/useStore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useCallback as t,
|
|
1
|
+
import{useCallback as t,useRef as e}from"react";export function useStore(r){var a=r.reducer,u=r.data,o=e(r.store).current,n=o.mutate=t(function(t){var e=t.type,r=t.payload,u=t.targets,n=a(o.state,{type:e,payload:r});return o.notify({type:e,payload:r,state:n,targets:u})},[]),s=o.query=t(function(t,e){var r;return null!=(r=t(o))?r:e},[]);return o.state||(o.state=u),{query:s,mutate:n,store:o}}
|
package/lib/observer/observer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export var Observer=function(){function r(){this.subscriptors=[]}var s=r.prototype;return s.subscribe=function(r){this.subscriptors.push(r)},s.unsubscribe=function(r){this.subscriptors.splice(this.subscriptors.findIndex(function(s){return s===r}),1)},s.notify=function(r){var s=this;return void 0===r&&(r={}),new Promise(function(t){s.subscriptors.forEach(function(s){return s(r,t)})})},r}();
|
|
1
|
+
export var Observer=function(){function r(){var r=this;this.subscriptors=[],this.has=function(s){return r.subscriptors.some(function(r){return s===r.id})}}var s=r.prototype;return s.subscribe=function(r){this.subscriptors.push(r)},s.unsubscribe=function(r){this.subscriptors.splice(this.subscriptors.findIndex(function(s){return s===r}),1)},s.notify=function(r){var s=this;return void 0===r&&(r={}),new Promise(function(t){s.subscriptors.forEach(function(s){return s(r,t)})})},r}();
|
package/lib/store/store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function _array_like_to_array(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,o=Array(t);r<t;r++)o[r]=e[r];return o}function _create_for_of_iterator_helper_loose(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return _array_like_to_array(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);if("Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r)return Array.from(r);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return _array_like_to_array(e,void 0)}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}import{hasValidList as e}from"../hooks/useObserver";export var Store=function(e){var t=this,r=e.context,o=e.observer,n=e.id;this.context=null,this.observer=null,this.id=null,this.notify=function(e){t.observer.notify({context:t.context,value:e})},this.query=function(){return console.log("method is not conencted to the reducer, please call useStore first")},this.mutate=function(){return console.log("method is not connected to the store, you need call useStore first")},this.id=n,this.context=r,this.observer=o};export var MicroStore=function(){var t=this;this.collection=new Map,this.listeners=new Map,this.subscribeStore=function(r,o){for(var n,i,s=o.observer,a=o.context,l=null!=(n=t.listeners.get(r))?n:[],u=_create_for_of_iterator_helper_loose(l);!(i=u()).done;)!function(){var t=i.value,r=function(r,o){var n;e([a],r)&&(null==r||null==(n=r.context)||n.update({value:r,listener:t}),null==t||t(r,o))};r.id=t.id,s.has(t.id)||s.subscribe(r)}()},this.add=function(e,r){return t.subscribeStore(e,r),t.collection.set(e,r),r},this.registerListener=function(e,r){if(t.listeners.has(e)){var o=t.listeners.get(e);o.push(r),t.listeners.set(e,o)}else t.listeners.set(e,[r])},this.hasListener=function(e){for(var r,o=!1,n=_create_for_of_iterator_helper_loose(t.listeners);!(r=n()).done;){var i=r.value;if(o=(i[0],i[1]).some(function(t){return t.id===e}))break}return o},this.remove=function(e,r){for(var o,n,i=t.collection.get(e),s=null!=(o=t.listeners.get(e))?o:[],a=_create_for_of_iterator_helper_loose(s);!(n=a()).done;){var l=n.value;if(l.id===r){i.observer.has(l.id)&&i.observer.unsubscribe(l);var u=s.indexOf(l);u>-1&&s.splice(u,1)}}},this.get=function(e){return t.collection.get(e)},this.has=function(e){return t.collection.has(e)}};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-io",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.11.82",
|
|
4
4
|
"description": "A lightweight React library that allows communication between Reactjs components by using the observer pattern and the hook api",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib/index.js",
|