hermes-io 2.9.88 → 2.10.81
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.
package/lib/context/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function _extends(){return(_extends=Object.assign||function(
|
|
1
|
+
function _extends(){return(_extends=Object.assign||function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n}).apply(this,arguments)}import n from"../constants";var _window_addEventListener,_window,_obj,recording=!1,collection=[];export var listenersMap=new Map;var actions=((_obj={})[n.START_RECORDING]=function(){recording=!0},_obj[n.STOP_RECORDING]=function(){recording=!1},_obj[n.RESET_RECORDING]=function(){collection=[],recording=!1},_obj[n.SET_CONTEXT]=function(n){var e=n.id,t=void 0===e?"":e,r=collection.find(function(n){return n._internalId===t});if(r){if(r.isFromExternalRecording){var i=listenersMap.get(r.listener);return null==i?void 0:i({value:JSON.parse(r.value)})}return r.listener(r.value)}},_obj[n.LOAD_RECORDING]=function(n){collection=n.recording.map(function(n){return void 0===n&&(n={}),_extends({},n,{isFromExternalRecording:!0,_internalId:n.id})})},_obj);null==(_window=window)||null==(_window_addEventListener=_window.addEventListener)||_window_addEventListener.call(_window,"message",function(e){try{var t=e.data,r=t.source,i=t.payload;if(r===n.CHROME_EXTENSION){if(null==i?void 0:i.type)return actions[i.type](i);actions[i]()}}catch(n){console.error(n)}});export var Context=function(e){var t=this;this.id=null,this._internalId=null,this.date=null,this.value=null,this.listener=null,this.stackTrace=null,this.update=function(n){var e=n.value,r=n.listener;t.date=new Date,t.value=e,t.stackTrace=t.getStackTrace(),t.listener=r,recording&&t.sendSnapshot()},this.sendSnapshot=function(){var e,r,i=t.takeSnapshot(),a=i.listener,o=i.stackTrace,l=i.value,s=i.date,c=i._internalId;collection.push(i),null==(r=window)||null==(e=r.postMessage)||e.call(r,{type:n.CONTEXT_SNAPSHOT,payload:{value:JSON.stringify(l.value),listener:a.name,stackTrace:o,date:s,id:c},source:"hermes-io"},"*")},this.takeSnapshot=function(){return{_internalId:crypto.randomUUID(),value:t.value,date:t.date,listener:t.listener,stackTrace:t.stackTrace}},this.getStackTrace=function(){return Error().stack},this.id=Symbol(e)};
|
package/lib/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./useObserver
|
|
1
|
+
export*from"./useObserver";export*from"./useMutations";export*from"./useStore";export*from"./useObservableStore";
|
|
@@ -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 e}from"react";import{useObserver as t}from"./useObserver
|
|
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 e}from"react";import{useObserver as t}from"./useObserver";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(n){void 0===n&&(n={});var o=n.events,a=void 0===o?[]:o,i=n.onChange,l=n.store,u=n.id,v=n.initialState,c=r(randomId()),d=(c[0],c[1]),s=e({state:_extends({},void 0===v?{}:v),events:[],onEvent:function(r,e){var t=s.current.events;t.some(function(e){return e.event===r})||t.push({event:r,onChange:e})}}),f=function(r){return n.noUpdate=r},_=function(r,e,t,o){var a=!r,i=!1;if(null==r||null==(l=r.forEach)||l.call(r,function(r){if(r===n.id){i=!0;var a,l=null!=(a=null==o?void 0:o(e,t,f,s.current.state))?a:{};n.noUpdate&&(l={}),s.current.state=_extends({},s.current.state,l)}}),a){var l,u,v=null!=(u=null==o?void 0:o(e,t,f,s.current.state))?u:{};n.noUpdate&&(v={}),s.current.state=_extends({},s.current.state,v)}!0!==n.noUpdate&&!1!==i&&d(randomId())};return t({id:u,microStore:l,listener:function(r,e){var t=null==(u=r.value)?void 0:null==(l=u.payload)?void 0:l.value,n=null==(v=r.value)?void 0:v.targets,o=null==(c=s.current)?void 0:c.events;if(o.length>0){for(var l,u,v,c,d,f=_create_for_of_iterator_helper_loose(o);!(d=f()).done;){var p=d.value;r.value.type===p.event&&_(n,t,e,p.onChange)}return}for(var y,m=_create_for_of_iterator_helper_loose(a);!(y=m()).done;){var h=y.value;r.value.type===h&&_(n,t,e,i)}},contexts:[null==l?void 0:l.context],observer:null==l?void 0:l.observer}),s.current};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useStore as r}from"./useStore
|
|
1
|
+
import{useStore as r}from"./useStore";import{Context as e}from"../context/context";import{Observer as o}from"../observer/observer";import{Store as t}from"../store/store";export var useObservableStore=function(s,n,m,i){var c={store:new t({id:s,context:new e("Context_"+s),observer:new o}),reducer:m,data:n};return i&&(c.microStore=i),{store:r(c).store}};
|
package/lib/hooks/useObserver.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useEffect as l}from"react";import{MicroStore as n}from"../store/store
|
|
1
|
+
import{useEffect as l}from"react";import{MicroStore as n}from"../store/store";export var useObserver=function(e){l(function(){var l,u,o=function(l,n){var e,u;(null==a?void 0:null==(e=a.find)?void 0:e.call(a,function(n){var e;return n.id===(null==l?void 0:null==(e=l.context)?void 0:e.id)}))&&(null==l||null==(u=l.context)||u.update({value:l,listener:t}),null==t||t(l,n))},r=function(){var l,n,e=null==c?void 0:null==(l=c.get)?void 0:l.call(c,i);s=null==e?void 0:e.observer,a=(null==e?void 0:e.context)?[e.context]:[],null==s||null==(n=s.subscribe)||n.call(s,o)},t=e.listener,i=e.id,c=e.microStore,s=e.observer,a=e.contexts;return(null!=n&&"undefined"!=typeof Symbol&&n[Symbol.hasInstance]?!!n[Symbol.hasInstance](c):c instanceof n)&&i?(null==c?void 0:null==(l=c.get)?void 0:l.call(c,i))?(c.unsubscribe(r),r()):c.subscribe(r):null==s||null==(u=s.subscribe)||u.call(s,o),function(){var l,n;null==s||null==(l=s.unsubscribe)||l.call(s,o),null==c||null==(n=c.unsubscribe)||n.call(c,r)}},[e.id,e.listener,e.observer,e.contexts,e.microStore])};
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./hooks
|
|
1
|
+
export*from"./hooks";export*from"./observer/observer";export*from"./context/context";export*from"./store/store";export*from"./components/withNotify/withNotify";
|
package/lib/store/store.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function _set_prototype_of(t,e){return(_set_prototype_of=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}import{Observer as t}from"../observer/observer
|
|
1
|
+
function _set_prototype_of(t,e){return(_set_prototype_of=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}import{Observer as t}from"../observer/observer";export var Store=function(t){var e=this,o=t.context,r=t.observer,n=t.id;this.context=null,this.observer=null,this.id=null,this.notify=function(t){return e.observer.notify({context:e.context,value:t})},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=o,this.observer=r};export var MicroStore=function(t){function e(){var e;return e=t.apply(this,arguments)||this,e.collection=new Map,e.add=function(t,o){return e.collection.set(t,o),o},e.remove=function(t){return e.collection.delete(t)},e.get=function(t){return e.collection.get(t)},e}return!function(t,e){if("function"!=typeof e&&null!==e)throw 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&&_set_prototype_of(t,e)}(e,t),e}(t);
|
package/package.json
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-io",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.81",
|
|
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",
|
|
7
|
-
"type": "module",
|
|
8
7
|
"scripts": {
|
|
9
8
|
"test": "vitest __test__",
|
|
10
9
|
"prepare": "swc ./src -d ./lib"
|
|
@@ -13,26 +12,6 @@
|
|
|
13
12
|
".": {
|
|
14
13
|
"import": "./lib/index.js",
|
|
15
14
|
"require": "./lib/index.js"
|
|
16
|
-
},
|
|
17
|
-
"./lib/hooks": {
|
|
18
|
-
"import": "./lib/hooks/index.js",
|
|
19
|
-
"require": "./lib/hooks/index.js"
|
|
20
|
-
},
|
|
21
|
-
"./lib/context": {
|
|
22
|
-
"import": "./lib/context/context.js",
|
|
23
|
-
"require": "./lib/context/context.js"
|
|
24
|
-
},
|
|
25
|
-
"./lib/observer": {
|
|
26
|
-
"import": "./lib/observer/observer.js",
|
|
27
|
-
"require": "./lib/observer/observer.js"
|
|
28
|
-
},
|
|
29
|
-
"./lib/store": {
|
|
30
|
-
"import": "./lib/store/store.js",
|
|
31
|
-
"require": "./lib/store/store.js"
|
|
32
|
-
},
|
|
33
|
-
"./lib/constants": {
|
|
34
|
-
"import": "./lib/constants.js",
|
|
35
|
-
"require": "./lib/constants.js"
|
|
36
15
|
}
|
|
37
16
|
},
|
|
38
17
|
"keywords": [
|