mami/src/mami.js/compat.js
flashwave 53258703e1 Removed Umi.Server object.
It still gets defined by the compatibility dingus though.
2024-02-29 23:57:36 +00:00

22 lines
568 B
JavaScript

const MamiCompat = (path, handler) => {
if(typeof path !== 'string')
throw 'path must be a string';
if(typeof handler !== 'object')
throw 'handler must be a property definition';
path = path.split('.');
const final = path.pop();
if(final === undefined)
throw 'invalid path';
let current = window;
for(const part of path) {
if(!(part in current))
current[part] = {};
current = current[part];
}
if(!(final in current))
Object.defineProperty(current, final, handler);
};