refactor(ngProbe): rename to ng.probe
BREAKING CHANGE: Closes #3786 - ngProbe => ng.probe
This commit is contained in:
parent
cebd670a8e
commit
4415855683
|
@ -20,7 +20,7 @@ Interfaces:
|
|||
|
||||
|
||||
Methods and functions:
|
||||
- Example: `bootstrap`, `ngProbe`
|
||||
- Example: `bootstrap`, `someMethod`
|
||||
- Should be camel case with first lower case
|
||||
|
||||
|
||||
|
|
|
@ -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 = '#';
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
@ -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); }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue