Move from spitroast to internalized demonpatcher
No more of that christianized Cumcord codetypescript
parent
e2f45acd3e
commit
3848a02879
File diff suppressed because one or more lines are too long
@ -1,5 +1,58 @@
|
||||
//NOTE: this isn't even a wrapper around spitroast, it's more a convienence for importing patcher internally
|
||||
import * as spitroast from "spitroast";
|
||||
function wackyPatch(parentObj, name, patches) {
|
||||
if (typeof parentObj === "string") {
|
||||
//assume parentObj and name are switched around (for backcompat/convienence)
|
||||
const tmp = parentObj
|
||||
parentObj = name
|
||||
name = tmp
|
||||
}
|
||||
const injId = Symbol()
|
||||
const before = patches["before"];
|
||||
const instead = patches["instead"];
|
||||
const after = patches["after"];
|
||||
const handler = {
|
||||
apply: (target, thisArg, [ctx, args]) => {
|
||||
if (before !== undefined) before.apply(ctx, [args]);
|
||||
const res = (patches["instead"] !== undefined) ? instead.apply(ctx, [args, target.bind(ctx)]) : target.apply(ctx, args)
|
||||
if (after === undefined) return res
|
||||
return after.apply(ctx, [args, res]);
|
||||
}
|
||||
};
|
||||
const prox = new Proxy(parentObj[name], handler);
|
||||
const orig = parentObj[name];
|
||||
parentObj[name] = function() {
|
||||
return prox(this, arguments);
|
||||
};
|
||||
const unpatch = () => {
|
||||
parentObj[name] = orig;
|
||||
}
|
||||
parentObj[injId] = {
|
||||
name: name,
|
||||
orig: orig,
|
||||
unpatch: unpatch
|
||||
};
|
||||
return unpatch;
|
||||
}
|
||||
|
||||
export * from "spitroast";
|
||||
export default spitroast;
|
||||
function before(parentObj, name, func) {
|
||||
return wackyPatch(parentObj, name, {before: func})
|
||||
}
|
||||
|
||||
function instead(parentObj, name, func) {
|
||||
return wackyPatch(parentObj, name, {instead: func})
|
||||
}
|
||||
|
||||
function after(parentObj, name, func) {
|
||||
return wackyPatch(parentObj, name, {after: func})
|
||||
}
|
||||
|
||||
export {
|
||||
instead,
|
||||
before,
|
||||
after
|
||||
}
|
||||
|
||||
export default {
|
||||
instead,
|
||||
before,
|
||||
after
|
||||
}
|
Loading…
Reference in new issue