Skip to content

Commit 4415855

Browse files
committed
refactor(ngProbe): rename to ng.probe
BREAKING CHANGE: Closes angular#3786 - ngProbe => ng.probe
1 parent cebd670 commit 4415855

File tree

7 files changed

+39
-9
lines changed

7 files changed

+39
-9
lines changed

NAMING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Interfaces:
2020

2121

2222
Methods and functions:
23-
- Example: `bootstrap`, `ngProbe`
23+
- Example: `bootstrap`, `someMethod`
2424
- Should be camel case with first lower case
2525

2626

modules/angular2/src/core/debug/debug_element_view_listener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {Renderer} from 'angular2/src/core/render/api';
88
import {DebugElement} from './debug_element';
99

1010
const NG_ID_PROPERTY = 'ngid';
11-
const INSPECT_GLOBAL_NAME = 'ngProbe';
11+
const INSPECT_GLOBAL_NAME = 'ng.probe';
1212

1313
var NG_ID_SEPARATOR = '#';
1414

modules/angular2/src/core/dom/browser_adapter.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,18 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
452452
}
453453

454454
// TODO(tbosch): move this into a separate environment class once we have it
455-
setGlobalVar(String name, value) {
456-
js.context[name] = value;
455+
setGlobalVar(String path, value) {
456+
var parts = path.split('.');
457+
var obj = js.context;
458+
while(parts.length > 1) {
459+
var name = parts.removeAt(0);
460+
if (obj.hasProperty(name)) {
461+
obj = obj[name];
462+
} else {
463+
obj = obj[name] = new js.JsObject(js.context['Object']);
464+
}
465+
}
466+
obj[parts.removeAt(0)] = value;
457467
}
458468
}
459469

modules/angular2/src/core/dom/browser_adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {List, MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
2-
import {isBlank, isPresent, global} from 'angular2/src/core/facade/lang';
2+
import {isBlank, isPresent, global, setValueOnPath} from 'angular2/src/core/facade/lang';
33
import {setRootDomAdapter} from './dom_adapter';
44
import {GenericBrowserDomAdapter} from './generic_browser_adapter';
55

@@ -320,7 +320,7 @@ export class BrowserDomAdapter extends GenericBrowserDomAdapter {
320320
}
321321
getData(element, name: string): string { return this.getAttribute(element, 'data-' + name); }
322322
// TODO(tbosch): move this into a separate environment class once we have it
323-
setGlobalVar(name: string, value: any) { global[name] = value; }
323+
setGlobalVar(path: string, value: any) { setValueOnPath(global, path, value); }
324324
}
325325

326326

modules/angular2/src/core/dom/parse5_adapter.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ var url = require('url');
99

1010
import {List, MapWrapper, ListWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
1111
import {DomAdapter, setRootDomAdapter} from './dom_adapter';
12-
import {BaseException, isPresent, isBlank, global} from 'angular2/src/core/facade/lang';
12+
import {
13+
BaseException,
14+
isPresent,
15+
isBlank,
16+
global,
17+
setValueOnPath
18+
} from 'angular2/src/core/facade/lang';
1319
import {SelectorMatcher, CssSelector} from 'angular2/src/core/render/dom/compiler/selector';
1420

1521
var _attrToPropMap = {
@@ -540,7 +546,7 @@ export class Parse5DomAdapter extends DomAdapter {
540546
getData(el, name: string): string { return this.getAttribute(el, 'data-' + name); }
541547
setData(el, name: string, value: string) { this.setAttribute(el, 'data-' + name, value); }
542548
// TODO(tbosch): move this into a separate environment class once we have it
543-
setGlobalVar(name: string, value: any) { global[name] = value; }
549+
setGlobalVar(path: string, value: any) { setValueOnPath(global, path, value); }
544550
}
545551

546552
// TODO: build a proper list, this one is all the keys of a HTMLInputElement

modules/angular2/src/core/facade/lang.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,3 +354,17 @@ export class DateWrapper {
354354
static now(): Date { return new Date(); }
355355
static toJson(date: Date): string { return date.toJSON(); }
356356
}
357+
358+
export function setValueOnPath(global: any, path: string, value: any) {
359+
var parts = path.split('.');
360+
var obj: any = global;
361+
while (parts.length > 1) {
362+
var name = parts.shift();
363+
if (obj.hasOwnProperty(name)) {
364+
obj = obj[name];
365+
} else {
366+
obj = obj[name] = {};
367+
}
368+
}
369+
obj[parts.shift()] = value;
370+
}

modules/angular2/test/core/debug/debug_element_view_listener_spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function main() {
6868
tcb.overrideTemplate(MyComp, '')
6969
.createAsync(MyComp)
7070
.then((rootTestComponent) => {
71-
expect(global['ngProbe'](rootTestComponent.nativeElement).componentInstance)
71+
expect(global['ng']['probe'](rootTestComponent.nativeElement).componentInstance)
7272
.toBeAnInstanceOf(MyComp);
7373

7474
async.done();

0 commit comments

Comments
 (0)