Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement deleteObjs method in Circuit #1228

Closed
wants to merge 18 commits into from

Conversation

Tevetron
Copy link

@Tevetron Tevetron commented Feb 10, 2023

No description provided.

@Tevetron Tevetron changed the base branch from master to model_refactor_api February 10, 2023 23:50
src/app/core/public/api/impl/Circuit.ts Outdated Show resolved Hide resolved
src/app/core/public/api/impl/Circuit.ts Outdated Show resolved Hide resolved
src/app/core/public/api/impl/Circuit.ts Outdated Show resolved Hide resolved
src/app/core/public/api/impl/Circuit.ts Show resolved Hide resolved
src/app/core/internal/impl/CircuitInternal.ts Outdated Show resolved Hide resolved
src/app/tests/DeleteObjects.test.ts Outdated Show resolved Hide resolved
actually delete from the circuit as opposed to deleting from the given array
Copy link
Member

@LeonMontealegre LeonMontealegre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

Please make sure to update your branch though, there are some merge conflicts

protected get selections(): SelectionsManager {
return this.state.selections;
}

public get kind(): string {
throw new Error("Unimplemented");
const tmp = this.circuit.getObjByID(this.objID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: called this obj

throw new Error("Unimplemented");
const tmp = this.circuit.getObjByID(this.objID);
if(!tmp)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't need brackets

public getProp(key: string): Prop {
throw new Error("Unimplemented");
const tmp = this.circuit.getObjByID(this.objID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: call this obj

throw new Error("Unimplemented");
const tmp = this.circuit.getObjByID(this.objID);
if(!tmp)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't need brackets

public getProps(): Record<string, Prop> {
throw new Error("Unimplemented");
const tmp = this.circuit.getObjByID(this.objID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: call this obj

const circuit = CreateCircuit();

const a = circuit.placeComponentAt(V(0, 0), "ANDGate");
expect(a.getProp('x')).toEqual(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use " not '

Comment on lines 41 to 42
let cArray: Component[] = [a];
circuit.deleteObjs(cArray);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do circuit.deleteObjs([a])

Comment on lines 15 to 16
let cArray: Component[] = [c];
circuit.deleteObjs(cArray);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just do circuit.deleteObjs([c])

src/app/tests/DeleteObjects.test.ts Outdated Show resolved Hide resolved
expect(s1.exists()).toEqual(false);
expect(s2.exists()).toEqual(false);
expect(l1.exists()).toEqual(false);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also add some tests for when there are connections between components, and things like deleting a component that has connections and making sure the wires were deleted

@LeonMontealegre
Copy link
Member

Also please update the title and description to provide some more useful information about the PR

@Tevetron Tevetron changed the title Model refactor api friedj friedj BaseObject api methods Apr 7, 2023
@LeonMontealegre LeonMontealegre changed the title friedj BaseObject api methods Implement deleteObjs method in Circuit Apr 8, 2023
@@ -1,5 +1,6 @@
import {BaseObject} from "./BaseObject";
import {Component} from "./Component";
import {Wire} from "./Wire";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spacing

*/
public deleteObjs(objs: Obj[]): void {
this.circuit.beginTransaction();
for(const obj of objs) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spacing

this.circuit.beginTransaction();
for(const obj of objs)
{
if(obj.baseKind == "Port") { continue; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix

this.circuit.beginTransaction();
for(const obj of objs) {
if(obj.baseKind == "Port") { continue; }
if(obj.baseKind == "Component") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spacing
nit: use ===

if(obj.baseKind == "Port") { continue; }
if(obj.baseKind == "Component")
{
this.circuit.setPortConfig(obj.id, {});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix

const circuit = CreateCircuit();

const c = circuit.placeComponentAt(V(0, 0), "ANDGate");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect a.exists() to be true before deleting it

const s1 = circuit.placeComponentAt(V(-5, 5), "Switch");
const s2 = circuit.placeComponentAt(V(-5, -5), "Switch");
const l1 = circuit.placeComponentAt(V(5, 0), "LED");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect them to exist before deleting it as well


const w1 = s1.ports["outputs"][0].connectTo(g.ports["inputs"][0]),
w2 = s2.ports["outputs"][0].connectTo(g.ports["inputs"][1]),
w3 = g.ports["outputs"][0].connectTo(l.ports["inputs"][0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't comma separate, just declare const for each of them

Comment on lines +52 to +54
//TODO test for wires existing
//TODO ensure deletion working properly for full circuit
//none of my test cases are working properly right now unfortunately
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do the TODOs or remove them

//TODO test for wires existing
//TODO ensure deletion working properly for full circuit
//none of my test cases are working properly right now unfortunately
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test case for deleting just a wire, make sure the components and ports still exist
Add one for deleting just the ANDGate from the above circuit, and expect that the Switches and LED still exist while all the wires and the ANDGate were deleted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants