@civet/events 1.1.0 → 1.1.1
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/ConfigProvider.js +5 -3
- package/lib/EventHandler.js +25 -7
- package/lib/useEventHandler.js +7 -0
- package/package.json +1 -1
- package/src/EventHandler.jsx +22 -7
- package/src/useEventHandler.js +13 -0
package/lib/ConfigProvider.js
CHANGED
|
@@ -7,15 +7,17 @@ exports["default"] = void 0;
|
|
|
7
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
8
|
var _EventReceiver = require("./EventReceiver");
|
|
9
9
|
var _context = require("./context");
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
11
12
|
var ConfigProvider = function ConfigProvider(_ref) {
|
|
12
13
|
var eventReceiver = _ref.eventReceiver,
|
|
13
14
|
children = _ref.children;
|
|
14
|
-
return /*#__PURE__*/
|
|
15
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_context.ConfigContext.Provider, {
|
|
15
16
|
value: {
|
|
16
17
|
eventReceiver: eventReceiver
|
|
17
|
-
}
|
|
18
|
-
|
|
18
|
+
},
|
|
19
|
+
children: children
|
|
20
|
+
});
|
|
19
21
|
};
|
|
20
22
|
ConfigProvider.propTypes = {
|
|
21
23
|
eventReceiver: _EventReceiver.eventReceiverPropType,
|
package/lib/EventHandler.js
CHANGED
|
@@ -7,23 +7,41 @@ exports["default"] = void 0;
|
|
|
7
7
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
8
|
var _EventReceiver = require("./EventReceiver");
|
|
9
9
|
var _useEventHandler = _interopRequireDefault(require("./useEventHandler"));
|
|
10
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
10
11
|
var _excluded = ["children"];
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
12
13
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
13
14
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
props = _objectWithoutProperties(_ref, _excluded);
|
|
17
|
-
(0, _useEventHandler["default"])(props);
|
|
18
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
19
|
-
}
|
|
20
|
-
EventHandler.propTypes = {
|
|
15
|
+
var propTypes = {
|
|
16
|
+
/** EventReceiver to be used */
|
|
21
17
|
eventReceiver: _EventReceiver.eventReceiverPropType,
|
|
18
|
+
/** ResourceContext to be used */
|
|
22
19
|
resource: _propTypes["default"].object,
|
|
20
|
+
/** Disables the event handler */
|
|
23
21
|
disabled: _propTypes["default"].bool,
|
|
22
|
+
/** Options for the EventReceiver */
|
|
24
23
|
options: _propTypes["default"].object,
|
|
24
|
+
/** Callback to filter events and handle your own event logic - if true is returned, the event does not cause the resource to update */
|
|
25
25
|
onEvent: _propTypes["default"].func,
|
|
26
|
+
/** Provides information on when the resource has been requested to update - events contains the events that lead to the update */
|
|
26
27
|
onNotify: _propTypes["default"].func,
|
|
27
28
|
children: _propTypes["default"].node
|
|
28
29
|
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Enables automatic updating for a Resource component or useResource hook by subscribing to an EventReceiver.
|
|
33
|
+
*
|
|
34
|
+
* Necessary configuration that is not directly specified is taken from the ConfigContext and ResourceContext.
|
|
35
|
+
*
|
|
36
|
+
* onEvent can be used to directly access events allowing you to add custom event logic to your components.
|
|
37
|
+
*/
|
|
38
|
+
function EventHandler(_ref) {
|
|
39
|
+
var children = _ref.children,
|
|
40
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
41
|
+
(0, _useEventHandler["default"])(props);
|
|
42
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
43
|
+
children: children
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
EventHandler.propTypes = propTypes;
|
|
29
47
|
var _default = exports["default"] = EventHandler;
|
package/lib/useEventHandler.js
CHANGED
|
@@ -15,6 +15,13 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
15
15
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
16
16
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
17
17
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
+
/**
|
|
19
|
+
* Enables automatic updating for a Resource component or useResource hook by subscribing to an EventReceiver.
|
|
20
|
+
*
|
|
21
|
+
* Necessary configuration that is not directly specified is taken from the ConfigContext and ResourceContext.
|
|
22
|
+
*
|
|
23
|
+
* onEvent can be used to directly access events allowing you to add custom event logic to your components.
|
|
24
|
+
*/
|
|
18
25
|
function useEventHandler(_ref) {
|
|
19
26
|
var eventReceiverProp = _ref.eventReceiver,
|
|
20
27
|
resourceProp = _ref.resource,
|
package/package.json
CHANGED
package/src/EventHandler.jsx
CHANGED
|
@@ -2,20 +2,35 @@ import PropTypes from 'prop-types';
|
|
|
2
2
|
import { eventReceiverPropType } from './EventReceiver';
|
|
3
3
|
import useEventHandler from './useEventHandler';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return <>{children}</>;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
EventHandler.propTypes = {
|
|
5
|
+
const propTypes = {
|
|
6
|
+
/** EventReceiver to be used */
|
|
12
7
|
eventReceiver: eventReceiverPropType,
|
|
8
|
+
/** ResourceContext to be used */
|
|
13
9
|
resource: PropTypes.object,
|
|
10
|
+
/** Disables the event handler */
|
|
14
11
|
disabled: PropTypes.bool,
|
|
12
|
+
/** Options for the EventReceiver */
|
|
15
13
|
options: PropTypes.object,
|
|
14
|
+
/** Callback to filter events and handle your own event logic - if true is returned, the event does not cause the resource to update */
|
|
16
15
|
onEvent: PropTypes.func,
|
|
16
|
+
/** Provides information on when the resource has been requested to update - events contains the events that lead to the update */
|
|
17
17
|
onNotify: PropTypes.func,
|
|
18
18
|
children: PropTypes.node,
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Enables automatic updating for a Resource component or useResource hook by subscribing to an EventReceiver.
|
|
23
|
+
*
|
|
24
|
+
* Necessary configuration that is not directly specified is taken from the ConfigContext and ResourceContext.
|
|
25
|
+
*
|
|
26
|
+
* onEvent can be used to directly access events allowing you to add custom event logic to your components.
|
|
27
|
+
*/
|
|
28
|
+
function EventHandler({ children, ...props }) {
|
|
29
|
+
useEventHandler(props);
|
|
30
|
+
|
|
31
|
+
return <>{children}</>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
EventHandler.propTypes = propTypes;
|
|
35
|
+
|
|
21
36
|
export default EventHandler;
|
package/src/useEventHandler.js
CHANGED
|
@@ -3,12 +3,25 @@ import deepEquals from 'fast-deep-equal';
|
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
4
|
import { useConfigContext } from './context';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Enables automatic updating for a Resource component or useResource hook by subscribing to an EventReceiver.
|
|
8
|
+
*
|
|
9
|
+
* Necessary configuration that is not directly specified is taken from the ConfigContext and ResourceContext.
|
|
10
|
+
*
|
|
11
|
+
* onEvent can be used to directly access events allowing you to add custom event logic to your components.
|
|
12
|
+
*/
|
|
6
13
|
function useEventHandler({
|
|
14
|
+
/** EventReceiver to be used */
|
|
7
15
|
eventReceiver: eventReceiverProp,
|
|
16
|
+
/** ResourceContext to be used */
|
|
8
17
|
resource: resourceProp,
|
|
18
|
+
/** Disables the event handler */
|
|
9
19
|
disabled,
|
|
20
|
+
/** Options for the EventReceiver */
|
|
10
21
|
options: optionsProp,
|
|
22
|
+
/** Callback to filter events and handle your own event logic - if true is returned, the event does not cause the resource to update */
|
|
11
23
|
onEvent,
|
|
24
|
+
/** Provides information on when the resource has been requested to update - events contains the events that lead to the update */
|
|
12
25
|
onNotify,
|
|
13
26
|
}) {
|
|
14
27
|
const configContext = useConfigContext();
|