Skip to content

Commit 55413b7

Browse files
committed
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core into gh-pages
2 parents 8db3113 + 61ef7fe commit 55413b7

File tree

5 files changed

+448
-51
lines changed

5 files changed

+448
-51
lines changed

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

Lines changed: 76 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export class AEDebuggingCache {
221221
constructor() {
222222
this.registeredDebuggingViews = [];
223223
this.debouncedUpdateDebuggingViews = _.debounce(this.updateDebggingViews, 100);
224+
this.changedFiles = new Set();
224225
}
225226
/*MD ## Registration MD*/
226227
async registerFileForAEDebugging(url, context, triplesCallback) {
@@ -231,7 +232,7 @@ export class AEDebuggingCache {
231232
}
232233
return false;
233234
};
234-
this.registeredDebuggingViews.push(callback);
235+
this.registeredDebuggingViews.push({ callback, url });
235236

236237
triplesCallback((await this.getDependencyTriplesForFile(url)));
237238
}
@@ -305,24 +306,24 @@ export class AEDebuggingCache {
305306
} else if (type === 1) {
306307
if (recentDeletions > 0) {
307308
const matchingLines = Math.max(recentDeletions, data.length);
308-
for(let i = 0; i < matchingLines; i++) {
309+
for (let i = 0; i < matchingLines; i++) {
309310
mapping[originalLine - matchingLines + i] = [newLine, true];
310311
newLine++;
311312
}
312-
data = data.substring(matchingLines)
313-
}
314-
if(data.length > 0) {
313+
data = data.substring(matchingLines);
314+
}
315+
if (data.length > 0) {
315316
newLine += data.length;
316317
recentAdditions += data.length;
317318
}
318319
} else {
319320
if (recentAdditions > 0) {
320321
const matchingLines = Math.max(recentAdditions, data.length);
321-
for(let i = 0; i < matchingLines; i++) {
322+
for (let i = 0; i < matchingLines; i++) {
322323
mapping[originalLine] = [newLine - matchingLines + i, true];
323324
originalLine++;
324-
}
325-
data = data.substring(matchingLines)
325+
}
326+
data = data.substring(matchingLines);
326327
}
327328
recentDeletions += data.length;
328329
for (let i = 0; i < data.length; i++) {
@@ -337,13 +338,21 @@ export class AEDebuggingCache {
337338
return mapping;
338339
}
339340
/*MD ## Rewriting API MD*/
341+
updateFiles(files) {
342+
if(!files) return;
343+
files.forEach(file => this.changedFiles.add(file));
344+
this.debouncedUpdateDebuggingViews();
345+
}
346+
340347
async updateDebggingViews() {
341348
for (let i = 0; i < this.registeredDebuggingViews.length; i++) {
342-
if (!(await this.registeredDebuggingViews[i]())) {
349+
if (![...this.changedFiles].some(file => file.includes(this.registeredDebuggingViews[i].url))) continue;
350+
if (!(await this.registeredDebuggingViews[i].callback())) {
343351
this.registeredDebuggingViews.splice(i, 1);
344352
i--;
345353
}
346354
}
355+
this.changedFiles = new Set();
347356
}
348357

349358
async getDependencyTriplesForFile(url) {
@@ -369,6 +378,9 @@ export class AEDebuggingCache {
369378
return result;
370379
}
371380
}
381+
382+
async function relatedFiles(dependencies, aexprs) {}
383+
372384
export const DebuggingCache = new AEDebuggingCache();
373385

374386
const DependenciesToAExprs = {
@@ -377,23 +389,37 @@ const DependenciesToAExprs = {
377389

378390
associate(dep, aexpr) {
379391
const location = aexpr.meta().get("location");
380-
if(location && location.file) {
392+
if (location && location.file) {
393+
DebuggingCache.updateFiles([location.file]);
381394
this._AEsPerFile.getOrCreate(location.file, () => new Set()).add(aexpr);
382395
}
383396
this._depsToAExprs.associate(dep, aexpr);
384397
dep.updateTracking();
385-
DebuggingCache.debouncedUpdateDebuggingViews();
398+
399+
// Track affected files
400+
for (const hook of HooksToDependencies.getHooksForDep(dep)) {
401+
hook.getLocations().then(locations => DebuggingCache.updateFiles(locations.map(loc => loc.file)));
402+
}
386403
},
387404

388405
disconnectAllForAExpr(aexpr) {
389406
const location = aexpr.meta().get("location");
390-
if (location && location.file && this._AEsPerFile.has(location.file)) {
391-
this._AEsPerFile.get(location.file).delete(aexpr);
407+
if (location && location.file) {
408+
DebuggingCache.updateFiles([location.file]);
409+
if( this._AEsPerFile.has(location.file)) {
410+
this._AEsPerFile.get(location.file).delete(aexpr);
411+
}
392412
}
393413
const deps = this.getDepsForAExpr(aexpr);
394414
this._depsToAExprs.removeAllLeftFor(aexpr);
395415
deps.forEach(dep => dep.updateTracking());
396-
DebuggingCache.debouncedUpdateDebuggingViews();
416+
417+
// Track affected files
418+
for (const dep of DependenciesToAExprs.getDepsForAExpr(aexpr)) {
419+
for (const hook of HooksToDependencies.getHooksForDep(dep)) {
420+
hook.getLocations().then(locations => DebuggingCache.updateFiles(locations.map(loc => loc.file)));
421+
}
422+
}
397423
},
398424

399425
getAEsInFile(url) {
@@ -431,12 +457,26 @@ const HooksToDependencies = {
431457

432458
associate(hook, dep) {
433459
this._hooksToDeps.associate(hook, dep);
434-
DebuggingCache.debouncedUpdateDebuggingViews();
460+
461+
// Track affected files
462+
hook.getLocations().then(locations => DebuggingCache.updateFiles(locations.map(loc => loc.file)));
463+
for (const ae of DependenciesToAExprs.getAExprsForDep(dep)) {
464+
if(ae.meta().has("location")) {
465+
DebuggingCache.updateFiles([ae.meta().get("location").file]);
466+
}
467+
}
435468
},
436469

437470
remove(hook, dep) {
438471
this._hooksToDeps.remove(hook, dep);
439-
DebuggingCache.debouncedUpdateDebuggingViews();
472+
473+
// Track affected files
474+
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+
DebuggingCache.updateFiles([ae.meta().get("location").file]);
478+
}
479+
}
440480
},
441481

442482
async getHooksInFile(url) {
@@ -453,7 +493,16 @@ const HooksToDependencies = {
453493

454494
disconnectAllForDependency(dep) {
455495
this._hooksToDeps.removeAllLeftFor(dep);
456-
DebuggingCache.debouncedUpdateDebuggingViews();
496+
497+
// Track affected files
498+
for (const hook of HooksToDependencies.getHooksForDep(dep)) {
499+
hook.getLocations().then(locations => DebuggingCache.updateFiles(locations.map(loc => loc.file)));
500+
}
501+
for (const ae of DependenciesToAExprs.getAExprsForDep(dep)) {
502+
if(ae.meta().has("location")) {
503+
DebuggingCache.updateFiles([ae.meta().get("location").file]);
504+
}
505+
}
457506
},
458507

459508
getDepsForHook(hook) {
@@ -516,6 +565,7 @@ class Hook {
516565
}
517566

518567
addLocation(location) {
568+
if (!location) return;
519569
if (!this.locations.some(loc => _.isEqual(loc, location))) {
520570
this.locations.push(location);
521571
}
@@ -529,6 +579,15 @@ class Hook {
529579

530580
notifyDependencies() {
531581
HooksToDependencies.getDepsForHook(this).forEach(dep => dep.notifyAExprs());
582+
583+
this.getLocations().then(locations => DebuggingCache.updateFiles(locations.map(loc => loc.file)));
584+
for (const dep of HooksToDependencies.getDepsForHook(this)) {
585+
for (const ae of DependenciesToAExprs.getAExprsForDep(dep)) {
586+
if(ae.meta().has("location")) {
587+
DebuggingCache.updateFiles([ae.meta().get("location").file]);
588+
}
589+
}
590+
}
532591
}
533592
}
534593

@@ -877,23 +936,20 @@ class TracingHandler {
877936
if (!hook) return;
878937
hook.addLocation(location || TracingHandler.findRegistrationLocation());
879938
hook.notifyDependencies();
880-
DebuggingCache.debouncedUpdateDebuggingViews();
881939
}
882940

883941
static globalUpdated(globalName, location) {
884942
const hook = SourceCodeHook.get(globalRef, globalName);
885943
if (!hook) return;
886944
hook.addLocation(location || TracingHandler.findRegistrationLocation());
887945
hook.notifyDependencies();
888-
DebuggingCache.debouncedUpdateDebuggingViews();
889946
}
890947

891948
static localUpdated(scope, varName, location) {
892949
const hook = SourceCodeHook.get(scope, varName);
893950
if (!hook) return;
894951
hook.addLocation(location || TracingHandler.findRegistrationLocation());
895952
hook.notifyDependencies();
896-
DebuggingCache.debouncedUpdateDebuggingViews();
897953
}
898954

899955
static async findRegistrationLocation() {

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

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,13 @@ export default class EventDrops extends Morph {
121121
//Register to overview selection changes
122122
jQuery(this.aeOverview).on("changed.jstree", (e, data) => {
123123
this.eventsChanged();
124-
}
124+
});
125+
this.ready = false;
126+
jQuery(this.aeOverview).one("ready.jstree", (e, data) => {
127+
this.ready = true;
128+
});
125129
//Register to grouping change
126-
);this.groupByLine.addEventListener('change', () => {
130+
this.groupByLine.addEventListener('change', () => {
127131
if (this.groupByLine.checked) {
128132
this.groupingFunction = this.locationGrouping();
129133
} else {
@@ -259,12 +263,12 @@ export default class EventDrops extends Morph {
259263
return { ae, events: ae.meta().get('events').filter(event => event.type === "changed value").filter(this.filterFunction) };
260264
});
261265
this.valuesOverTime.innerHTML = "";
262-
263-
for(const {ae, events} of aeWithRelevantEvents) {
264-
if(events.length === 0) continue;
265-
let row = <tr><th>{ae.meta().get('id')}</th></tr>
266+
267+
for (const { ae, events } of aeWithRelevantEvents) {
268+
if (events.length === 0) continue;
269+
let row = <tr><th>{ae.meta().get('id')}</th></tr>;
266270
row.append(<td>{events[0].value.lastValue}</td>);
267-
for(const event of events) {
271+
for (const event of events) {
268272
row.append(<td>{event.value.value}</td>);
269273
}
270274
this.valuesOverTime.append(row);
@@ -273,7 +277,7 @@ export default class EventDrops extends Morph {
273277

274278
updateOverview(aexprs) {
275279
jQuery(this.aeOverview).jstree(true).settings.core.data = this.generateOverviewJSON(aexprs);
276-
jQuery(this.aeOverview).jstree(true).refresh();
280+
jQuery(this.aeOverview).jstree(true).refresh(true);
277281
}
278282

279283
generateOverviewJSON(aexprs) {
@@ -330,6 +334,29 @@ export default class EventDrops extends Morph {
330334
this.detached = true;
331335
}
332336

337+
filterToAEs(aes) {
338+
const tree = jQuery(this.aeOverview).jstree(true);
339+
tree.deselect_all();
340+
if(this.ready) {
341+
for(const ae of aes) {
342+
tree.select_node(ae.timelineID + 1);
343+
}
344+
} else {
345+
this.filteredAEs = aes;
346+
jQuery(this.aeOverview).on("refresh.jstree", (e, data) => {
347+
if(this.filteredAEs) {
348+
for(const ae of this.filteredAEs) {
349+
tree.select_node(ae.timelineID + 1);
350+
}
351+
if(tree.get_node([...this.filteredAEs][0])) {
352+
this.filteredAEs = [];
353+
}
354+
}
355+
});
356+
tree.refresh();
357+
}
358+
}
359+
333360
get diagram() {
334361
return this.get("#diagram");
335362
}

0 commit comments

Comments
 (0)