Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
santiago-elustondo committed Jun 4, 2018
1 parent d41bd4a commit 8a79dd0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/backend/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ const featureModulesPipe = new MessagePipeBackend({
messageQueue: messageBuffer,
sendMessage: send,
createQueueAlertMessage: () => MessageFactory.push()
})
});

const onUpdateNotifier = new Subject<void>()
const onUpdateNotifier = new Subject<void>();

highlighter.useComponentTreeInstance(previousTree);
highlighter.useDocumentInstance(document);
Expand Down Expand Up @@ -234,7 +234,7 @@ const bind = (root) => {
Promise.all([
updateComponentTree(getAllAngularRootElements().map(r => ng.probe(r))),
updateRouterTree()
]).then(() => onUpdateNotifier.next())
]).then(() => onUpdateNotifier.next());
}));

// initial load
Expand Down
53 changes: 42 additions & 11 deletions src/feature-modules/highlighter/backend/Highlighter.class.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Observable } from 'rxjs'
import { Observable } from 'rxjs';

// project deps
import { MessagePipeBackend, MessageType, Message } from 'feature-modules/.lib';
Expand Down Expand Up @@ -36,6 +36,7 @@ export class Highlighter {
overlay: {
element: HTMLElement;
};
watcher: any;
target: {
domElement: HTMLElement;
auguryNode: Node;
Expand All @@ -61,16 +62,15 @@ export class Highlighter {
public useOnUpdateNotifier(notifier: Observable<void>) {
this._onUpdateNotifier = notifier;
this._onUpdateNotifier.subscribe(() => {
if (!this._currentHighlight) { return; }
if (!this._dom.contains(this._currentHighlight.target.domElement)) { this.clear(); }
if (!this.targetIsStillThere()) { return; }
this.highlightAuguryNode(this._currentHighlight.target.auguryNode);
});
}

/**
*/
public useMessagePipe(pipe: MessagePipeBackend) {
this._pipe = pipe
this._pipe = pipe;
this._pipe.addHandler((message: Message<any>) => {
switch (message.messageType) {

Expand All @@ -89,7 +89,7 @@ export class Highlighter {
break;

}
})
});
}

// --- Public Methods ---
Expand All @@ -111,11 +111,11 @@ export class Highlighter {
*/
private highlightAuguryNode(node: Node) {
this.clear();
console.log(node.nativeElement())
this._currentHighlight = {
overlay: {
element: this.paintOverlay(this.getAuguryNodeOffsets(node), node.name)
},
watcher: setTimeout(() => this.repaintOverlay(), 500),
target: {
auguryNode: node,
domElement: node.nativeElement()
Expand All @@ -130,22 +130,32 @@ export class Highlighter {
const overlay = this._currentHighlight.overlay.element;
try { overlay.remove(); }
catch (e) { console.error('error removing highlight', overlay, e); }
clearInterval(this._currentHighlight.watcher);
this._currentHighlight = null;
}

/**
*/
private startFinding() {

const detainEvent = (e: Event) => {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
}

this.stopFinding();
this._onHoverListener = (event) => {
this._onHoverListener = (event: Event) => {
this.highlightNodeFromElement(event.target);
detainEvent(event);
};
this._onSelectListener = (event) => {
console.log('found thing');
this._onSelectListener = (event: Event) => {
this.selectNodeFromElement(event.target);
this.clear();
this.stopFinding();
setTimeout(() => this.stopFinding(), 0);
detainEvent(event);
};

window.addEventListener(
'mouseover',
this._onHoverListener,
Expand All @@ -156,6 +166,7 @@ export class Highlighter {
this._onSelectListener,
false
);

}

/**
Expand Down Expand Up @@ -188,7 +199,9 @@ export class Highlighter {
private highlightNodeFromElement(element) {
this.clear();
const ngNode = this.findNearestAuguryParent(element);
if (ngNode) { this.highlightAuguryNode(ngNode); }
if (ngNode) {
this.highlightAuguryNode(ngNode);
}
}

/**
Expand All @@ -211,12 +224,30 @@ export class Highlighter {

}

/**
*/
private targetIsStillThere() {
if (!this._currentHighlight) { return false; }
if (!this._dom.contains(this._currentHighlight.target.domElement)) {
this.clear();
return false;
}
return true;
}

/**
*/
private getAuguryNodeOffsets(node: Node): Offsets {
return addUpElementAndChildrenOffsets(node.nativeElement());
}

/**
*/
private repaintOverlay() {
if (!this.targetIsStillThere()) { return; }
this.highlightAuguryNode(this._currentHighlight.target.auguryNode);
}

/**
*/
private paintOverlay(offsets: Offsets, label?: string): HTMLElement {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/function-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export const functionName = (fn: Function): string => {
}
}

name = name.replace(/[^\w]/gi, '');

if (typeof name !== 'string' || name === '') {
name = 'anonymous';
}

name = name.replace(/[^\w]/gi, '');

if (!isNaN(parseInt(name[0], 10))) {
name = '__num_' + name[0];
}
Expand Down

0 comments on commit 8a79dd0

Please sign in to comment.