This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.removeEventListener("beforeunload", beforeUnloadFunction); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.removeEventListener("beforeunload", beforeUnloadFunction); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const links = document.getElementsByTagName("a"); | |
for (var i = 0; i < links.length; i++) { | |
links[i].addEventListener("click", handleClickEvents, false); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import BeforeUnloadComponent from 'react-beforeunload-component'; | |
// React Hook | |
const Example = () => { | |
return ( | |
<div> | |
<BeforeUnloadComponent | |
blockRoute={true} | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import BeforeUnloadComponent from 'react-beforeunload-component'; | |
import MyModal from 'path/MyModal'; | |
// React Hook | |
const Example = () => { | |
return ( | |
<div> | |
<BeforeUnloadComponent | |
blockRoute={true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const db = require('./dbConnection'); | |
const putFunction = require('./controllers/putFunction'); | |
const postFunction = require('./controllers/postFunction'); | |
const YOURMiddleware = require('./YOURMiddleware'); // You can create a private package to make it sharable or you can find a way to share your middleware with other functions. | |
const gcf = new YOURMiddleware() | |
gcf.context({ | |
db | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const postFunction = async (ctx) => { | |
try { | |
const {id} = ctx.req.body; | |
const r = await ctx.db.getData(id); | |
// This respond function is customizable in your middleware | |
ctx.respond(200, r); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// you can create your own path matcher or you can use any url matcher from npm. | |
const route = require('path-match')({ | |
sensitive: true, | |
strict: true, | |
end: true, | |
}); | |
class YOURMiddleware { | |
constructor(opts = {}) { | |
this.stack = []; // Middleware stack |