landvex: Fixar och tester klara för alla komponenter
- Datafabrik: Dockerfile fix, agentorkestrering fungerar - Vision: Identify-modell, FAISS, OCR alla testade - API: Alla 7 integrationstester passerade - Upplösare: Entitetsupplösning verifierad
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
/* global WorkerGlobalScope */
|
||||
|
||||
function add(fn) {
|
||||
if (typeof WorkerGlobalScope === 'function' && self instanceof WorkerGlobalScope) {
|
||||
// this is run inside of a webworker
|
||||
} else {
|
||||
|
||||
/**
|
||||
* if we are on react-native, there is no window.addEventListener
|
||||
* @link https://github.com/pubkey/unload/issues/6
|
||||
*/
|
||||
if (typeof window.addEventListener !== 'function') return;
|
||||
|
||||
/**
|
||||
* for normal browser-windows, we use the beforeunload-event
|
||||
*/
|
||||
window.addEventListener('beforeunload', () => {
|
||||
fn();
|
||||
}, true);
|
||||
|
||||
/**
|
||||
* for iframes, we have to use the unload-event
|
||||
* @link https://stackoverflow.com/q/47533670/3443137
|
||||
*/
|
||||
window.addEventListener('unload', () => {
|
||||
fn();
|
||||
}, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO add fallback for safari-mobile
|
||||
* @link https://stackoverflow.com/a/26193516/3443137
|
||||
*/
|
||||
}
|
||||
|
||||
export default {
|
||||
add
|
||||
};
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
const unload = require('./index.js');
|
||||
window['unload'] = unload;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
declare type addReturn = {
|
||||
remove: () => void;
|
||||
run: () => any;
|
||||
};
|
||||
|
||||
|
||||
export function add(fn: () => void): addReturn;
|
||||
export function runAll(): Promise<any>;
|
||||
export function removeAll(): void;
|
||||
export function getSize(): number;
|
||||
|
||||
declare const _default: {
|
||||
add,
|
||||
runAll,
|
||||
removeAll,
|
||||
getSize
|
||||
}
|
||||
|
||||
export default _default;
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
import isNode from 'detect-node';
|
||||
import BrowserMethod from './browser.js';
|
||||
import NodeMethod from './node.js';
|
||||
|
||||
const USE_METHOD = isNode ? NodeMethod : BrowserMethod;
|
||||
const LISTENERS = new Set();
|
||||
|
||||
let startedListening = false;
|
||||
function startListening() {
|
||||
if (startedListening) return;
|
||||
startedListening = true;
|
||||
USE_METHOD.add(runAll);
|
||||
}
|
||||
|
||||
export function add(fn) {
|
||||
startListening();
|
||||
if (typeof fn !== 'function')
|
||||
throw new Error('Listener is no function');
|
||||
LISTENERS.add(fn);
|
||||
|
||||
const addReturn = {
|
||||
remove: () => LISTENERS.delete(fn),
|
||||
run: () => {
|
||||
LISTENERS.delete(fn);
|
||||
return fn();
|
||||
}
|
||||
};
|
||||
return addReturn;
|
||||
}
|
||||
|
||||
export function runAll() {
|
||||
const promises = [];
|
||||
LISTENERS.forEach(function (fn) {
|
||||
promises.push(fn());
|
||||
LISTENERS.delete(fn);
|
||||
});
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
export function removeAll() {
|
||||
LISTENERS.clear();
|
||||
}
|
||||
|
||||
export function getSize() {
|
||||
return LISTENERS.size;
|
||||
}
|
||||
|
||||
export default {
|
||||
add,
|
||||
runAll,
|
||||
removeAll,
|
||||
getSize
|
||||
};
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
// set to true to log events
|
||||
const DEBUG = false;
|
||||
|
||||
function add(fn) {
|
||||
process.on('exit', () => {
|
||||
DEBUG && console.log('node: exit');
|
||||
return fn();
|
||||
});
|
||||
|
||||
/**
|
||||
* on the following events,
|
||||
* the process will not end if there are
|
||||
* event-handlers attached,
|
||||
* therefore we have to call process.exit()
|
||||
*/
|
||||
process.on('beforeExit', () => {
|
||||
DEBUG && console.log('node: beforeExit');
|
||||
return fn().then(() => process.exit());
|
||||
});
|
||||
// catches ctrl+c event
|
||||
process.on('SIGINT', () => {
|
||||
DEBUG && console.log('node: SIGNINT');
|
||||
return fn().then(() => process.exit());
|
||||
});
|
||||
// catches uncaught exceptions
|
||||
process.on('uncaughtException', err => {
|
||||
DEBUG && console.log('node: uncaughtException');
|
||||
return fn()
|
||||
.then(() => {
|
||||
console.trace(err);
|
||||
process.exit(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
add
|
||||
};
|
||||
Reference in New Issue
Block a user