hermes-io 2.4.47 → 2.5.49
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/MIT-LICENSE.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2024 Esneyder Amin Palacios Mena
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,23 +1,67 @@
|
|
|
1
|
-
# hermes-io
|
|
2
|
-
|
|
1
|
+
# hermes-io
|
|
3
2
|
A lightweight React library that allows communication between components by using the observer pattern and the hook api.
|
|
4
3
|
|
|
4
|
+
## Usage
|
|
5
|
+
```javascript
|
|
6
|
+
function App({ notify }) {
|
|
7
|
+
const increment = () => {
|
|
8
|
+
notify({
|
|
9
|
+
value: {
|
|
10
|
+
type: INCREMENT,
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const decrement = () => {
|
|
16
|
+
notify({
|
|
17
|
+
value: {
|
|
18
|
+
type: DECREMENT,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div>
|
|
25
|
+
<Counter />
|
|
26
|
+
<RenderTracker />
|
|
27
|
+
<button onClick={increment}>Increment</button>
|
|
28
|
+
<button onClick={decrement}>Decrement</button>
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
export default withNotify(App, {
|
|
33
|
+
context: CounterContext,
|
|
34
|
+
observer: CounterObserver
|
|
35
|
+
});
|
|
5
36
|
```
|
|
6
|
-
npm i hermes-io --save
|
|
7
|
-
```
|
|
8
|
-
Documentation: [here](https://hermes-io-docs.vercel.app/)
|
|
9
37
|
|
|
38
|
+
```javascript
|
|
39
|
+
export function Counter() {
|
|
40
|
+
const [count, setCount] = useState(0);
|
|
41
|
+
const handleCounterNotification = (event) => {
|
|
42
|
+
const { value = {} } = event;
|
|
43
|
+
const { type } = value;
|
|
44
|
+
if (type === INCREMENT) setCount((prevValue) => prevValue + 1);
|
|
45
|
+
if (type === DECREMENT) setCount((prevValue) => prevValue - 1);
|
|
46
|
+
};
|
|
10
47
|
|
|
11
|
-
|
|
48
|
+
useObserver({
|
|
49
|
+
contexts: [CounterContext],
|
|
50
|
+
observer: CounterObserver,
|
|
51
|
+
listener: handleCounterNotification,
|
|
52
|
+
});
|
|
12
53
|
|
|
13
|
-
|
|
54
|
+
return <h1>Counter: {count}</h1>;
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
<img src="https://raw.githubusercontent.com/Maxtermax/hermes-io-counter-demo/master/src/assets/optimized.gif" />
|
|
14
58
|
|
|
15
|
-
|
|
59
|
+
## Documentation
|
|
60
|
+
See: https://hermes-io-docs.vercel.app/
|
|
16
61
|
|
|
17
|
-

|
|
18
62
|
|
|
19
|
-
##
|
|
63
|
+
## Devtool
|
|
20
64
|
|
|
21
|
-
|
|
65
|
+
Install from chrome web store [here](https://chrome.google.com/webstore/detail/hermes-io/pjdkgcpikfmkncldipldmimanfkpeedm?hl=en)
|
|
22
66
|
|
|
23
|
-
https://
|
|
67
|
+

|
|
@@ -1 +1 @@
|
|
|
1
|
-
function _array_like_to_array(r,t){(null==t||t>r.length)&&(t=r.length);for(var
|
|
1
|
+
function _array_like_to_array(r,t){(null==t||t>r.length)&&(t=r.length);for(var n=0,e=Array(t);n<t;n++)e[n]=r[n];return e}import{useState as r,useRef as t}from"react";import{useObserver as n}from"../hooks/useObserver";var randomId=function(){var r,t;return(null==(t=crypto)?void 0:null==(r=t.randomUUID)?void 0:r.call(t))||Math.random().toString(36).substring(2,16)};export var useMutations=function(e){var o=e.store,a=e.id,l=e.events,i=e.noUpdate,u=void 0!==i&&i,v=e.onChange,d=r(randomId()),c=(d[0],d[1]),f=t(null);return n({listener:function(r,t){for(var n,e=function(r,t){var n="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(n)return(n=n.call(r)).next.bind(n);if(Array.isArray(r)||(n=function(r,t){if(r){if("string"==typeof r)return _array_like_to_array(r,void 0);var n=Object.prototype.toString.call(r).slice(8,-1);if("Object"===n&&r.constructor&&(n=r.constructor.name),"Map"===n||"Set"===n)return Array.from(n);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return _array_like_to_array(r,void 0)}}(r))){n&&(r=n);var e=0;return function(){return e>=r.length?{done:!0}:{done:!1,value:r[e++]}}}throw TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(l);!(n=e()).done;)!function(){var e=n.value;if(r.value.type===e){var o,l,i,d,f,s,y=null==(l=r.value)?void 0:null==(o=l.payload)?void 0:o.value,m=!(null==(i=r.value)?void 0:i.targets);if(null==r||null==(s=r.value)||null==(f=s.targets)||null==(d=f.forEach)||d.call(f,function(r){return r===a&&(null==v?void 0:v(y,t))}),m&&(null==v||v(y,t)),!0===u)return;c(randomId())}}()},contexts:[o.context],observer:o.observer}),f};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hermes-io",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.49",
|
|
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",
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
function _extends() {
|
|
2
|
-
return (_extends =
|
|
3
|
-
Object.assign ||
|
|
4
|
-
function (e) {
|
|
5
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
6
|
-
var t = arguments[r];
|
|
7
|
-
for (var n in t)
|
|
8
|
-
Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
|
|
9
|
-
}
|
|
10
|
-
return e;
|
|
11
|
-
}).apply(this, arguments);
|
|
12
|
-
}
|
|
13
|
-
import { useObserver as e } from "../../hooks/useObserver";
|
|
14
|
-
import r, { useState as t } from "react";
|
|
15
|
-
export function withReactive(n) {
|
|
16
|
-
var o = n.context,
|
|
17
|
-
a = n.observer,
|
|
18
|
-
i = n.values,
|
|
19
|
-
u = void 0 === i ? {} : i;
|
|
20
|
-
return function (n) {
|
|
21
|
-
var i = t(!1),
|
|
22
|
-
s = (i[0], i[1]);
|
|
23
|
-
return (
|
|
24
|
-
e({
|
|
25
|
-
listener: function (e) {
|
|
26
|
-
var r = e.value,
|
|
27
|
-
t = r.id,
|
|
28
|
-
o = r.value;
|
|
29
|
-
n.id === t &&
|
|
30
|
-
((u = _extends({}, u, o)),
|
|
31
|
-
s(function (e) {
|
|
32
|
-
return !e;
|
|
33
|
-
}));
|
|
34
|
-
},
|
|
35
|
-
contexts: [o],
|
|
36
|
-
observer: a,
|
|
37
|
-
}),
|
|
38
|
-
r.createElement(r.Fragment, null, n.render(u))
|
|
39
|
-
);
|
|
40
|
-
};
|
|
41
|
-
}
|