From 8afa421d75c95562060e35dbe8f576bd1e81c294 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Fri, 19 Sep 2014 16:38:37 -0700 Subject: [PATCH] first chunk of interfaces that are valid via dart analyzer --- gulpfile.js | 16 +++-- modules/change_detection/pubspec.yaml | 6 ++ .../change_detection/src/change_detection.js | 5 ++ modules/change_detection/src/proto_record.js | 3 + .../change_detection/src/proto_watch_group.js | 27 ++++++++ modules/change_detection/src/record.js | 3 + modules/change_detection/src/watch_group.js | 4 ++ .../src/watch_group_dispatcher.js | 4 ++ modules/core/pubspec.yaml | 12 ++++ modules/core/src/angular.js | 12 ++++ modules/core/src/annotations/component.js | 65 +++++++++++++++++++ modules/core/src/annotations/directive.js | 19 ++++++ modules/core/src/annotations/facade.dart | 5 ++ modules/core/src/annotations/facade.es6 | 2 + .../core/src/annotations/template_config.js | 16 +++++ .../compiler/{compiler.es6d => compiler.js} | 16 ++++- modules/core/src/compiler/template_loader.js | 11 ++++ modules/core/src/life_cycle/life_cycle.js | 11 ++++ .../core/src/view/element_injector_target.js | 13 ++++ modules/core/src/view/element_module.js | 1 + modules/core/src/view/on_change_dispatcher.js | 19 ++++++ .../core/src/view/proto_element_injector.js | 27 ++++++++ modules/core/src/view/proto_view.js | 10 +++ modules/core/src/view/view.js | 34 ++++++++++ modules/core/test/compiler/compiler_spec.js | 9 +++ modules/di/pubspec.yaml | 6 ++ modules/di/src/di.js | 1 + modules/di/src/module.js | 24 +++++++ modules/examples/pubspec.yaml | 6 ++ .../examples/src/todo/{app.es6d => app.js} | 1 + modules/facade/bootstrap.es5 | 12 ++++ modules/facade/pubspec.yaml | 6 ++ modules/facade/src/collection.dart | 20 ++++++ modules/facade/src/collection.es6 | 15 +++++ .../src/todo => facade/src}/dom.dart | 4 +- .../{examples/src/todo => facade/src}/dom.es6 | 5 ++ modules/facade/src/lang.dart | 4 ++ modules/facade/src/lang.es6 | 2 + modules/facade/test.dart | 13 ++++ tools/js2dart | 2 +- 40 files changed, 462 insertions(+), 9 deletions(-) create mode 100644 modules/change_detection/pubspec.yaml create mode 100644 modules/change_detection/src/change_detection.js create mode 100644 modules/change_detection/src/proto_record.js create mode 100644 modules/change_detection/src/proto_watch_group.js create mode 100644 modules/change_detection/src/record.js create mode 100644 modules/change_detection/src/watch_group.js create mode 100644 modules/change_detection/src/watch_group_dispatcher.js create mode 100644 modules/core/pubspec.yaml create mode 100644 modules/core/src/angular.js create mode 100644 modules/core/src/annotations/component.js create mode 100644 modules/core/src/annotations/directive.js create mode 100644 modules/core/src/annotations/facade.dart create mode 100644 modules/core/src/annotations/facade.es6 create mode 100644 modules/core/src/annotations/template_config.js rename modules/core/src/compiler/{compiler.es6d => compiler.js} (50%) create mode 100644 modules/core/src/compiler/template_loader.js create mode 100644 modules/core/src/life_cycle/life_cycle.js create mode 100644 modules/core/src/view/element_injector_target.js create mode 100644 modules/core/src/view/element_module.js create mode 100644 modules/core/src/view/on_change_dispatcher.js create mode 100644 modules/core/src/view/proto_element_injector.js create mode 100644 modules/core/src/view/proto_view.js create mode 100644 modules/core/src/view/view.js create mode 100644 modules/core/test/compiler/compiler_spec.js create mode 100644 modules/di/pubspec.yaml create mode 100644 modules/di/src/di.js create mode 100644 modules/di/src/module.js create mode 100644 modules/examples/pubspec.yaml rename modules/examples/src/todo/{app.es6d => app.js} (94%) create mode 100644 modules/facade/bootstrap.es5 create mode 100644 modules/facade/pubspec.yaml create mode 100644 modules/facade/src/collection.dart create mode 100644 modules/facade/src/collection.es6 rename modules/{examples/src/todo => facade/src}/dom.dart (74%) rename modules/{examples/src/todo => facade/src}/dom.es6 (62%) create mode 100644 modules/facade/src/lang.dart create mode 100644 modules/facade/src/lang.es6 create mode 100644 modules/facade/test.dart diff --git a/gulpfile.js b/gulpfile.js index 597ab31cae..24ec0c6dff 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -58,9 +58,10 @@ var sourceTypeConfigs = { compiler: function() { return traceur(js2dartOptions, true); }, - transpileSrc: ['modules/**/*.es6d'], + transpileSrc: ['modules/**/*.js'], htmlSrc: ['modules/*/src/**/*.html'], - copySrc: ['modules/**/*.dart'], + // TODO: execute pub get after a yaml changed and was copied over to 'build' folder + copySrc: ['modules/**/*.dart', 'modules/**/*.yaml'], outputDir: 'build/dart', outputExt: 'dart', mimeType: 'application/dart' @@ -69,9 +70,9 @@ var sourceTypeConfigs = { compiler: function() { return traceur(js2es5Options, true); }, - transpileSrc: ['modules/**/*.es*'], + transpileSrc: ['modules/**/*.js', 'modules/**/*.es6'], htmlSrc: ['modules/*/src/**/*.html'], - copySrc: ['modules/**/*.js'], + copySrc: ['modules/**/*.es5'], outputDir: 'build/js', outputExt: 'js' } @@ -82,18 +83,25 @@ gulp.task('modules/clean', function() { .pipe(clean()); }); +function renameSrcToLib(file) { + file.dirname = file.dirname.replace(/\bsrc\b/, 'lib'); +} + function createModuleTask(sourceTypeConfig, isWatch) { var start = isWatch ? watch : gulp.src.bind(gulp); return function(done) { var transpile = start(sourceTypeConfig.transpileSrc) .pipe(rename({extname: '.'+sourceTypeConfig.outputExt})) + .pipe(rename(renameSrcToLib)) .pipe(sourceTypeConfig.compiler()) .pipe(gulp.dest(sourceTypeConfig.outputDir)); var copy = start(sourceTypeConfig.copySrc) + .pipe(rename(renameSrcToLib)) .pipe(gulp.dest(sourceTypeConfig.outputDir)); // TODO: provide the list of files to the template // automatically! var html = start(sourceTypeConfig.htmlSrc) + .pipe(rename(renameSrcToLib)) .pipe(ejs({ type: sourceTypeConfig.outputExt })) diff --git a/modules/change_detection/pubspec.yaml b/modules/change_detection/pubspec.yaml new file mode 100644 index 0000000000..cbcecb376a --- /dev/null +++ b/modules/change_detection/pubspec.yaml @@ -0,0 +1,6 @@ +name: change_detection +environment: + sdk: '>=1.4.0' +dependencies: +dev_dependencies: + unittest: '>=0.10.1 <0.12.0' diff --git a/modules/change_detection/src/change_detection.js b/modules/change_detection/src/change_detection.js new file mode 100644 index 0000000000..3c578a523e --- /dev/null +++ b/modules/change_detection/src/change_detection.js @@ -0,0 +1,5 @@ +export class ChangeDetection { + + detectChanges():int {} + +} \ No newline at end of file diff --git a/modules/change_detection/src/proto_record.js b/modules/change_detection/src/proto_record.js new file mode 100644 index 0000000000..b7a05672fa --- /dev/null +++ b/modules/change_detection/src/proto_record.js @@ -0,0 +1,3 @@ +export class ProtoRecord { + +} \ No newline at end of file diff --git a/modules/change_detection/src/proto_watch_group.js b/modules/change_detection/src/proto_watch_group.js new file mode 100644 index 0000000000..3c83902ab2 --- /dev/null +++ b/modules/change_detection/src/proto_watch_group.js @@ -0,0 +1,27 @@ +export class ProtoWatchGroup { + watch( + expression:String, + context:dynamic, + {isCollection}) + { + + } +} + +/* +@Component( + bind: { + 'title': 'title', + 'name': 'name' + } +) +class MyComponent implements ChangeListener { + String name; + String title; + + onChange(List changes) { + + } +} + +*/ \ No newline at end of file diff --git a/modules/change_detection/src/record.js b/modules/change_detection/src/record.js new file mode 100644 index 0000000000..75bad1116d --- /dev/null +++ b/modules/change_detection/src/record.js @@ -0,0 +1,3 @@ +export class Record { + +} \ No newline at end of file diff --git a/modules/change_detection/src/watch_group.js b/modules/change_detection/src/watch_group.js new file mode 100644 index 0000000000..53b89fa1bd --- /dev/null +++ b/modules/change_detection/src/watch_group.js @@ -0,0 +1,4 @@ +export class WatchGroup { + @FIELD('final dispatcher:WatchGroupDispatcher') + constructor() {} +} \ No newline at end of file diff --git a/modules/change_detection/src/watch_group_dispatcher.js b/modules/change_detection/src/watch_group_dispatcher.js new file mode 100644 index 0000000000..58fae35b74 --- /dev/null +++ b/modules/change_detection/src/watch_group_dispatcher.js @@ -0,0 +1,4 @@ + +export class WatchGroupDispatcher { + notify(record:Record, context) {} +} \ No newline at end of file diff --git a/modules/core/pubspec.yaml b/modules/core/pubspec.yaml new file mode 100644 index 0000000000..56df496cee --- /dev/null +++ b/modules/core/pubspec.yaml @@ -0,0 +1,12 @@ +name: core +environment: + sdk: '>=1.4.0' +dependencies: + change_detection: + path: ../change_detection + di: + path: ../di + facade: + path: ../facade +dev_dependencies: + unittest: '>=0.10.1 <0.12.0' diff --git a/modules/core/src/angular.js b/modules/core/src/angular.js new file mode 100644 index 0000000000..ad390e3cd9 --- /dev/null +++ b/modules/core/src/angular.js @@ -0,0 +1,12 @@ +/** + * Define public API for Angular here + */ +export * from './annotations/directive'; +export * from './annotations/component'; +export * from './annotations/template_config'; + +export * from './compiler/compiler'; +export * from './compiler/template_loader'; + +export * from './view/proto_view'; +export * from './view/view'; diff --git a/modules/core/src/annotations/component.js b/modules/core/src/annotations/component.js new file mode 100644 index 0000000000..cc854eec4a --- /dev/null +++ b/modules/core/src/annotations/component.js @@ -0,0 +1,65 @@ +import {Directive} from './directive'; + +export class Component extends Directive { + @CONST constructor({ + selector, + template, + elementServices, + componentServices, + implementsTypes + }:{ + selector:String, + template:TemplateConfig, + lightDomServices:DomServicesFunction, + shadowDomServices:DomServicesFunction, + componentServices:ComponentServicesFunction, + implementsTypes:Array + }) + { + // super({selector, lightDomServices, implementsTypes}); + } +} + +/////////////////////////// +/* +import 'package:angular/core.dart' as core; + + +@Component( + selector: 'example', + template: const TemplateConfig( + url: 'example.dart', + uses: const [core.CONFIG], + directives: const [CompA], + formatters: const [Stringify] + ), + componentServices: Example.componentServices, + elementServices: Example.elementServices, + implementsTypes: const [App] +) +class Example implements App { + static componentServices(Module m) { + m.bind(); + } + static elementServices(ElementModule m) { + m.bind(); + } +} + +class CompA {} + +@Formatter() +class Stringify {} + + + LightDOM: + + +CompA ShadowDOM: +
+ +
+ +CompB SHadowDOM: +
+*/ \ No newline at end of file diff --git a/modules/core/src/annotations/directive.js b/modules/core/src/annotations/directive.js new file mode 100644 index 0000000000..f36be850b5 --- /dev/null +++ b/modules/core/src/annotations/directive.js @@ -0,0 +1,19 @@ +import {Type} from 'facade/lang'; +import {ElementServicesFunction} from './facade'; + +@ABSTRACT +export class Directive { + @CONST constructor({ + selector, + lightDomServices, + implementsTypes + }:{ + selector:String, + lightDomServices:ElementServicesFunction, + implementsTypes:Array + }) + { + this.lightDomServices = lightDomServices; + this.selector = selector; + } +} diff --git a/modules/core/src/annotations/facade.dart b/modules/core/src/annotations/facade.dart new file mode 100644 index 0000000000..56ac0c7744 --- /dev/null +++ b/modules/core/src/annotations/facade.dart @@ -0,0 +1,5 @@ +import 'package:di/di.dart' show Module; +import '../view/element_module.dart' show ElementModule; + +typedef DomServicesFunction(ElementModule m); +typedef ComponentServicesFunction(Module m); \ No newline at end of file diff --git a/modules/core/src/annotations/facade.es6 b/modules/core/src/annotations/facade.es6 new file mode 100644 index 0000000000..ee9dc146b6 --- /dev/null +++ b/modules/core/src/annotations/facade.es6 @@ -0,0 +1,2 @@ +export var DomServicesFunction = Function; +export var ComponentServicesFunction = Function; \ No newline at end of file diff --git a/modules/core/src/annotations/template_config.js b/modules/core/src/annotations/template_config.js new file mode 100644 index 0000000000..ca834aff2e --- /dev/null +++ b/modules/core/src/annotations/template_config.js @@ -0,0 +1,16 @@ +import {Type, List} from 'facade/lang'; + +export class TemplateConfig { + @CONST constructor({ + url, + directives, + formatters, + source + }: { + url: String, + directives: List, + formatters: List, + source: List + }) + {} +} \ No newline at end of file diff --git a/modules/core/src/compiler/compiler.es6d b/modules/core/src/compiler/compiler.js similarity index 50% rename from modules/core/src/compiler/compiler.es6d rename to modules/core/src/compiler/compiler.js index 32089af724..3ff9b4471a 100644 --- a/modules/core/src/compiler/compiler.es6d +++ b/modules/core/src/compiler/compiler.js @@ -1,7 +1,15 @@ -import {Future} from '../facade'; -import {ProtoView} from './proto_view'; +import {Future} from 'facade/lang'; +import {Element} from 'facade/dom'; +import {ProtoView} from '../view/proto_view'; +import {TemplateLoader} from './template_loader'; export class Compiler { + + @FIELD('final _templateLoader:TemplateLoader') + constructor(templateLoader:TemplateLoader) { + this._templateLoader = templateLoader; + } + /** * # Why future? * - compilation will load templates. Instantiating views before templates are loaded will @@ -10,7 +18,9 @@ export class Compiler { * - don't know about injector in deserialization * - compile does not need the injector, only the ViewFactory does */ - @of(ProtoView) compile(element:TemplateElement):Future { + compile(component:Type, element:Element/* = null*/):Future { + return null; } + } \ No newline at end of file diff --git a/modules/core/src/compiler/template_loader.js b/modules/core/src/compiler/template_loader.js new file mode 100644 index 0000000000..cc03cf8551 --- /dev/null +++ b/modules/core/src/compiler/template_loader.js @@ -0,0 +1,11 @@ +import {Future} from 'facade/lang'; +import {Document} from 'facade/dom'; + +export class TemplateLoader { + + constructor() {} + + load(url:String):Future { + return null; + } +} \ No newline at end of file diff --git a/modules/core/src/life_cycle/life_cycle.js b/modules/core/src/life_cycle/life_cycle.js new file mode 100644 index 0000000000..5185b7ce95 --- /dev/null +++ b/modules/core/src/life_cycle/life_cycle.js @@ -0,0 +1,11 @@ +export class LifeCycle { + + @FIELD('final _changeDetection:ChangeDetection') + @FIELD('final _onChangeDispatcher:OnChangeDispatcher') + constructor() {} + + digest() { + _changeDetection.detectChanges(); + _onChangeDispatcher.done(); + } +} \ No newline at end of file diff --git a/modules/core/src/view/element_injector_target.js b/modules/core/src/view/element_injector_target.js new file mode 100644 index 0000000000..67392367cf --- /dev/null +++ b/modules/core/src/view/element_injector_target.js @@ -0,0 +1,13 @@ +export class ElementInjectorTarget { + @FIELD('final _elementInjectorIndex:int') + @FIELD('final _directiveIndex:int') + @FIELD('final _setterName:String') + @FIELD('final _setter:SetterFn') + constructor() {} + + invoke(record:Record, elementInjectors:List) { + var elementInjector:ElementInjector = elementInjectors[this._elementInjectorIndex]; + var directive = elementInjectors.getByIndex(this._directiveIndex); + this._setter(directive, record.currentValue); + } +} diff --git a/modules/core/src/view/element_module.js b/modules/core/src/view/element_module.js new file mode 100644 index 0000000000..2487f92f44 --- /dev/null +++ b/modules/core/src/view/element_module.js @@ -0,0 +1 @@ +export class ElementModule {} \ No newline at end of file diff --git a/modules/core/src/view/on_change_dispatcher.js b/modules/core/src/view/on_change_dispatcher.js new file mode 100644 index 0000000000..5fdc017fa3 --- /dev/null +++ b/modules/core/src/view/on_change_dispatcher.js @@ -0,0 +1,19 @@ + +//TODO(tbosch): I don't like to have done be called from a different place than notify +// notify is called by change detection, but done is called by our wrapper on detect changes. +export class OnChangeDispatcher { + + @FIELD('_lastView:View') + @FIELD('_lastTarget:ElementInjectorTarget') + constructor() { + + } + + notify(view:View, eTarget:ElementInjectorTarget) { + + } + + done() { + + } +} \ No newline at end of file diff --git a/modules/core/src/view/proto_element_injector.js b/modules/core/src/view/proto_element_injector.js new file mode 100644 index 0000000000..9c3029bc17 --- /dev/null +++ b/modules/core/src/view/proto_element_injector.js @@ -0,0 +1,27 @@ + + +/** + +Difference beteween di.Injector and ElementInjector + +di.Injector (di.Module): + - imperative based (can create child injectors imperativly) + - Lazy loading of code + - Component/App Level services which are usually not DOM Related. + + +ElementInjector (ElementModule): + - ProtoBased (Injector structure fixed at compile time) + - understands @Ancestor, @Parent, @Child, @Descendent + - Fast + - Query mechanism for children + - 1:1 to DOM structure. + */ + +export class ProtoElementInjector { + @FIELD('final _parent:ProtoElementInjector') + /// Temporory instance while instantiating + @FIELD('_instance:ElementInjector') + constructor() {} +} + diff --git a/modules/core/src/view/proto_view.js b/modules/core/src/view/proto_view.js new file mode 100644 index 0000000000..93c97e6e99 --- /dev/null +++ b/modules/core/src/view/proto_view.js @@ -0,0 +1,10 @@ +import {Module} from 'di/di'; +import {TemplateElement} from 'facade/dom'; + +export class ProtoView { + @FIELD('final _template:TemplateElement') + @FIELD('final _module:Module') + @FIELD('final _protoElementInjectors:List') + @FIELD('final _protoWatchGroup:ProtoWatchGroup') + @CONST constructor() { } +} \ No newline at end of file diff --git a/modules/core/src/view/view.js b/modules/core/src/view/view.js new file mode 100644 index 0000000000..506432ce43 --- /dev/null +++ b/modules/core/src/view/view.js @@ -0,0 +1,34 @@ +import {Node, DocumentFragment} from 'facade/dom'; +import {ListWrapper wraps List} from 'facade/collection'; +import {Record} from 'change_detection/record'; + +@IMPLEMENTS(WatchGroupDispatcher) +export class View { + @FIELD('final _fragment:DocumentFragment') + /// This list matches the _nodes list. It is sparse, since only Elements have ElementInjector + @FIELD('final _rootElementInjectors:List') + @FIELD('final _elementInjectors:List') + @FIELD('final _textNodes:List') + @FIELD('final _watchGroup:WatchGroup') + /// When the view is part of render tree, the DocumentFragment is empty, which is why we need + /// to keep track of the nodes. + @FIELD('final _nodes:List') + constructor(fragment:DocumentFragment) { + this._fragment = fragment; + this._nodes = ListWrapper.clone(fragment.childNodes); + } + + notify(record:Record, target) { + /* + // dispatch to element injector or text nodes based on context + if (Number.is(target)) { + // we know it refferst to _textNodes. + } else { + // we know that it is ElementInjectorTarge + var eTarget:ElementInjectorTarget = target; + onChangeDispatcher.notify(this, eTarget); + eTarget.invoke(record, _elementInjectors); + } + */ + } +} diff --git a/modules/core/test/compiler/compiler_spec.js b/modules/core/test/compiler/compiler_spec.js new file mode 100644 index 0000000000..f4d50cd01e --- /dev/null +++ b/modules/core/test/compiler/compiler_spec.js @@ -0,0 +1,9 @@ +import {describe, id} from 'spec/spec'; + +function main() { + describe('compiler', () => { + it('should hello', () => { + print('I am working'); + }); + }); +} diff --git a/modules/di/pubspec.yaml b/modules/di/pubspec.yaml new file mode 100644 index 0000000000..c42a0029cd --- /dev/null +++ b/modules/di/pubspec.yaml @@ -0,0 +1,6 @@ +name: di +environment: + sdk: '>=1.4.0' +dependencies: +dev_dependencies: + unittest: '>=0.10.1 <0.12.0' diff --git a/modules/di/src/di.js b/modules/di/src/di.js new file mode 100644 index 0000000000..57b512dfc9 --- /dev/null +++ b/modules/di/src/di.js @@ -0,0 +1 @@ +export * from './module'; \ No newline at end of file diff --git a/modules/di/src/module.js b/modules/di/src/module.js new file mode 100644 index 0000000000..7664a7f3aa --- /dev/null +++ b/modules/di/src/module.js @@ -0,0 +1,24 @@ +import {Type} from 'facade/lang'; +import {Map, MapWrapper wraps Map} from 'facade/collection'; + +/// becouse we need to know when toValue was not set. +/// (it could be that toValue is set to null or undefined in js) +var _UNDEFINED = {} + +export class Module { + + @FIELD('final bindings:Map') + constructor(){ + this.bindings = new MapWrapper(); + } + + bind(type:Type, + {toValue=_UNDEFINED, toFactory, toImplementation, inject, toInstanceOf, withAnnotation}/*: + {toFactory:Function, toImplementation: Type, inject: Array, toInstanceOf:Type}*/) {} + + bindByKey(key:Key, + {toValue=_UNDEFINED, toFactory, toImplementation, inject, toInstanceOf}/*: + {toFactory:Function, toImplementation: Type, inject: Array, toInstanceOf:Type}*/) {} + + install(module:Module) {} +} diff --git a/modules/examples/pubspec.yaml b/modules/examples/pubspec.yaml new file mode 100644 index 0000000000..03b2478582 --- /dev/null +++ b/modules/examples/pubspec.yaml @@ -0,0 +1,6 @@ +name: examples +environment: + sdk: '>=1.4.0' +dependencies: +dev_dependencies: + unittest: '>=0.10.1 <0.12.0' diff --git a/modules/examples/src/todo/app.es6d b/modules/examples/src/todo/app.js similarity index 94% rename from modules/examples/src/todo/app.es6d rename to modules/examples/src/todo/app.js index c51bf74975..626ba7d06b 100644 --- a/modules/examples/src/todo/app.es6d +++ b/modules/examples/src/todo/app.js @@ -1,5 +1,6 @@ import {DOM} from './dom'; export class App { + @field('input:Element') constructor() { this.input = null; this.list = null; diff --git a/modules/facade/bootstrap.es5 b/modules/facade/bootstrap.es5 new file mode 100644 index 0000000000..7ba8e2a189 --- /dev/null +++ b/modules/facade/bootstrap.es5 @@ -0,0 +1,12 @@ +/** + * This is a special facade used to bootstrap JS automatically. + * (In contrast to door wheere the user needs to explicitly call into angular.) + * This file is appened to AngularJS and needs to be written in ES5. + */ +(function(window, document) { + document.addEventListener('DOMContentLoaded', bootstrap, false); + function bootstrap() { + // TODO(misko): load application factory from the module system. + applicationFactory().run(); + } +})(window, document); \ No newline at end of file diff --git a/modules/facade/pubspec.yaml b/modules/facade/pubspec.yaml new file mode 100644 index 0000000000..e5bd9d2b19 --- /dev/null +++ b/modules/facade/pubspec.yaml @@ -0,0 +1,6 @@ +name: facade +environment: + sdk: '>=1.4.0' +dependencies: +dev_dependencies: + unittest: '>=0.10.1 <0.12.0' diff --git a/modules/facade/src/collection.dart b/modules/facade/src/collection.dart new file mode 100644 index 0000000000..36341c1629 --- /dev/null +++ b/modules/facade/src/collection.dart @@ -0,0 +1,20 @@ +library facade.collection; + +import 'dart:collection' show HashMap; +export 'dart:collection' show Map; +export 'dart:core' show List; + +class MapWrapper { + static HashMap create() => new HashMap(); + static get(m, k) => m[k]; + static void set(m, k, v){ m[k] = v; } + static contains(m, k) => m.containsKey(k); +} + +class ListWrapper { + static List clone(List l) => new List.from(l); + static List create() => new List(); + static get(m, k) => m[k]; + static void set(m, k, v) { m[k] = v; } + static contains(m, k) => m.containsKey(k); +} diff --git a/modules/facade/src/collection.es6 b/modules/facade/src/collection.es6 new file mode 100644 index 0000000000..d80c3eb8e2 --- /dev/null +++ b/modules/facade/src/collection.es6 @@ -0,0 +1,15 @@ +export var List = window.Array; +export var Map = window.Map; +export class MapWrapper { + static create():HashMap { return new HashMap(); } + static get(m, k) { return m[k]; } + static set(m, k, v) { m[k] = v; } + static contains(m, k) { return m.containsKey(k); } +} + + +export class ListWrapper { + static create():List { return new List(); } + static get(m, k) { return m[k]; } + static set(m, k, v) { m[k] = v; } +} \ No newline at end of file diff --git a/modules/examples/src/todo/dom.dart b/modules/facade/src/dom.dart similarity index 74% rename from modules/examples/src/todo/dom.dart rename to modules/facade/src/dom.dart index 620a906604..aa41098f83 100644 --- a/modules/examples/src/todo/dom.dart +++ b/modules/facade/src/dom.dart @@ -1,7 +1,9 @@ -library dom; +library angular.core.facade.dom; import 'dart:html'; +export 'dart:html' show DocumentFragment, Node, Element, TemplateElement; + class DOM { static query(selector) { return document.query(selector); diff --git a/modules/examples/src/todo/dom.es6 b/modules/facade/src/dom.es6 similarity index 62% rename from modules/examples/src/todo/dom.es6 rename to modules/facade/src/dom.es6 index 38552a8a9a..87f2b0b921 100644 --- a/modules/examples/src/todo/dom.es6 +++ b/modules/facade/src/dom.es6 @@ -1,3 +1,8 @@ +export var DocumentFragment = window.DocumentFragment; +export var Node = window.Node; +export var Element = window.HTMLElement; +export var TemplateElement = window.HTMLTemplateElement; + export class DOM { static query(selector) { return document.querySelector(selector); diff --git a/modules/facade/src/lang.dart b/modules/facade/src/lang.dart new file mode 100644 index 0000000000..bfea25f1ec --- /dev/null +++ b/modules/facade/src/lang.dart @@ -0,0 +1,4 @@ +library angular.core.facade.async; + +export 'dart:async' show Future; +export 'dart:core' show Type; \ No newline at end of file diff --git a/modules/facade/src/lang.es6 b/modules/facade/src/lang.es6 new file mode 100644 index 0000000000..12d7f60c9a --- /dev/null +++ b/modules/facade/src/lang.es6 @@ -0,0 +1,2 @@ +export var Future = Promise; +export var Type = Function; \ No newline at end of file diff --git a/modules/facade/test.dart b/modules/facade/test.dart new file mode 100644 index 0000000000..251399affd --- /dev/null +++ b/modules/facade/test.dart @@ -0,0 +1,13 @@ +import 'dart:core' as core; +import 'dart:collection'; + +class Map { + + new() => null; + + ping() => core.print('map'); +} + +main() { + new Map().ping(); +} \ No newline at end of file diff --git a/tools/js2dart b/tools/js2dart index 9fc0b73866..971ffb32b8 160000 --- a/tools/js2dart +++ b/tools/js2dart @@ -1 +1 @@ -Subproject commit 9fc0b738664c75ac16c44f190322b4b7ca95a1ea +Subproject commit 971ffb32b88bcad5eab5877ecbde2995e30c96c1