Skip to content

Commit

Permalink
feat: remove operations array, apply naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
JanLewDev committed Dec 30, 2024
1 parent 1ebcbb5 commit 54223fc
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 31 deletions.
2 changes: 1 addition & 1 deletion examples/canvas/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function paint_pixel(pixel: HTMLDivElement) {
random_int(256),
];
canvasDRP.paint([x, y], painting);
const [r, g, b] = canvasDRP.pixel(x, y).color();
const [r, g, b] = canvasDRP.getPixel(x, y).color();
pixel.style.backgroundColor = `rgb(${r}, ${g}, ${b})`;
}

Expand Down
2 changes: 1 addition & 1 deletion examples/canvas/src/objects/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Canvas implements DRP {
this.canvas[offset[0]][offset[1]].paint(rgb);
}

pixel(x: number, y: number): Pixel {
getPixel(x: number, y: number): Pixel {
return this.canvas[x][y];
}

Expand Down
5 changes: 2 additions & 3 deletions packages/blueprints/src/AddWinsSet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from "@ts-drp/object";

export class AddWinsSet<T> implements DRP {
operations: string[] = ["add", "remove"];
state: Map<T, boolean>;
semanticsType = SemanticsType.pair;

Expand All @@ -31,11 +30,11 @@ export class AddWinsSet<T> implements DRP {
this._remove(value);
}

contains(value: T): boolean {
queryContains(value: T): boolean {
return this.state.get(value) === true;
}

values(): T[] {
getValues(): T[] {
return Array.from(this.state.entries())
.filter(([_, exists]) => exists)
.map(([value, _]) => value);
Expand Down
8 changes: 4 additions & 4 deletions packages/blueprints/src/AddWinsSetWithACL/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ export class AddWinsSetWithACL<T> implements DRP {
this._remove(value);
}

contains(value: T): boolean {
queryContains(value: T): boolean {
return this.state.get(value) === true;
}

values(): T[] {
getValues(): T[] {
return Array.from(this.state.entries())
.filter(([_, exists]) => exists)
.map(([value, _]) => value);
Expand All @@ -62,14 +62,14 @@ export class AddWinsSetWithACL<T> implements DRP {

if (
this.acl?.operations.includes(vertices[0].operation.type) &&

Check failure on line 64 in packages/blueprints/src/AddWinsSetWithACL/index.ts

View workflow job for this annotation

GitHub Actions / tests

packages/blueprints/tests/AddWinsSetWithACL.test.ts > AccessControl tests with RevokeWins resolution > Resolve conflicts with RevokeWins

TypeError: Cannot read properties of undefined (reading 'includes') ❯ AddWinsSetWithACL.resolveConflicts packages/blueprints/src/AddWinsSetWithACL/index.ts:64:14 ❯ packages/blueprints/tests/AddWinsSetWithACL.test.ts:58:22
this.acl?.operations.includes(vertices[0].operation.type)
this.acl?.operations.includes(vertices[1].operation.type)
) {
return this.acl.resolveConflicts(vertices);
}

if (
this.operations.includes(vertices[0].operation.type) &&
this.operations.includes(vertices[0].operation.type)
this.operations.includes(vertices[1].operation.type)
) {
return vertices[0].operation.type === "add"
? { action: ActionType.DropRight }
Expand Down
4 changes: 2 additions & 2 deletions packages/blueprints/src/PseudoRandomWinsSet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ export class PseudoRandomWinsSet<T> implements DRP {
this._remove(value);
}

contains(value: T): boolean {
queryContains(value: T): boolean {
return this.state.get(value) === true;
}

values(): T[] {
getValues(): T[] {
return Array.from(this.state.entries())
.filter(([_, exists]) => exists)
.map(([value, _]) => value);
Expand Down
29 changes: 9 additions & 20 deletions packages/object/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ export class DRPObject implements IDRPObject {
if (typeof target[propKey as keyof object] === "function") {
return new Proxy(target[propKey as keyof object], {
apply(applyTarget, thisArg, args) {
if (!(propKey as string).startsWith("_"))
if (
!(propKey as string).startsWith("_") &&
!(propKey as string).startsWith("is") &&
!(propKey as string).startsWith("get") &&
!(propKey as string).startsWith("query")
)
obj.callFn(
propKey as string,
args.length === 1 ? args[0] : args,
Expand All @@ -130,12 +135,8 @@ export class DRPObject implements IDRPObject {
}
const preOperationState = this._computeState(this.hashGraph.getFrontier());

const drp = Object.create(
Object.getPrototypeOf(this.originalDRP),
Object.getOwnPropertyDescriptors(structuredClone(this.originalDRP)),
) as DRP;

const state = structuredClone(preOperationState);
const drp = cloneDeep(this.originalDRP);
const state = cloneDeep(preOperationState);

for (const [key, value] of state.entries()) {
drp[key] = value;
Expand All @@ -158,20 +159,8 @@ export class DRPObject implements IDRPObject {
return;
}

for (const [key, value] of preOperationState.entries()) {
console.log("before", key, value);
console.log("after", key, drp[key]);
try {
deepStrictEqual(value, drp[key]);
console.log("they are equal");
} catch (e) {
stateChanged = true;
console.log("they are different");
}
}

const vertex = this.hashGraph.addToFrontier({ type: fn, value: args });
console.log("vertex", vertex);

const varNames: string[] = Object.keys(drp);
// biome-ignore lint: values can be anything
const newState: Map<string, any> = new Map();
Expand Down

0 comments on commit 54223fc

Please sign in to comment.