@virtuous/react-conductor
Version:
React bindings for Conductor
93 lines (73 loc) • 1.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = require("react");
var _conductor = require("@virtuous/conductor");
function eventHook(event, callback) {
(0, _react.useEffect)(function () {
_conductor.emitter.addListener(event, callback);
return function () {
return _conductor.emitter.removeListener(event, callback);
};
});
}
function push(params) {
return _conductor.router.push(params);
}
function willPush(callback) {
return eventHook(_conductor.EVENT_WILL_PUSH, callback);
}
function didPush(callback) {
return eventHook(_conductor.EVENT_DID_PUSH, callback);
}
function pop(params) {
return _conductor.router.pop(params);
}
function willPop(callback) {
return eventHook(_conductor.EVENT_WILL_POP, callback);
}
function didPop(callback) {
return eventHook(_conductor.EVENT_DID_POP, callback);
}
function replace(params) {
return _conductor.router.replace(params);
}
function willReplace(callback) {
return eventHook(_conductor.EVENT_WILL_REPLACE, callback);
}
function didReplace(callback) {
return eventHook(_conductor.EVENT_DID_REPLACE, callback);
}
function reset() {
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
return _conductor.router.reset(state);
}
function willReset(callback) {
return eventHook(_conductor.EVENT_WILL_RESET, callback);
}
function didReset(callback) {
return eventHook(_conductor.EVENT_DID_RESET, callback);
}
function resetTo(params) {
return _conductor.router.resetTo(params.pathname, params.state);
}
var _default = function _default() {
return {
push: push,
pop: pop,
replace: replace,
reset: reset,
resetTo: resetTo,
willPush: willPush,
didPush: didPush,
willPop: willPop,
didPop: didPop,
willReplace: willReplace,
didReplace: didReplace,
willReset: willReset,
didReset: didReset
};
};
exports["default"] = _default;