Skip to content

Commit 4cebade

Browse files
committed
AEDebugging_ Add sourceCode to callback changes, add more hook location data and bugfixes
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-injective-map.js,AUTO-COMMIT-src-client-reactive-babel-plugin-active-expression-rewriting-index.js,AUTO-COMMIT-src-client-reactive-components-basic-aexpr-timeline.js,AUTO-COMMIT-src-client-reactive-components-rewritten-aexpr-test-component.js,AUTO-COMMIT-src-client-utils-stack.js,AUTO-COMMIT-src-client-utils-stack.js.l4a,
1 parent eedbb22 commit 4cebade

File tree

8 files changed

+56
-27
lines changed

8 files changed

+56
-27
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ class Dependency {
152152
const compKey = CompositeKeyToDependencies.getLeftFor(this);
153153
CompositeKeyToDependencies.removeRight(this);
154154
HooksToDependencies.disconnectAllForDependency(this);
155-
ContextAndIdentifierCompositeKey.remove(compKey);
155+
156+
if(!CompositeKeyToDependencies.hasLeft(compKey)) {
157+
ContextAndIdentifierCompositeKey.remove(compKey);
158+
}
156159
}
157160

158161
contextIdentifierValue() {
@@ -582,13 +585,16 @@ class Hook {
582585

583586
async getLocations() {
584587
this.locations = await Promise.all(this.locations);
588+
this.locations = this.locations.filter(l => l);
585589
return this.locations;
586590
}
587591

588592
untrack() {}
589593

590-
notifyDependencies(location) {
591-
HooksToDependencies.getDepsForHook(this).forEach(dep => dep.notifyAExprs(location));
594+
notifyDependencies(location) {
595+
const loc = location || TracingHandler.findRegistrationLocation();
596+
this.addLocation(loc);
597+
HooksToDependencies.getDepsForHook(this).forEach(dep => dep.notifyAExprs(loc));
592598

593599
this.getLocations().then(locations => DebuggingCache.updateFiles(locations.map(loc => loc.file)));
594600
for (const dep of HooksToDependencies.getDepsForHook(this)) {
@@ -666,9 +672,7 @@ class DataStructureHook extends Hook {
666672
}
667673

668674
this; // references the modified container
669-
const location = TracingHandler.findRegistrationLocation();
670-
hook.addLocation(location);
671-
hook.notifyDependencies(location);
675+
hook.notifyDependencies();
672676
});
673677
} else {
674678
// console.warn(`Property ${addDescriptor.key} has a value that is not a function, but ${addDescriptor.value}.`)
@@ -949,21 +953,18 @@ class TracingHandler {
949953
static memberUpdated(obj, prop, location) {
950954
const hook = SourceCodeHook.get(obj, prop);
951955
if (!hook) return;
952-
hook.addLocation(location || TracingHandler.findRegistrationLocation());
953956
hook.notifyDependencies(location);
954957
}
955958

956959
static globalUpdated(globalName, location) {
957960
const hook = SourceCodeHook.get(globalRef, globalName);
958961
if (!hook) return;
959-
hook.addLocation(location || TracingHandler.findRegistrationLocation());
960962
hook.notifyDependencies(location);
961963
}
962964

963965
static localUpdated(scope, varName, location) {
964966
const hook = SourceCodeHook.get(scope, varName);
965967
if (!hook) return;
966-
hook.addLocation(location || TracingHandler.findRegistrationLocation());
967968
hook.notifyDependencies(location);
968969
}
969970

@@ -977,6 +978,13 @@ class TracingHandler {
977978
return await frame.getSourceLocBabelStyle();
978979
}
979980
}
981+
982+
for (let frame of frames.slice()) {
983+
if (frame.func.includes(".notifyDependencies")) {
984+
return await frame.getSourceLocBabelStyle();
985+
}
986+
}
987+
console.log(stack);
980988
return undefined;
981989
}
982990

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ export default class InjectiveMap {
1414
return this.leftToRight.get(left);
1515
}
1616

17-
hasRightFor(left) {
17+
hasLeft(left) {
1818
return this.leftToRight.has(left);
1919
}
2020

2121
getOrCreateRightFor(left, constructorCallback) {
22-
if (!this.hasRightFor(left)) {
22+
if (!this.hasLeft(left)) {
2323
this.associate(left, constructorCallback(left));
2424
}
2525
return this.leftToRight.get(left);
@@ -37,12 +37,12 @@ export default class InjectiveMap {
3737
return this.rightToLeft.get(right);
3838
}
3939

40-
hasLeftFor(right) {
40+
hasRight(right) {
4141
return this.rightToLeft.has(right);
4242
}
4343

4444
getOrCreateLeftFor(right, constructorCallback) {
45-
if (!this.hasLeftFor(right)) {
45+
if (!this.hasRight(right)) {
4646
this.associate(constructorCallback(right), right);
4747
}
4848
return this.rightToLeft.get(right);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ export class BaseActiveExpression {
289289
* @param callback
290290
* @returns {BaseActiveExpression} this very active expression (for chaining)
291291
*/
292-
onChange(callback) {
292+
onChange(callback, originalSource) {
293293
this.callbacks.push(callback);
294-
this.logEvent('callbacks changed', 'Added: ' + callback);
294+
this.logEvent('callbacks changed', 'Added: ' + originalSource.sourceCode);
295295
AExprRegistry.updateAExpr(this);
296296
return this;
297297
}
@@ -301,11 +301,11 @@ export class BaseActiveExpression {
301301
* @returns {BaseActiveExpression} this very active expression (for chaining)
302302
*/
303303
// #TODO: should this remove all occurences of the callback?
304-
offChange(callback) {
304+
offChange(callback, originalSource) {
305305
const index = this.callbacks.indexOf(callback);
306306
if (index > -1) {
307307
this.callbacks.splice(index, 1);
308-
this.logEvent('callbacks', 'Removed: ' + callback);
308+
this.logEvent('callbacks', 'Removed: ' + originalSource.sourceCode);
309309
AExprRegistry.updateAExpr(this);
310310
}
311311
if (this._shouldDisposeOnLastCallbackDetached && this.callbacks.length === 0) {
@@ -471,9 +471,9 @@ export class BaseActiveExpression {
471471
return this;
472472
}
473473

474-
dataflow(callback) {
474+
dataflow(callback, orignalSource) {
475475
// setup dependency
476-
this.onChange(callback);
476+
this.onChange(callback, orignalSource);
477477

478478
// call immediately
479479
// #TODO: duplicated code: we should extract this call

src/client/reactive/babel-plugin-active-expression-rewriting/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,21 @@ export default function (babel) {
779779
if (isInDestructuringAssignment(path)) {
780780
return;
781781
}
782+
783+
if(t.isMemberExpression(path.node.callee)) {
784+
const methodName = path.node.callee.property.name;
785+
if(methodName === "dataflow" || methodName === "onChange" || methodName === "offChange") {
786+
const args = path.get('arguments');
787+
if (args.length > 0) {
788+
const expressionPath = args[0];
789+
const sourceCode = expressionPath.getSource();
790+
debugger;
791+
path.pushContainer('arguments', t.objectExpression([t.objectProperty(t.identifier("sourceCode"), t.stringLiteral(sourceCode))]));
792+
}
793+
//addOriginalSourceCode(path);
794+
return;
795+
}
796+
}
782797

783798
// check whether we call a MemberExpression
784799
if (t.isMemberExpression(path.node.callee)) {

src/client/reactive/components/basic/aexpr-timeline.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,14 @@ export default class EventDrops extends Morph {
173173
const stack = data.value.stack;
174174
const locations = await Promise.all(stack.frames.map(frame => frame.getSourceLocBabelStyle()));
175175
locations.forEach((location, index) => {
176-
const isAELoaction = aeLocation.file === location.file && aeLocation.start.line === location.start.line;
177-
menuItems.push([this.fileNameString(location.file) + ":" + location.start.line, () => {
178-
this.openLocationInBrowser(isAELoaction ? aeLocation : location);
179-
}, isAELoaction ? "aexpr call" : "", index + 1]);
176+
if(!location) {
177+
menuItems.push(["anonymous", () => {}, "", index + 1]);
178+
} else {
179+
const isAELoaction = aeLocation.file === location.file && aeLocation.start.line === location.start.line;
180+
menuItems.push([this.fileNameString(location.file) + ":" + location.start.line, () => {
181+
this.openLocationInBrowser(isAELoaction ? aeLocation : location);
182+
}, isAELoaction ? "aexpr call" : "", index + 1]);
183+
}
180184
});
181185
break;
182186
}
@@ -295,7 +299,6 @@ export default class EventDrops extends Morph {
295299
updateTimeline(aexprs) {
296300
const checkedIndices = jQuery(this.aeOverview).jstree(true).get_bottom_selected();
297301
const selectedAEs = checkedIndices.map(i => aexprs[i - 1]).filter(ae => ae);
298-
this.updateValuesOverTime(selectedAEs);
299302
let scrollBefore = this.diagram.scrollTop;
300303
let groups = selectedAEs.groupBy(this.getGroupingFunction());
301304
groups = Object.keys(groups).map(each => ({
@@ -328,6 +331,7 @@ export default class EventDrops extends Morph {
328331
this.chart.scale().domain(newDomain);
329332
this.chart.zoomToDomain(newDomain);
330333
this.diagram.scrollTop = scrollBefore;
334+
this.updateValuesOverTime(selectedAEs);
331335
}
332336

333337
updateValuesOverTime(aexprs) {
@@ -361,7 +365,8 @@ export default class EventDrops extends Morph {
361365
this.chart.zoomToDomain([min, max]);
362366
//Add delay to allow rerender
363367
setTimeout(() => {
364-
const selectedDrops = this.shadowRoot.querySelectorAll(".drop[cx=\"437\"]")
368+
const referenceItem = this.shadowRoot.querySelector(".domain");
369+
const selectedDrops = this.shadowRoot.querySelectorAll(".drop[cx=\"" + referenceItem.getBoundingClientRect().width/2 + "\"]")
365370
.filter(drop => {
366371
const dropLineName = drop.parentElement.nextElementSibling.innerHTML;
367372
let dropLineAEName = dropLineName.substring(0, dropLineName.lastIndexOf(" "));

src/client/reactive/components/rewritten/aexpr-test-component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class AexprTest extends Morph {
1818

1919
addAE() {
2020
let z = 4;
21-
this.aes.push(aexpr(() => this.x.getBestOption() + this.y + z));
21+
this.aes.push(aexpr(() => this.x.getBestOption() + this.y + z + 8).onChange(lively.notify));
2222
this.aes.push(aexpr(() => this.x.getBestOption() + this.y + z));
2323
z++;
2424
}

src/client/utils/stack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ export class Frame {
205205
async getSourceLocBabelStyle() {
206206
if(!this._sourceLoc) {
207207
await this._determineSourceInfo();
208+
if(!this._sourceLoc) return undefined;
208209
}
209210
const location = {line: this._sourceLoc.line, column: this._sourceLoc.column};
210211
return {start: location, end: location, file: this._sourceLoc.source};

0 commit comments

Comments
 (0)