Skip to content

Commit 18ce714

Browse files
committed
AEDebugging_ Improve multimap implementation and fix events not showing in code view
SQUASHED: AUTO-COMMIT-src-client-reactive-active-expression-active-expression.js,AUTO-COMMIT-src-client-reactive-active-expression-rewriting-active-expression-rewriting.js,AUTO-COMMIT-src-client-reactive-active-expression-rewriting-bidirectional-multi-map.js,AUTO-COMMIT-src-components-widgets-lively-code-mirror.js,
1 parent 685af8d commit 18ce714

File tree

4 files changed

+46
-34
lines changed

4 files changed

+46
-34
lines changed

src/client/reactive/active-expression-rewriting/active-expression-rewriting.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ class Dependency {
161161
return [context, identifier, value];
162162
}
163163

164-
notifyAExprs() {
164+
notifyAExprs(location) {
165165
const aexprs = DependenciesToAExprs.getAExprsForDep(this);
166-
DependencyManager.checkAndNotifyAExprs(aexprs);
166+
DependencyManager.checkAndNotifyAExprs(aexprs, location);
167167
}
168168

169169
isMemberDependency() {
@@ -339,7 +339,7 @@ export class AEDebuggingCache {
339339
}
340340
/*MD ## Rewriting API MD*/
341341
updateFiles(files) {
342-
if(!files) return;
342+
if (!files) return;
343343
files.forEach(file => this.changedFiles.add(file));
344344
this.debouncedUpdateDebuggingViews();
345345
}
@@ -406,7 +406,7 @@ const DependenciesToAExprs = {
406406
const location = aexpr.meta().get("location");
407407
if (location && location.file) {
408408
DebuggingCache.updateFiles([location.file]);
409-
if( this._AEsPerFile.has(location.file)) {
409+
if (this._AEsPerFile.has(location.file)) {
410410
this._AEsPerFile.get(location.file).delete(aexpr);
411411
}
412412
}
@@ -430,9 +430,11 @@ const DependenciesToAExprs = {
430430
},
431431

432432
getAExprsForDep(dep) {
433+
if(!this._depsToAExprs.hasLeft(dep)) return [];
433434
return Array.from(this._depsToAExprs.getRightsFor(dep));
434435
},
435436
getDepsForAExpr(aexpr) {
437+
if(!this._depsToAExprs.hasRight(aexpr)) return [];
436438
return Array.from(this._depsToAExprs.getLeftsFor(aexpr));
437439
},
438440

@@ -461,7 +463,7 @@ const HooksToDependencies = {
461463
// Track affected files
462464
hook.getLocations().then(locations => DebuggingCache.updateFiles(locations.map(loc => loc.file)));
463465
for (const ae of DependenciesToAExprs.getAExprsForDep(dep)) {
464-
if(ae.meta().has("location")) {
466+
if (ae.meta().has("location")) {
465467
DebuggingCache.updateFiles([ae.meta().get("location").file]);
466468
}
467469
}
@@ -472,8 +474,8 @@ const HooksToDependencies = {
472474

473475
// Track affected files
474476
hook.getLocations().then(locations => DebuggingCache.updateFiles(locations.map(loc => loc.file)));
475-
for (const ae of DependenciesToAExprs.getAExprsForDep(dep)) {
476-
if(ae.meta().has("location")) {
477+
for (const ae of DependenciesToAExprs.getAExprsForDep(dep)) {
478+
if (ae.meta().has("location")) {
477479
DebuggingCache.updateFiles([ae.meta().get("location").file]);
478480
}
479481
}
@@ -498,17 +500,19 @@ const HooksToDependencies = {
498500
for (const hook of HooksToDependencies.getHooksForDep(dep)) {
499501
hook.getLocations().then(locations => DebuggingCache.updateFiles(locations.map(loc => loc.file)));
500502
}
501-
for (const ae of DependenciesToAExprs.getAExprsForDep(dep)) {
502-
if(ae.meta().has("location")) {
503+
for (const ae of DependenciesToAExprs.getAExprsForDep(dep)) {
504+
if (ae.meta().has("location")) {
503505
DebuggingCache.updateFiles([ae.meta().get("location").file]);
504506
}
505507
}
506508
},
507509

508510
getDepsForHook(hook) {
511+
if(!this._hooksToDeps.hasLeft(hook)) return [];
509512
return Array.from(this._hooksToDeps.getRightsFor(hook));
510513
},
511514
getHooksForDep(dep) {
515+
if(!this._hooksToDeps.hasRight(dep)) return [];
512516
return Array.from(this._hooksToDeps.getLeftsFor(dep));
513517
},
514518

@@ -577,13 +581,13 @@ class Hook {
577581
return this.locations;
578582
}
579583

580-
notifyDependencies() {
581-
HooksToDependencies.getDepsForHook(this).forEach(dep => dep.notifyAExprs());
582-
584+
notifyDependencies(location) {
585+
HooksToDependencies.getDepsForHook(this).forEach(dep => dep.notifyAExprs(location));
586+
583587
this.getLocations().then(locations => DebuggingCache.updateFiles(locations.map(loc => loc.file)));
584588
for (const dep of HooksToDependencies.getDepsForHook(this)) {
585589
for (const ae of DependenciesToAExprs.getAExprsForDep(dep)) {
586-
if(ae.meta().has("location")) {
590+
if (ae.meta().has("location")) {
587591
DebuggingCache.updateFiles([ae.meta().get("location").file]);
588592
}
589593
}
@@ -652,8 +656,9 @@ class DataStructureHook extends Hook {
652656
}
653657

654658
this; // references the modified container
655-
hook.addLocation(TracingHandler.findRegistrationLocation());
656-
hook.notifyDependencies();
659+
const location = TracingHandler.findRegistrationLocation();
660+
hook.addLocation(location);
661+
hook.notifyDependencies(location);
657662
});
658663
} else {
659664
// console.warn(`Property ${addDescriptor.key} has a value that is not a function, but ${addDescriptor.value}.`)
@@ -897,9 +902,9 @@ class DependencyManager {
897902
}
898903

899904
// #TODO, #REFACTOR: extract into configurable dispatcher class
900-
static checkAndNotifyAExprs(aexprs) {
905+
static checkAndNotifyAExprs(aexprs, location) {
901906
aexprs.forEach(aexpr => aexpr.updateDependencies());
902-
aexprs.forEach(aexpr => aexpr.checkAndNotify());
907+
aexprs.forEach(aexpr => aexpr.checkAndNotify(location));
903908
}
904909

905910
/**
@@ -935,21 +940,21 @@ class TracingHandler {
935940
const hook = SourceCodeHook.get(obj, prop);
936941
if (!hook) return;
937942
hook.addLocation(location || TracingHandler.findRegistrationLocation());
938-
hook.notifyDependencies();
943+
hook.notifyDependencies(location);
939944
}
940945

941946
static globalUpdated(globalName, location) {
942947
const hook = SourceCodeHook.get(globalRef, globalName);
943948
if (!hook) return;
944949
hook.addLocation(location || TracingHandler.findRegistrationLocation());
945-
hook.notifyDependencies();
950+
hook.notifyDependencies(location);
946951
}
947952

948953
static localUpdated(scope, varName, location) {
949954
const hook = SourceCodeHook.get(scope, varName);
950955
if (!hook) return;
951956
hook.addLocation(location || TracingHandler.findRegistrationLocation());
952-
hook.notifyDependencies();
957+
hook.notifyDependencies(location);
953958
}
954959

955960
static async findRegistrationLocation() {

src/client/reactive/active-expression-rewriting/bidirectional-multi-map.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ export default class BidirectionalMultiMap {
44
this.domainToRange = new Map();
55
this.rangeToDomain = new Map();
66
}
7-
7+
88
associate(left, right) {
99
this.getRightsFor(left).add(right);
1010
this.getLeftsFor(right).add(left);
1111
}
12-
12+
1313
remove(left, right) {
14-
this.getRightsFor(left).delete(right);
15-
this.getLeftsFor(right).delete(left);
14+
const rights = this.getRightsFor(left);
15+
rights.delete(right);
16+
if(rights.size === 0) this.domainToRange.delete(left);
17+
18+
const lefts = this.getLeftsFor(right);
19+
lefts.delete(left);
20+
if(lefts.size === 0) this.rangeToDomain.delete(right);
1621
}
1722

1823
removeAllRightFor(left) {
@@ -27,11 +32,11 @@ export default class BidirectionalMultiMap {
2732
this.domainToRange.clear();
2833
this.rangeToDomain.clear();
2934
}
30-
31-
hasRight(val) {
35+
36+
hasRight(val) {
3237
return this.rangeToDomain.has(val);
3338
}
34-
39+
3540
hasLeft(val) {
3641
return this.domainToRange.has(val);
3742
}
@@ -43,7 +48,7 @@ export default class BidirectionalMultiMap {
4348
getLeftsFor(right) {
4449
return this.rangeToDomain.getOrCreate(right, () => new Set());
4550
}
46-
51+
4752
getAllLeft() {
4853
return Array.from(this.domainToRange.keys());
4954
}
@@ -52,4 +57,4 @@ export default class BidirectionalMultiMap {
5257
return Array.from(this.rangeToDomain.keys());
5358
}
5459

55-
}
60+
}

src/client/reactive/active-expression/active-expression.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export class BaseActiveExpression {
320320
* Mainly for implementation strategies.
321321
* @public
322322
*/
323-
checkAndNotify() {
323+
checkAndNotify(location) {
324324
if (!this._isEnabled) {
325325
return;
326326
}
@@ -331,9 +331,10 @@ export class BaseActiveExpression {
331331
}
332332
const lastValue = this.lastValue;
333333
this.storeResult(value);
334-
this.findCallee().then(trigger => {
335-
this.logEvent('changed value', { value, trigger, lastValue });
336-
});
334+
Promise.resolve(location)
335+
.then(trigger => this.logEvent('changed value', { value, trigger, lastValue }));
336+
//this.findCallee().then(trigger => {
337+
//});
337338

338339
this.notify(value, {
339340
lastValue,

src/components/widgets/lively-code-mirror.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,8 @@ export default class LivelyCodeMirror extends HTMLElement {
15261526
const AELine = AELocation.start.line - 1;
15271527

15281528
var valueChangedEvents = ae.meta().get("events").filter(event => event.type === "changed value");
1529-
const relatedEvents = valueChangedEvents.filter(event => event.value.trigger.source.includes(dependencyFile) && event.value.trigger.line - 1 === dependencyLine);
1529+
debugger;
1530+
const relatedEvents = valueChangedEvents.filter(event => dependencyFile.includes(event.value.trigger.file) && event.value.trigger.start.line - 1 === dependencyLine);
15301531

15311532
if (dependencyFile.includes(this.fileURL())) {
15321533
// Dependency is in this file

0 commit comments

Comments
 (0)