@enact/core
Version:
Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.
30 lines (29 loc) • 1.39 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
exports.useHandlers = useHandlers;
var _useClass = _interopRequireDefault(require("../useClass"));
var _Handlers = _interopRequireDefault(require("./Handlers"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* Creates a map of event handlers with consistent references across renders.
*
* Each function in the `handlers` will receive the first argument passed by the downstream caller
* along with the latest `props` and `context` values passed to `useHandlers`. This is designed to
* work well with {@link core/handle} which generates handlers with this function signature.
*
* @param {Object.<String, Function>} handlers Map of handler names to functions.
* @params {any} [props] Typically, the props for the component but that is
* not required.
* @params {any} [context] Additional data or methods the handlers may need.
* @returns {Object} A map of bound handlers
* @private
*/
function useHandlers(handlers, props, context) {
var h = (0, _useClass["default"])(_Handlers["default"], handlers);
h.setContext(props, context);
return h.handlers;
}
var _default = exports["default"] = useHandlers;
;