diff --git a/NAMING.md b/NAMING.md index 20087b7e41..69e16b406b 100644 --- a/NAMING.md +++ b/NAMING.md @@ -20,7 +20,7 @@ Interfaces: Methods and functions: - - Example: `bootstrap`, `ngProbe` + - Example: `bootstrap`, `someMethod` - Should be camel case with first lower case diff --git a/modules/angular2/src/core/debug/debug_element_view_listener.ts b/modules/angular2/src/core/debug/debug_element_view_listener.ts index 56a54c3934..1f3e63078a 100644 --- a/modules/angular2/src/core/debug/debug_element_view_listener.ts +++ b/modules/angular2/src/core/debug/debug_element_view_listener.ts @@ -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 = '#'; diff --git a/modules/angular2/src/core/dom/browser_adapter.dart b/modules/angular2/src/core/dom/browser_adapter.dart index 8e7641a29e..d3518a40dc 100644 --- a/modules/angular2/src/core/dom/browser_adapter.dart +++ b/modules/angular2/src/core/dom/browser_adapter.dart @@ -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; } } diff --git a/modules/angular2/src/core/dom/browser_adapter.ts b/modules/angular2/src/core/dom/browser_adapter.ts index 20b0129e00..9187c405eb 100644 --- a/modules/angular2/src/core/dom/browser_adapter.ts +++ b/modules/angular2/src/core/dom/browser_adapter.ts @@ -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); } } diff --git a/modules/angular2/src/core/dom/parse5_adapter.ts b/modules/angular2/src/core/dom/parse5_adapter.ts index db4ef73f1c..375fc52934 100644 --- a/modules/angular2/src/core/dom/parse5_adapter.ts +++ b/modules/angular2/src/core/dom/parse5_adapter.ts @@ -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 diff --git a/modules/angular2/src/core/facade/lang.ts b/modules/angular2/src/core/facade/lang.ts index e85c6dd79c..31c1cf3c6f 100644 --- a/modules/angular2/src/core/facade/lang.ts +++ b/modules/angular2/src/core/facade/lang.ts @@ -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; +} diff --git a/modules/angular2/test/core/debug/debug_element_view_listener_spec.ts b/modules/angular2/test/core/debug/debug_element_view_listener_spec.ts index 2e61335c45..6260ee5889 100644 --- a/modules/angular2/test/core/debug/debug_element_view_listener_spec.ts +++ b/modules/angular2/test/core/debug/debug_element_view_listener_spec.ts @@ -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();