Skip to content

Commit

Permalink
chore: more code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Percslol committed Dec 9, 2024
1 parent f022024 commit a5a99ea
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 23 deletions.
39 changes: 18 additions & 21 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,18 @@ export class ScramjetClient {
get: (target, prop: string) => {
if (prop in target) {
return target[prop];
} else {
const split = prop.split(".");
const realProp = split.pop();
const realTarget = split.reduce((a, b) => a?.[b], this.global);
}

if (!realTarget) return;
const split = prop.split(".");
const realProp = split.pop();
const realTarget = split.reduce((a, b) => a?.[b], this.global);

const original = Reflect.get(realTarget, realProp);
target[prop] = original;
if (!realTarget) return;

return target[prop];
}
const original = Reflect.get(realTarget, realProp);
target[prop] = original;

return target[prop];
},
}
);
Expand All @@ -147,21 +147,18 @@ export class ScramjetClient {
get: (target, prop: string) => {
if (prop in target) {
return target[prop];
} else {
const split = prop.split(".");
const realProp = split.pop();
const realTarget = split.reduce((a, b) => a?.[b], this.global);
}

if (!realTarget) return;
const split = prop.split(".");
const realProp = split.pop();
const realTarget = split.reduce((a, b) => a?.[b], this.global);

const original = nativeGetOwnPropertyDescriptor(
realTarget,
realProp
);
target[prop] = original;
if (!realTarget) return;

return target[prop];
}
const original = nativeGetOwnPropertyDescriptor(realTarget, realProp);
target[prop] = original;

return target[prop];
},
}
);
Expand Down
12 changes: 10 additions & 2 deletions src/client/dom/attr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ export default function (client: ScramjetClient, _self: typeof window) {

client.Trap("Attr.prototype.value", {
get(ctx) {
return ctx.this.ownerElement?.getAttribute(ctx.this.name);
if (ctx.this?.ownerElement) {
return ctx.this.ownerElement.getAttribute(ctx.this.name);
}

return ctx.get();
},
set(ctx, value) {
return ctx.this.ownerElement?.setAttribute(ctx.this.name, value);
if (ctx.this?.ownerElement) {
return ctx.this.ownerElement.setAttribute(ctx.this.name, value);
}

return ctx.set(value);
},
});
}
6 changes: 6 additions & 0 deletions src/client/dom/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ export default function (client: ScramjetClient, self: typeof window) {
},
});

client.Proxy("Element.prototype.getAttributeNode", {
apply(ctx) {
if (ctx.args[0].startsWith("scramjet-attr")) return ctx.return(null);
},
});

client.Proxy("Element.prototype.hasAttribute", {
apply(ctx) {
if (ctx.args[0].startsWith("scramjet-attr")) return ctx.return(false);
Expand Down

0 comments on commit a5a99ea

Please sign in to comment.