Skip to content

Commit b9be1a7

Browse files
committed
not re-rendering
1 parent d7907a3 commit b9be1a7

File tree

11 files changed

+54
-39
lines changed

11 files changed

+54
-39
lines changed

src/features/cseMachine/CseMachineUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export function isMainReference(value: Value, reference: ReferenceType) {
265265
export function isDummyReference(reference: ReferenceType) {
266266
return (
267267
(reference instanceof Binding && reference.isDummyBinding) ||
268-
(reference instanceof ArrayUnit && !reference.parent.isReferenced())
268+
(reference instanceof ArrayUnit && !reference.parent.isReachable())
269269
);
270270
}
271271

src/features/cseMachine/components/ArrayEmptyUnit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class ArrayEmptyUnit extends Visible {
2929
y={this.y()}
3030
width={this.width()}
3131
height={this.height()}
32-
stroke={this.parent.isReferenced() ? reachedStrokeColor() : defaultStrokeColor()}
32+
stroke={this.parent.isReachable() ? reachedStrokeColor() : defaultStrokeColor()}
3333
ref={this.ref}
3434
/>
3535
);

src/features/cseMachine/components/ArrayNullUnit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class ArrayNullUnit extends Visible {
2323
{...ShapeDefaultProps}
2424
key={Layout.key++}
2525
points={[this.x(), this.y() + this.height(), this.x() + this.width(), this.y()]}
26-
stroke={this.reference.parent.isReferenced() ? reachedStrokeColor() : defaultStrokeColor()}
26+
stroke={this.reference.parent.isReachable() ? reachedStrokeColor() : defaultStrokeColor()}
2727
hitStrokeWidth={Config.DataHitStrokeWidth}
2828
ref={this.ref}
2929
listening={false}

src/features/cseMachine/components/Frame.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,13 @@ export class Frame extends Visible implements IHoverable {
178178
CseAnimation.setCurrentFrame(this);
179179
this.setParentChainReachable();
180180
}
181+
182+
console.log('frame constructor');
183+
184+
181185
}
182186

183-
private setParentChainReachable(): void {
187+
public setParentChainReachable(): void {
184188
this.setReachable(true);
185189
this.arrow?.setReachable(true);
186190

@@ -194,6 +198,12 @@ export class Frame extends Visible implements IHoverable {
194198
onMouseLeave = () => {};
195199

196200
draw(): React.ReactNode {
201+
202+
this.bindings.map(binding => binding.key.setReachable(this.isReachable()))
203+
if (this.isReachable() && this.parentFrame) {
204+
this.bindings.map(binding => binding.value.setReachable(true))
205+
}
206+
197207
return (
198208
<Group ref={this.ref} key={Layout.key++}>
199209
{this.name.draw()}
@@ -215,8 +225,8 @@ export class Frame extends Visible implements IHoverable {
215225
onMouseLeave={this.onMouseLeave}
216226
key={Layout.key++}
217227
/>
218-
{this.bindings.map(binding => binding.key.setReachable(this.isReachable()))}
219-
{this.bindings.map(binding => binding.value.setReachable(this.isReachable()))}
228+
{/* {this.bindings.map(binding => binding.key.setReachable(this.isReachable()))}
229+
{this.isReachable() && this.parentFrame && this.bindings.map(binding => binding.value.setReachable(true))} */}
220230
{this.bindings.map(binding => binding.draw())}
221231
{this.arrow?.draw()}
222232
</Group>

src/features/cseMachine/components/StashItemComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class StashItemComponent extends Visible implements IHoverable {
7979
this._x = ControlStashConfig.StashPosX + stackWidth;
8080
this._y = ControlStashConfig.StashPosY;
8181
if (arrowTo) {
82-
arrowTo.markAsReferenced();
82+
arrowTo.setReachable(true);
8383
this.arrow = new ArrowFromStashItemComponent(this).to(arrowTo) as ArrowFromStashItemComponent;
8484
}
8585
}

src/features/cseMachine/components/arrows/ArrowFromFn.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ export class ArrowFromFn extends GenericArrow<FnValue | GlobalFnValue | ContValu
1919

2020
if (!to) return [];
2121

22+
if (this.isReachable() && !to.isReachable()) {
23+
console.log('setting to reachable...');
24+
25+
to.setParentChainReachable();
26+
}
27+
28+
to.draw();
29+
console.log('to', to.isReachable());
30+
console.log(to);
31+
32+
33+
2234
const steps: StepsArray = [
2335
(x, y) =>
2436
this.source instanceof ContValue

src/features/cseMachine/components/arrows/ArrowFromStashItemComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class ArrowFromStashItemComponent extends GenericArrow<
2121
const from = this.source;
2222
const to = this.target;
2323

24-
to?.setReachable(true);
24+
//to?.setReachable(true);
2525
console.log(to);
2626

2727
if (!to) return [];

src/features/cseMachine/components/values/ArrayValue.tsx

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ export class ArrayValue extends Value implements IHoverable {
2727
super();
2828
Layout.memoizeValue(data, this);
2929
this.addReference(firstReference);
30+
console.log('arrayvalue constructor...');
31+
console.log(firstReference);
3032
}
3133

3234
handleNewReference(newReference: ReferenceType): void {
@@ -77,11 +79,13 @@ export class ArrayValue extends Value implements IHoverable {
7779
}
7880
}
7981

80-
markAsReferenced() {
81-
if (this.isReferenced()) return;
82-
super.markAsReferenced();
82+
setReachable(reachable: boolean = true) {
83+
if (this.isReachable()) return;
84+
super.setReachable(reachable);
85+
// Propagate reachability to all array units
8386
for (const unit of this.units) {
84-
unit.value.markAsReferenced();
87+
unit.setReachable(reachable);
88+
unit.value.setReachable(reachable);
8589
}
8690
}
8791

@@ -101,6 +105,8 @@ export class ArrayValue extends Value implements IHoverable {
101105

102106
draw(): React.ReactNode {
103107
if (this.isDrawn()) return null;
108+
console.log('drawingarray...');
109+
console.log(this);
104110
this._isDrawn = true;
105111
return (
106112
<Group
@@ -115,12 +121,4 @@ export class ArrayValue extends Value implements IHoverable {
115121
</Group>
116122
);
117123
}
118-
119-
setReachable(reachable: boolean) {
120-
super.setReachable(reachable);
121-
// Propagate reachability to all array units
122-
this.units.forEach(unit => {
123-
unit.setReachable(reachable);
124-
});
125-
}
126124
}

src/features/cseMachine/components/values/FnValue.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,19 @@ export class FnValue extends Value implements IHoverable {
126126
};
127127

128128
draw(): React.ReactNode {
129+
if (this.isDrawn()) return;
130+
this._isDrawn = true;
131+
129132
if (this.fnName === undefined) {
130133
throw new Error('Closure has no main reference and is not initialised!');
131134
}
132135
if (this.enclosingFrame) {
133136
this._arrow = new ArrowFromFn(this).to(this.enclosingFrame) as ArrowFromFn;
137+
138+
if (this.isReachable()) {
139+
this._arrow.setReachable(true);
140+
}
141+
134142
}
135143
const textColor = this.isReachable() ? reachedTextColor() : defaultTextColor();
136144
const strokeColor = this.isReachable() ? reachedStrokeColor() : defaultStrokeColor();

src/features/cseMachine/components/values/PrimitiveValue.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ export class PrimitiveValue extends Value {
6161
throw new Error('Primitive values cannot have more than one reference!');
6262
}
6363

64-
markAsReferenced() {
65-
if (this.isReferenced()) return;
66-
super.markAsReferenced();
67-
if (this.text instanceof Text) this.text.options.faded = false;
64+
setReachable(reachable: boolean = true) {
65+
if (this.isReachable()) return;
66+
super.setReachable(reachable);
67+
if (this.text instanceof Text) this.text.options.faded = !reachable;
6868
}
6969

7070
draw(): React.ReactNode {

0 commit comments

Comments
 (0)