Skip to content

Commit

Permalink
refactor(ngProbe): rename to ng.probe
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

Closes angular#3786

- ngProbe => ng.probe
  • Loading branch information
mhevery committed Aug 31, 2015
1 parent cebd670 commit 4415855
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion NAMING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Interfaces:


Methods and functions:
- Example: `bootstrap`, `ngProbe`
- Example: `bootstrap`, `someMethod`
- Should be camel case with first lower case


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {Renderer} from 'angular2/src/core/render/api';
import {DebugElement} from './debug_element';

const NG_ID_PROPERTY = 'ngid';
const INSPECT_GLOBAL_NAME = 'ngProbe';
const INSPECT_GLOBAL_NAME = 'ng.probe';

var NG_ID_SEPARATOR = '#';

Expand Down
14 changes: 12 additions & 2 deletions modules/angular2/src/core/dom/browser_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,18 @@ class BrowserDomAdapter extends GenericBrowserDomAdapter {
}

// TODO(tbosch): move this into a separate environment class once we have it
setGlobalVar(String name, value) {
js.context[name] = value;
setGlobalVar(String path, value) {
var parts = path.split('.');
var obj = js.context;
while(parts.length > 1) {
var name = parts.removeAt(0);
if (obj.hasProperty(name)) {
obj = obj[name];
} else {
obj = obj[name] = new js.JsObject(js.context['Object']);
}
}
obj[parts.removeAt(0)] = value;
}
}

Expand Down
4 changes: 2 additions & 2 deletions modules/angular2/src/core/dom/browser_adapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {List, MapWrapper, ListWrapper} from 'angular2/src/core/facade/collection';
import {isBlank, isPresent, global} from 'angular2/src/core/facade/lang';
import {isBlank, isPresent, global, setValueOnPath} from 'angular2/src/core/facade/lang';
import {setRootDomAdapter} from './dom_adapter';
import {GenericBrowserDomAdapter} from './generic_browser_adapter';

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


Expand Down
10 changes: 8 additions & 2 deletions modules/angular2/src/core/dom/parse5_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ var url = require('url');

import {List, MapWrapper, ListWrapper, StringMapWrapper} from 'angular2/src/core/facade/collection';
import {DomAdapter, setRootDomAdapter} from './dom_adapter';
import {BaseException, isPresent, isBlank, global} from 'angular2/src/core/facade/lang';
import {
BaseException,
isPresent,
isBlank,
global,
setValueOnPath
} from 'angular2/src/core/facade/lang';
import {SelectorMatcher, CssSelector} from 'angular2/src/core/render/dom/compiler/selector';

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

// TODO: build a proper list, this one is all the keys of a HTMLInputElement
Expand Down
14 changes: 14 additions & 0 deletions modules/angular2/src/core/facade/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,3 +354,17 @@ export class DateWrapper {
static now(): Date { return new Date(); }
static toJson(date: Date): string { return date.toJSON(); }
}

export function setValueOnPath(global: any, path: string, value: any) {
var parts = path.split('.');
var obj: any = global;
while (parts.length > 1) {
var name = parts.shift();
if (obj.hasOwnProperty(name)) {
obj = obj[name];
} else {
obj = obj[name] = {};
}
}
obj[parts.shift()] = value;
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function main() {
tcb.overrideTemplate(MyComp, '')
.createAsync(MyComp)
.then((rootTestComponent) => {
expect(global['ngProbe'](rootTestComponent.nativeElement).componentInstance)
expect(global['ng']['probe'](rootTestComponent.nativeElement).componentInstance)
.toBeAnInstanceOf(MyComp);

async.done();
Expand Down

0 comments on commit 4415855

Please sign in to comment.