Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-router-maa

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-router-maa - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

.travis.yml

51

__test__/router/router.transition-middleware.test.js

@@ -227,2 +227,53 @@ import { __PRIVATES__, setCheckIfIsInitialisedFunction, pushTransitionAllowedCheckFunction, isTransitionAllowed } from '../../router/router.transition-middleware';

test('pushing transition allowed check function while transition is being checked will delay the pushing till the currently running check is over', (done) => {
isInitialisedReturn = true;
let resolveFunction;
const transitionAllowedCheckFunction = jestFn(function() {
return new Promise((resolve) => {
resolveFunction = resolve;
});
});
expect(__PRIVATES__.getRouterTransitionAllowedChecks().length).toEqual(0);
expect(__PRIVATES__.getRouterTransitionAllowedChecksPushFunctionsStack().length).toEqual(0);
pushTransitionAllowedCheckFunction(transitionAllowedCheckFunction);
expect(__PRIVATES__.getRouterTransitionAllowedChecks().length).toEqual(1);
expect(__PRIVATES__.getRouterTransitionAllowedChecks()[0].checkFunc).toEqual(transitionAllowedCheckFunction);
expect(__PRIVATES__.getRouterTransitionAllowedChecksPushFunctionsStack().length).toEqual(0);
expect(__PRIVATES__.getIsCheckingIfTransitionIsAllowed()).toEqual(false);
const promise = isTransitionAllowed();
expect(__PRIVATES__.getIsCheckingIfTransitionIsAllowed()).toEqual(true);
const transitionAllowedCheckFunction2 = () => true;
expect(__PRIVATES__.getRouterTransitionAllowedChecks().length).toEqual(1);
expect(__PRIVATES__.getRouterTransitionAllowedChecksPushFunctionsStack().length).toEqual(0);
expect(__PRIVATES__.getIsCheckingIfTransitionIsAllowed()).toEqual(true);
pushTransitionAllowedCheckFunction(transitionAllowedCheckFunction2);
expect(__PRIVATES__.getIsCheckingIfTransitionIsAllowed()).toEqual(true);
expect(__PRIVATES__.getRouterTransitionAllowedChecks().length).toEqual(1);
expect(__PRIVATES__.getRouterTransitionAllowedChecks()[0].checkFunc).toEqual(transitionAllowedCheckFunction);
expect(__PRIVATES__.getRouterTransitionAllowedChecksPushFunctionsStack().length).toEqual(1);
expect(__PRIVATES__.getIsCheckingIfTransitionIsAllowed()).toEqual(true);
resolveFunction(true);
promise
.then((res) => {
expect(__PRIVATES__.getIsCheckingIfTransitionIsAllowed()).toEqual(false);
expect(res).toEqual(true);
expect(__PRIVATES__.getRouterTransitionAllowedChecks().length).toEqual(1); // 1 poped since route allowed and replaced by one from routerTransitionAllowedChecksPushFunctionsStack
expect(__PRIVATES__.getRouterTransitionAllowedChecksPushFunctionsStack().length).toEqual(0);
expect(__PRIVATES__.getRouterTransitionAllowedChecks()[0].checkFunc).toEqual(transitionAllowedCheckFunction2);
done();
})
.catch((err) => {
fail(err);
done();
});
});
test('allow transition is async and by default pops the function once transition is allowed', (done) => {

@@ -229,0 +280,0 @@

4

example/package.json

@@ -14,4 +14,4 @@ {

"react-redux": "^5.1.1",
"react-router-maa": "^2.0.0",
"react-scripts": "2.1.1",
"react-router-maa": "^2.0.2",
"react-scripts": "^2.1.2",
"react-thunk": "^1.0.0",

@@ -18,0 +18,0 @@ "redux": "^4.0.1",

{
"name": "react-router-maa",
"version": "2.0.1",
"version": "2.0.2",
"description": "state based react router linked to url through parseUrl and toUrl functions, has working route blocking control mechanisim, and async initialisation phase",

@@ -5,0 +5,0 @@ "main": "index.js",

import { promisifyFunctionCall, sortedInsert } from "./router.util";
const routerTransitionAllowedChecks = [];
const routerTransitionAllowedChecksPushFunctionsStack = [];

@@ -20,3 +21,9 @@ const AllowNavigationResult = { ForceAllow: true, Deny: false, DontCare: undefined };

};
sortedInsert(routerTransitionAllowedChecks, obj, priorityComareFunc);
const pushFunc = sortedInsert.bind(null, routerTransitionAllowedChecks, obj, priorityComareFunc);
if(isCheckingIfTransitionIsAllowed) {
routerTransitionAllowedChecksPushFunctionsStack.push(pushFunc);
}
else {
pushFunc();
}
return popFunc;

@@ -87,2 +94,6 @@ }

isCheckingIfTransitionIsAllowed = false;
for(let i = 0; i < routerTransitionAllowedChecksPushFunctionsStack.length; i++) {
routerTransitionAllowedChecksPushFunctionsStack[i]();
}
routerTransitionAllowedChecksPushFunctionsStack.splice(0, routerTransitionAllowedChecksPushFunctionsStack.length);
return res;

@@ -101,2 +112,8 @@ });

},
getRouterTransitionAllowedChecksPushFunctionsStack() {
return routerTransitionAllowedChecksPushFunctionsStack;
},
getRouterTransitionAllowedChecks() {
return routerTransitionAllowedChecks;
},
reset() {

@@ -103,0 +120,0 @@ isCheckingIfTransitionIsAllowed = false;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc