hermes-io 2.11.93 → 2.11.94

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
- import{useEffect as r,useRef as n}from"react";export function useMicroStore(u,t){var l=n(null);return r(function(){var r,n=function(){l.current=u.get(t),l.store=l.current};return null==u||null==(r=u.subscribe)||r.call(u,n),function(){var r;return null==u?void 0:null==(r=u.unsubscribe)?void 0:r.call(u,n)}},[]),l}
1
+ import{useEffect as l}from"react";export var useMicroStore=function(r){var n=r.name,o=r.id,a=r.microStore,u=r.store;l(function(){var l,r;if(!(!o||(null==a?void 0:null==(l=a.has)?void 0:l.call(a,o))))return null==a||null==(r=a.add)||r.call(a,o,u,n),function(){var l;null==a||null==(l=a.removeAll)||l.call(a,o)}},[a,u,o])};
@@ -1 +1 @@
1
- function _array_like_to_array(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function _extends(){return(_extends=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function _create_for_of_iterator_helper_loose(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return _array_like_to_array(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.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(e,void 0)}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[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 e,useEffect as r,useRef as t,useCallback as n}from"react";import{useObserver as o}from"./useObserver.js";import{MicroStore as a}from"../store/store.js";import{randomId as i}from"../utils.js";export var useMutations=function(l){void 0===l&&(l={});var u,s=l.events,v=void 0===s?[]:s,c=l.onChange,f=l.store,d=l.id,_=l.initialState,p=e(i()),y=(p[0],p[1]),h=t({id:i(),state:_extends({},void 0===_?{}:_),events:[],onEvent:function(e,r){var t=h.current.events;t.some(function(r){return r.event===e})||t.push({event:e,onChange:r})}}),m=function(e){return l.noUpdate=e},b=function(e,r,t,n){var o=!e,a=!1;if(null==e||null==(u=e.forEach)||u.call(e,function(e){if(e===l.id){a=!0;var o,i=null!=(o=null==n?void 0:n(r,t,m,h.current.state))?o:{};l.noUpdate&&(i={}),h.current.state=_extends({},h.current.state,i)}}),o){var u,s,v=null!=(s=null==n?void 0:n(r,t,m,h.current.state))?s:{};l.noUpdate&&(v={}),h.current.state=_extends({},h.current.state,v)}!0!==l.noUpdate&&!1!==a&&y(i())},g=n(function(e,r){var t=null==(i=e.value)?void 0:null==(a=i.payload)?void 0:a.value,n=null==(l=e.value)?void 0:l.targets,o=null==(u=h.current)?void 0:u.events;if(o.length>0){for(var a,i,l,u,s,f=_create_for_of_iterator_helper_loose(o);!(s=f()).done;){var d=s.value;e.value.type===d.event&&b(n,t,r,d.onChange)}return}for(var _,p=_create_for_of_iterator_helper_loose(v);!(_=p()).done;){var y=_.value;e.value.type===y&&b(n,t,r,c)}},[v,null==(u=h.current)?void 0:u.events]);return r(function(){var e=null!=a&&"undefined"!=typeof Symbol&&a[Symbol.hasInstance]?!!a[Symbol.hasInstance](f):f instanceof a;if(e){var r=h.current.id;g.id=r;var t=f.has(d);f.hasListener(r)||f.registerListener(d,g),t&&!f.get(d).observer.has(r)&&f.subscribeStore(d,f.get(d))}return function(){e&&f.remove(d,h.current.id)}},[]),o({store:f,listener:g,contexts:[null==f?void 0:f.context],observer:null==f?void 0:f.observer}),h.current};
1
+ function _array_like_to_array(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=Array(r);t<r;t++)n[t]=e[t];return n}function _extends(){return(_extends=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function _create_for_of_iterator_helper_loose(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return _array_like_to_array(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);if("Object"===t&&e.constructor&&(t=e.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(e,void 0)}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[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 e,useEffect as r,useRef as t,useCallback as n}from"react";import{useObserver as o}from"./useObserver.js";import{MicroStore as a}from"../store/store.js";import{getStackTrace as i,randomId as u}from"../utils.js";export var useMutations=function(l){void 0===l&&(l={});var s,v=l.events,c=void 0===v?[]:v,f=l.onChange,d=l.store,_=l.id,p=l.initialState,y=l.name,m=void 0===y?"":y,h=e(u()),b=(h[0],h[1]),g=t({id:i()+"_"+(null!=_?_:""),state:_extends({},void 0===p?{}:p),events:[],onEvent:function(e,r){var t=g.current.events;t.some(function(r){return r.event===e})||t.push({event:e,onChange:r})}}),S=function(e){return l.noUpdate=e},x=function(e,r,t,n){var o=!e,a=!1;if(null==e||null==(i=e.forEach)||i.call(e,function(e){if(e===l.id){a=!0;var o,i=null!=(o=null==n?void 0:n(r,t,S,g.current.state))?o:{};l.noUpdate&&(i={}),g.current.state=_extends({},g.current.state,i)}}),o){var i,s,v=null!=(s=null==n?void 0:n(r,t,S,g.current.state))?s:{};l.noUpdate&&(v={}),g.current.state=_extends({},g.current.state,v)}!0!==l.noUpdate&&!1!==a&&b(u())},j=n(function(e,r){var t=null==(i=e.value)?void 0:null==(a=i.payload)?void 0:a.value,n=null==(u=e.value)?void 0:u.targets,o=null==(l=g.current)?void 0:l.events;if(o.length>0){for(var a,i,u,l,s,v=_create_for_of_iterator_helper_loose(o);!(s=v()).done;){var d=s.value;e.value.type===d.event&&x(n,t,r,d.onChange)}return}for(var _,p=_create_for_of_iterator_helper_loose(c);!(_=p()).done;){var y=_.value;e.value.type===y&&x(n,t,r,f)}},[c,null==(s=g.current)?void 0:s.events]);return r(function(){var e=function(){r&&d.remove(_,g.current.id)},r=null!=a&&"undefined"!=typeof Symbol&&a[Symbol.hasInstance]?!!a[Symbol.hasInstance](d):d instanceof a;if(r){var t=g.current.id;j.id=t;var n=d.has(_);d.hasListener(t)||d.registerListener(_,j),n&&!d.get(_).observer.has(t)&&d.subscribeStore(_,d.get(_),m)}return function(){return e()}},[j]),o({store:d,listener:j,contexts:[null==d?void 0:d.context],observer:null==d?void 0:d.observer}),g.current};
@@ -1 +1 @@
1
- import{useEffect as r}from"react";import{useStore as e}from"./useStore.js";import{Context as o}from"../context/context.js";import{Observer as t}from"../observer/observer.js";import{Store as s}from"../store/store.js";export var useObservableStore=function(n,m,a,c){var i=e({microStore:c,store:new s({id:n,context:new o("Context_"+n),observer:new t}),reducer:a,data:m}).store;return r(function(){var r;null==c||null==(r=c.add)||r.call(c,n,i)},[c,i,n]),{store:i}};
1
+ import{useStore as r}from"./useStore.js";import{Context as e}from"../context/context.js";import{Observer as o}from"../observer/observer.js";import{Store as t}from"../store/store.js";import{useMicroStore as s}from"./useMicroStore.js";export var useObservableStore=function(m,i,n,c,a){var f=r({microStore:c,store:new t({id:m,context:new e("Context_"+m),observer:new o}),reducer:n,data:i}).store;return s({id:m,microStore:c,store:f,name:a}),{store:f}};
@@ -1 +1 @@
1
- import{useEffect as t,useCallback as e,useRef as r}from"react";export function useStore(a){var o=a.reducer,u=a.data,n=a.microStore,s=a.id,y=r(a.store).current,c=y.mutate=e(function(t){var e=t.type,r=t.payload,a=t.targets,u=o(y.state,{type:e,payload:r});return y.notify({type:e,payload:r,state:u,targets:a})},[]),d=y.query=e(function(t,e){var r;return null!=(r=t(y))?r:e},[]);return y.state||(y.state=u),t(function(){n&&n.add(s,y)},[n,y,s]),{query:d,mutate:c,store:y}}
1
+ import{useCallback as t,useRef as r}from"react";import{useMicroStore as e}from"./useMicroStore";export function useStore(a){var o=a.name,u=a.reducer,n=a.data,i=a.microStore,s=a.id,m=r(a.store).current,c=m.mutate=t(function(t){var r=t.type,e=t.payload,a=t.targets,o=u(m.state,{type:r,payload:e});return m.notify({type:r,payload:e,state:o,targets:a})},[]),p=m.query=t(function(t,r){var e;return null!=(e=t(m))?e:r},[]);return m.state||(m.state=n),e({id:s,microStore:i,store:m,name:o}),{query:p,mutate:c,store:m}}
@@ -1 +1 @@
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.js";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){return 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)}};
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.js";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){return 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,l=o.context,a=null!=(n=t.listeners.get(r))?n:[],u=_create_for_of_iterator_helper_loose(a);!(i=u()).done;)!function(){var t=i.value,r=function(r,o){var n;e([l],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:[],l=_create_for_of_iterator_helper_loose(s);!(n=l()).done;){var a=n.value;if(a.id===r){i.observer.has(a.id)&&i.observer.unsubscribe(a);var u=s.indexOf(a);u>-1&&s.splice(u,1)}}},this.removeAll=function(e){for(var r,o,n=t.collection.get(e),i=null!=(r=t.listeners.get(e))?r:[],s=_create_for_of_iterator_helper_loose(i);!(o=s()).done;){var l=o.value;n.observer.has(l.id)&&n.observer.unsubscribe(l);var a=i.indexOf(l);a>-1&&i.splice(a,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.11.93",
3
+ "version": "2.11.94",
4
4
  "type": "module",
5
5
  "description": "A lightweight React library that allows communication between Reactjs components by using the observer pattern and the hook api",
6
6
  "main": "./lib/index.js",