Skip to content

Commit 6a0cd71

Browse files
committed
Merge branch 'gh-pages' of https://github.com/LivelyKernel/lively4-core into gh-pages
2 parents 5f17feb + e0ca6fb commit 6a0cd71

File tree

3 files changed

+64
-19
lines changed

3 files changed

+64
-19
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,14 @@ const DependenciesToAExprs = {
220220
associate(dep, aexpr) {
221221
this._depsToAExprs.associate(dep, aexpr);
222222
dep.updateTracking();
223+
debouncedUpdateDebuggingViews();
223224
},
224225

225226
disconnectAllForAExpr(aexpr) {
226227
const deps = this.getDepsForAExpr(aexpr);
227228
this._depsToAExprs.removeAllLeftFor(aexpr);
228229
deps.forEach(dep => dep.updateTracking());
230+
debouncedUpdateDebuggingViews();
229231
},
230232

231233
getAETriplesForFile(url) {
@@ -271,9 +273,11 @@ const HooksToDependencies = {
271273

272274
associate(hook, dep) {
273275
this._hooksToDeps.associate(hook, dep);
276+
debouncedUpdateDebuggingViews();
274277
},
275278
remove(hook, dep) {
276279
this._hooksToDeps.remove(hook, dep);
280+
debouncedUpdateDebuggingViews();
277281
},
278282

279283
async getHookTriplesForFile(url) {
@@ -293,6 +297,7 @@ const HooksToDependencies = {
293297

294298
disconnectAllForDependency(dep) {
295299
this._hooksToDeps.removeAllLeftFor(dep);
300+
debouncedUpdateDebuggingViews();
296301
},
297302

298303
getDepsForHook(hook) {
@@ -715,20 +720,23 @@ class TracingHandler {
715720
if(!hook) return;
716721
hook.addLocation(location || TracingHandler.findRegistrationLocation());
717722
hook.notifyDependencies();
723+
debouncedUpdateDebuggingViews();
718724
}
719725

720726
static globalUpdated(globalName, location) {
721727
const hook = SourceCodeHook.get(globalRef, globalName);
722728
if(!hook) return;
723729
hook.addLocation(location || TracingHandler.findRegistrationLocation());
724730
hook.notifyDependencies();
731+
debouncedUpdateDebuggingViews();
725732
}
726733

727734
static localUpdated(scope, varName, location) {
728735
const hook = SourceCodeHook.get(scope, varName);
729736
if(!hook) return;
730737
hook.addLocation(location || TracingHandler.findRegistrationLocation());
731738
hook.notifyDependencies();
739+
debouncedUpdateDebuggingViews();
732740
}
733741

734742
static async findRegistrationLocation() {
@@ -896,6 +904,32 @@ export function getGlobal(globalName) {
896904
}
897905
}
898906

907+
const registeredDebuggingViews = [];
908+
909+
const debouncedUpdateDebuggingViews = _.debounce(updateDebggingViews, 100);
910+
911+
async function updateDebggingViews() {
912+
for(let i = 0; i < registeredDebuggingViews.length; i++) {
913+
if(!await registeredDebuggingViews[i]()) {
914+
registeredDebuggingViews.splice(i, 1);
915+
i--;
916+
}
917+
}
918+
}
919+
920+
export async function registerFileForAEDebugging(url, context, triplesCallback) {
921+
const callback = async () => {
922+
if(context && (!context.valid || context.valid())) {
923+
triplesCallback(await getDependencyTriplesForFile(url));
924+
return true;
925+
}
926+
return false;
927+
}
928+
registeredDebuggingViews.push(callback);
929+
930+
triplesCallback(await getDependencyTriplesForFile(url));
931+
}
932+
899933
export async function getDependencyTriplesForFile(url) {
900934
const result = [];
901935
for (const hook of HooksToDependencies._hooksToDeps.getAllLeft()) {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,13 @@
147147
*/
148148

149149
.activeExpressionGutter {
150-
width: 10px;
150+
width: 12px;
151151

152152
transition: all 0.5s ease-in-out;
153153
transition-property: opacity;
154154

155155
opacity: 0;
156-
background-color: orange;/*lightgray;*/
156+
background-color: lightgray;
157157
border-left: solid 0.3px gray;
158158
border-right: solid 0.3px gray;
159159
}
@@ -169,9 +169,9 @@
169169
transition: all 0.3s ease-in-out;
170170
transition-property: background-color, color;
171171

172-
background-color: rgba(0,255,165,0.5);
173-
color: rgba(0,0,0,0.5);
174-
text-align: center;
172+
/* background-color: rgba(255,165,0,0.5);*/
173+
color: rgba(0,0,255,1);
174+
/*text-align: center;*/
175175
vertical-align: middle;
176176
line-height: normal;
177177
display: flex;
@@ -187,9 +187,9 @@
187187
transition: all 0.3s ease-in-out;
188188
transition-property: background-color, color;
189189

190-
background-color: rgba(255,165,0,0.5);
191-
color: rgba(0,0,0,0.5);
192-
text-align: center;
190+
/* background-color: rgba(255,165,0,0.5);*/
191+
color: rgba(255,0,0,1);
192+
/*text-align: center;*/
193193
vertical-align: middle;
194194
line-height: normal;
195195
display: flex;

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let loadPromise = undefined;
3030
import { loc, range } from 'utils';
3131
import indentationWidth from 'src/components/widgets/indent.js';
3232
import { DependencyGraph } from 'src/client/dependency-graph/graph.js';
33-
import { getDependencyTriplesForFile } from 'src/client/reactive/active-expression-rewriting/active-expression-rewriting.js';
33+
import { getDependencyTriplesForFile, registerFileForAEDebugging } from 'src/client/reactive/active-expression-rewriting/active-expression-rewriting.js';
3434
import { AExprRegistry } from 'src/client/reactive/active-expression/active-expression.js';
3535
import ContextMenu from 'src/client/contextmenu.js';
3636

@@ -223,6 +223,7 @@ export default class LivelyCodeMirror extends HTMLElement {
223223

224224
await lively.sleep(0);
225225
this.editor.refresh();
226+
this.updateAExprDependencies();
226227
}
227228

228229
async editorLoaded() {
@@ -1411,10 +1412,15 @@ export default class LivelyCodeMirror extends HTMLElement {
14111412
}
14121413
// this.showAExprTextMarkers();
14131414
await this.showAExprDependencyGutter();
1414-
const [depToAE, AEToDep] = await this.allDependenciesByLine();
1415-
this.editor.doc.clearGutter('activeExpressionGutter')
1416-
this.showAExprDependencyGutterMarkers(depToAE, false);
1417-
this.showAExprDependencyGutterMarkers(AEToDep, true);
1415+
1416+
1417+
registerFileForAEDebugging(this.fileURL(), this, (triplets) => {
1418+
this.allDependenciesByLine(triplets).then(([depToAE, AEToDep]) => {
1419+
this.editor.doc.clearGutter('activeExpressionGutter');
1420+
this.showAExprDependencyGutterMarkers(depToAE, false);
1421+
this.showAExprDependencyGutterMarkers(AEToDep, true);
1422+
});
1423+
});
14181424
}
14191425

14201426
async showAExprTextMarkers() {
@@ -1490,7 +1496,7 @@ export default class LivelyCodeMirror extends HTMLElement {
14901496
}
14911497
}
14921498

1493-
async allDependenciesByLine() {
1499+
async allDependenciesByLine(depsMapInFile) {
14941500
const depToAE = new Map();
14951501
const AEToDep = new Map();
14961502

@@ -1527,19 +1533,19 @@ export default class LivelyCodeMirror extends HTMLElement {
15271533
if (!depToAE.get(dependencyLine)) {
15281534
depToAE.set(dependencyLine, []);
15291535
}
1530-
depToAE.get(dependencyLine).push({ location: AELocation, source: ae.meta().get("sourceCode"), events: relatedEvents.length });
1536+
// Group by AE to distinguish between mutltiple AE Objects in the same line?
1537+
depToAE.get(dependencyLine).push({ location: AELocation, source: ae.meta().get("sourceCode"), events: relatedEvents.length, aes: new Set([ae]) });
15311538
}
15321539

15331540
if (AELocation.file.includes(this.fileURL())) {
15341541
// AE is in this file
15351542
if (!AEToDep.get(AELine)) {
15361543
AEToDep.set(AELine, []);
15371544
}
1538-
AEToDep.get(AELine).push({ location: dependencyLoc, source: dependencySource, events: relatedEvents.length });
1545+
AEToDep.get(AELine).push({ location: dependencyLoc, source: dependencySource, events: relatedEvents.length, aes: new Set([ae]) });
15391546
}
15401547
};
15411548

1542-
const depsMapInFile = await getDependencyTriplesForFile(this.fileURL());
15431549
for (const { hook, dependency, ae } of depsMapInFile) {
15441550
const dependencyInfo = dependency.contextIdentifierValue();
15451551
const locations = await hook.getLocations();
@@ -1584,6 +1590,10 @@ export default class LivelyCodeMirror extends HTMLElement {
15841590
fileURL() {
15851591
return lively.query(this, "lively-container").getURL().pathname;
15861592
}
1593+
1594+
valid() {
1595+
return !!lively.query(this, "lively-container");
1596+
}
15871597

15881598
drawAExprGutter(line, dependencies, isAE) {
15891599
this.editor.doc.setGutterMarker(line, 'activeExpressionGutter', this.drawAExprGutterMarker(dependencies, isAE));
@@ -1627,6 +1637,7 @@ export default class LivelyCodeMirror extends HTMLElement {
16271637
if(dep.location.end.column > lastDep.location.end.column) {
16281638
lastDep.location.end = dep.location.end;
16291639
}
1640+
lastDep.aes = new Set([...lastDep.aes, ...dep.aes]);
16301641
}
16311642
});
16321643

@@ -1636,7 +1647,7 @@ export default class LivelyCodeMirror extends HTMLElement {
16361647
};
16371648

16381649
return <div class={"activeExpressionGutter-marker" + (isAE ? "-ae" : "-dep")} click={callback}>
1639-
{accumulated.length}
1650+
{isAE ? <b>AE</b> : <i class="fa fa-share-alt"></i>}
16401651
</div>;
16411652
}
16421653

@@ -1664,7 +1675,7 @@ export default class LivelyCodeMirror extends HTMLElement {
16641675
lively.openBrowser(path, true, {start, end}, false, undefined, true);
16651676
}
16661677
menu.remove();
1667-
}, dep.events + " event" + (dep.events === 1 ? "" : "s"), this.faIcon(inThisFile ? 'location-arrow' : 'file-code-o')]);
1678+
}, dep.events + " event" + (dep.events === 1 ? "" : "s") + ", " + dep.aes.size + " instance" + (dep.aes.size === 1 ? "" : "s"), this.faIcon(inThisFile ? 'location-arrow' : 'file-code-o')]);
16681679
});
16691680

16701681
const menu = await ContextMenu.openIn(document.body, { clientX: markerBounds.left, clientY: markerBounds.bottom }, undefined, document.body, menuItems);

0 commit comments

Comments
 (0)