hermes-io 2.11.92 → 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
|
|
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{getStackTrace as i,randomId as
|
|
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{
|
|
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}};
|
package/lib/hooks/useStore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
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}}
|
package/lib/store/store.js
CHANGED
|
@@ -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,
|
|
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.
|
|
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",
|