Skip to content

Commit

Permalink
Introducing callHooks flag #265
Browse files Browse the repository at this point in the history
  • Loading branch information
Krasimir Tsonev committed Jan 13, 2021
1 parent cf531cb commit a7367d0
Show file tree
Hide file tree
Showing 22 changed files with 156 additions and 40 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.6.0

Introducing `callHooks` flag to the `navigate` options.

## 8.5.0

* `data-navigo` now accepts a `"false"` (as string) argument.
Expand Down
3 changes: 3 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ type NavigateOptions = {
historyAPIMethod?: string;
updateBrowserURL?: boolean;
callHandler?: boolean;
callHooks?: boolean;
updateState?: boolean;
force?: boolean;
resolveOptions?: ResolveOptions;
Expand Down Expand Up @@ -302,6 +303,7 @@ After the last line the browser will have in its address bar `/about` as a path
* If you don't want to have a new entry in the history you should pass `{ historyAPIMethod: 'replaceState' }`. By default is `pushState`.
* If `updateBrowserURL` is set to `false` the library will not use the history API at all. Meaning, the browser URL will not change.
* If `callHandler` is set to `false` your route handler will not be fired.
* If `callHooks` is set to `false` your route hooks will be skipped.
* If `updateState` is set to `false` the router will not update its internal state. This means that the `lastResolved()`/`current` route will not be updated.
* If `force` is set to `true` the router will update its internal state only. This makes the router like it already resolved specific URL.
* `resolveOptions` are the same options used in the [resolve](#resolving-routes) method.
Expand Down Expand Up @@ -705,6 +707,7 @@ type NavigateOptions = {
historyAPIMethod?: string;
updateBrowserURL?: boolean;
callHandler?: boolean;
callHooks?: boolean;
updateState?: boolean;
force?: boolean;
resolveOptions?: ResolveOptions;
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export type NavigateOptions = {
historyAPIMethod?: string;
updateBrowserURL?: boolean;
callHandler?: boolean;
callHooks?: boolean;
updateState?: boolean;
force?: boolean;
resolveOptions?: ResolveOptions;
Expand Down
4 changes: 3 additions & 1 deletion lib/es/middlewares/checkForAfterHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
exports.__esModule = true;
exports.default = _checkForAfterHook;

var _utils = require("../utils");

function _checkForAfterHook(context, done) {
if (context.match.route.hooks && context.match.route.hooks.after) {
if (context.match.route.hooks && context.match.route.hooks.after && (0, _utils.undefinedOrTrue)(context.navigateOptions, "callHooks")) {
context.match.route.hooks.after.forEach(function (f) {
return f(context.match);
});
Expand Down
10 changes: 7 additions & 3 deletions lib/es/middlewares/checkForAlreadyHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
exports.__esModule = true;
exports.default = checkForAlreadyHook;

var _utils = require("../utils");

function checkForAlreadyHook(context, done) {
var current = context.instance.lastResolved();

if (current && current[0] && current[0].route === context.match.route && current[0].url === context.match.url && current[0].queryString === context.match.queryString) {
current.forEach(function (c) {
if (c.route.hooks && c.route.hooks.already) {
c.route.hooks.already.forEach(function (f) {
return f(context.match);
});
if ((0, _utils.undefinedOrTrue)(context.navigateOptions, "callHooks")) {
c.route.hooks.already.forEach(function (f) {
return f(context.match);
});
}
}
});
done(false);
Expand Down
4 changes: 3 additions & 1 deletion lib/es/middlewares/checkForBeforeHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ exports.default = checkForBeforeHook;

var _Q = _interopRequireDefault(require("../Q"));

var _utils = require("../utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function checkForBeforeHook(context, done) {
if (context.match.route.hooks && context.match.route.hooks.before) {
if (context.match.route.hooks && context.match.route.hooks.before && (0, _utils.undefinedOrTrue)(context.navigateOptions, "callHooks")) {
(0, _Q.default)(context.match.route.hooks.before.map(function (f) {
// just so we match the Q interface
return function beforeHookInternal(_, d) {
Expand Down
6 changes: 4 additions & 2 deletions lib/es/middlewares/checkForLeaveHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ exports.default = checkForLeaveHook;

var _Q = _interopRequireDefault(require("../Q"));

var _utils = require("../utils");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function checkForLeaveHook(context, done) {
Expand All @@ -21,10 +23,10 @@ function checkForLeaveHook(context, done) {
if (!oldMatch.route.hooks || !oldMatch.route.hooks.leave) {
leaveLoopDone();
return;
} // no match or different path
} // no match or different path or callHooks=false


if (!context.match || !instance.matchLocation(oldMatch.route.path, context.match.url)) {
if ((0, _utils.undefinedOrTrue)(context.navigateOptions, "callHooks") && (!context.match || !instance.matchLocation(oldMatch.route.path, context.match.url))) {
(0, _Q.default)(oldMatch.route.hooks.leave.map(function (f) {
// just so we match the Q interface
return function (_, d) {
Expand Down
24 changes: 17 additions & 7 deletions lib/navigo.amd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/navigo.amd.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/navigo.amd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/navigo.amd.min.js.map

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions lib/navigo.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/navigo.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit a7367d0

Please sign in to comment.