Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions benchmark/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ packages:
analyzer:
description: analyzer
source: hosted
version: "0.13.6"
version: "0.15.7"
angular:
description:
path: ".."
Expand All @@ -30,23 +30,25 @@ packages:
code_transformers:
description: code_transformers
source: hosted
version: "0.1.3"
version: "0.1.4+2"
collection:
description: collection
source: hosted
version: "0.9.2"
di:
description: di
source: hosted
version: "1.0.0"
description:
path: "../../di.dart"
relative: true
source: path
version: "2.0.0-alpha.9"
html5lib:
description: html5lib
source: hosted
version: "0.10.0"
intl:
description: intl
source: hosted
version: "0.9.9"
version: "0.9.10"
logging:
description: logging
source: hosted
Expand Down
1 change: 1 addition & 0 deletions benchmark/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ transformers:
- $dart2js:
minify: false
checked: false
commandLineOptions: [--dump-info]
1 change: 1 addition & 0 deletions benchmark/web/tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class NgFreeTreeClass implements ShadowRootAware {

// Main function runs the benchmark.
main() {
setupModuleTypeReflector();
var cleanup, createDom;

var module = new Module()
Expand Down
4 changes: 1 addition & 3 deletions bin/parser_generator_for_spec.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:io' as io;

import 'package:di/di.dart';
import 'package:di/dynamic_injector.dart';
import 'package:angular/cache/module.dart';
import 'package:angular/core/parser/lexer.dart';
import 'package:angular/core/parser/parser.dart';
Expand All @@ -14,8 +13,7 @@ main(arguments) {
..bind(Parser, toImplementation: DynamicParser)
..install(new CacheModule());
module.bind(ParserBackend, toImplementation: DartGetterSetterGen);
Injector injector = new DynamicInjector(modules: [module],
allowImplicitInjection: true);
Injector injector = new ModuleInjector([module]);

// List generated using:
// node node_modules/karma/bin/karma run | grep -Eo ":XNAY:.*:XNAY:" | sed -e 's/:XNAY://g' | sed -e "s/^/'/" | sed -e "s/$/',/" | sort | uniq > missing_expressions
Expand Down
13 changes: 8 additions & 5 deletions lib/application.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import 'package:angular/routing/module.dart';
import 'package:angular/introspection.dart';

import 'package:angular/core_dom/static_keys.dart';
import 'package:angular/core_dom/directive_injector.dart';

/**
* This is the top level module which describes all Angular components,
Expand All @@ -96,6 +97,7 @@ import 'package:angular/core_dom/static_keys.dart';
*/
class AngularModule extends Module {
AngularModule() {
DirectiveInjector.initUID();
install(new CacheModule());
install(new CoreModule());
install(new CoreDomModule());
Expand All @@ -105,7 +107,6 @@ class AngularModule extends Module {
install(new PerfModule());
install(new RoutingModule());

bind(MetadataExtractor);
bind(Expando, toValue: elementExpando);
}
}
Expand Down Expand Up @@ -175,9 +176,11 @@ abstract class Application {
injector.getByKey(JS_CACHE_REGISTER_KEY);
initializeDateFormatting(null, null).then((_) {
try {
var compiler = injector.getByKey(COMPILER_KEY);
var viewFactory = compiler(rootElements, injector.getByKey(DIRECTIVE_MAP_KEY));
viewFactory(injector, rootElements);
Compiler compiler = injector.getByKey(COMPILER_KEY);
DirectiveMap directiveMap = injector.getByKey(DIRECTIVE_MAP_KEY);
RootScope rootScope = injector.getByKey(ROOT_SCOPE_KEY);
ViewFactory viewFactory = compiler(rootElements, directiveMap);
viewFactory(rootScope, injector.get(DirectiveInjector), rootElements);
} catch (e, s) {
exceptionHandler(e, s);
}
Expand All @@ -190,5 +193,5 @@ abstract class Application {
* Creates an injector function that can be used for retrieving services as well as for
* dependency injection.
*/
Injector createInjector();
Injector createInjector() => new ModuleInjector(modules);
}
3 changes: 0 additions & 3 deletions lib/application_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
library angular.app.factory;

import 'package:di/dynamic_injector.dart';
import 'package:angular/angular.dart';
import 'package:angular/core/registry.dart';
import 'package:angular/core/parser/parser.dart' show ClosureMap;
Expand Down Expand Up @@ -64,8 +63,6 @@ class _DynamicApplication extends Application {
..bind(FieldGetterFactory, toImplementation: DynamicFieldGetterFactory)
..bind(ClosureMap, toImplementation: DynamicClosureMap);
}

Injector createInjector() => new DynamicInjector(modules: modules);
}

/**
Expand Down
26 changes: 9 additions & 17 deletions lib/application_factory_static.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
*/
library angular.app.factory.static;

import 'package:di/static_injector.dart';
import 'package:di/di.dart' show TypeFactory, Injector;
import 'package:angular/application.dart';
import 'package:angular/core/registry.dart';
import 'package:angular/core/parser/parser.dart';
Expand All @@ -46,9 +44,7 @@ export 'package:angular/change_detection/change_detection.dart' show
FieldSetter;

class _StaticApplication extends Application {
final Map<Type, TypeFactory> typeFactories;

_StaticApplication(Map<Type, TypeFactory> this.typeFactories,
_StaticApplication(
Map<Type, Object> metadata,
Map<String, FieldGetter> fieldGetters,
Map<String, FieldSetter> fieldSetters,
Expand All @@ -58,9 +54,6 @@ class _StaticApplication extends Application {
..bind(FieldGetterFactory, toValue: new StaticFieldGetterFactory(fieldGetters))
..bind(ClosureMap, toValue: new StaticClosureMap(fieldGetters, fieldSetters, symbols));
}

Injector createInjector() =>
new StaticInjector(modules: modules, typeFactories: typeFactories);
}

/**
Expand All @@ -81,20 +74,19 @@ class _StaticApplication extends Application {
* becomes:
*
* main() {
* staticApplication(generated_static_injector.factories,
* generated_static_metadata.typeAnnotations,
* generated_static_expressions.getters,
* generated_static_expressions.setters,
* generated_static_expressions.symbols)
* .addModule(new Module()..bind(HelloWorldController))
* .run();
* staticApplication(
* generated_static_metadata.typeAnnotations,
* generated_static_expressions.getters,
* generated_static_expressions.setters,
* generated_static_expressions.symbols)
* .addModule(new Module()..bind(HelloWorldController))
* .run();
*
*/
Application staticApplicationFactory(
Map<Type, TypeFactory> typeFactories,
Map<Type, Object> metadata,
Map<String, FieldGetter> fieldGetters,
Map<String, FieldSetter> fieldSetters,
Map<String, Symbol> symbols) {
return new _StaticApplication(typeFactories, metadata, fieldGetters, fieldSetters, symbols);
return new _StaticApplication(metadata, fieldGetters, fieldSetters, symbols);
}
3 changes: 3 additions & 0 deletions lib/cache/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ class CacheModule extends Module {
CacheModule() {
bind(CacheRegister);
}
CacheModule.withReflector(reflector): super.withReflector(reflector) {
bind(CacheRegister);
}
}
1 change: 1 addition & 0 deletions lib/change_detection/ast_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ library angular.change_detection.ast_parser;

import 'dart:collection';

import 'package:di/di.dart' show Injectable;
import 'package:angular/core/parser/syntax.dart' as syntax;
import 'package:angular/core/parser/parser.dart';
import 'package:angular/core/formatter.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/core/annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export "package:angular/core/annotation_src.dart" show
Formatter,
DirectiveBinder,
DirectiveBinderFn,
Injectable,

Directive,
Component,
Controller,
Decorator,
Visibility,

DirectiveAnnotation,
NgAttr,
Expand Down
65 changes: 23 additions & 42 deletions lib/core/annotation_src.dart
Original file line number Diff line number Diff line change
@@ -1,43 +1,28 @@
library angular.core.annotation_src;

import "package:di/di.dart" show Injector, Visibility;
import "package:di/di.dart" show Injector, Visibility, Factory;

abstract class DirectiveBinder {
bind(key, {Function toFactory, inject,
Visibility visibility: Directive.CHILDREN_VISIBILITY});
bind(key, {Function toFactory, inject, Visibility visibility: Visibility.CHILDREN});
}

typedef void DirectiveBinderFn(DirectiveBinder module);

RegExp _ATTR_NAME = new RegExp(r'\[([^\]]+)\]$');

const String SHADOW_DOM_INJECTOR_NAME = 'SHADOW_INJECTOR';

skipShadow(Injector injector)
=> injector.name == SHADOW_DOM_INJECTOR_NAME ? injector.parent : injector;

localVisibility (Injector requesting, Injector defining)
=> identical(skipShadow(requesting), defining);

directChildrenVisibility(Injector requesting, Injector defining) {
requesting = skipShadow(requesting);
return identical(requesting.parent, defining) || localVisibility(requesting, defining);
}

Directive cloneWithNewMap(Directive annotation, map)
=> annotation._cloneWithNewMap(map);

String mappingSpec(DirectiveAnnotation annotation) => annotation._mappingSpec;

class Visibility {
static const LOCAL = const Visibility._('LOCAL');
static const CHILDREN = const Visibility._('CHILDREN');
static const DIRECT_CHILD = const Visibility._('DIRECT_CHILD');

/**
* An annotation when applied to a class indicates that the class (service) will
* be instantiated by di injector. This annotation is also used to designate which
* classes need to have a static factory generated when using static angular, and
* therefore is required on any injectable class.
*/
class Injectable {
const Injectable();
final String name;
const Visibility._(this.name);
toString() => 'Visibility: $name';
}

/**
Expand All @@ -46,16 +31,19 @@ class Injectable {
abstract class Directive {

/// The directive can only be injected to other directives on the same element.
static const Visibility LOCAL_VISIBILITY = localVisibility;
@deprecated // ('Use Visibility.LOCAL instead')
static const Visibility LOCAL_VISIBILITY = Visibility.LOCAL;

/// The directive can be injected to other directives on the same or child elements.
static const Visibility CHILDREN_VISIBILITY = null;
@deprecated// ('Use Visibility.CHILDREN instead')
static const Visibility CHILDREN_VISIBILITY = Visibility.CHILDREN;

/**
* The directive on this element can only be injected to other directives
* declared on elements which are direct children of the current element.
*/
static const Visibility DIRECT_CHILDREN_VISIBILITY = directChildrenVisibility;
@deprecated// ('Use Visibility.DIRECT_CHILD instead')
static const Visibility DIRECT_CHILDREN_VISIBILITY = Visibility.DIRECT_CHILD;

/**
* CSS selector which will trigger this component/directive.
Expand Down Expand Up @@ -129,8 +117,8 @@ abstract class Directive {
* selector: '[foo]',
* module: Foo.moduleFactory)
* class Foo {
* static moduleFactory() => new Module()
* ..bind(SomeTypeA, visibility: Directive.LOCAL_VISIBILITY);
* static moduleFactory(DirectiveBinder binder) =>
* binder.bind(SomeTypeA, visibility: Directive.LOCAL_VISIBILITY);
* }
*
* When specifying types, factories or values in the module, notice that
Expand All @@ -139,7 +127,7 @@ abstract class Directive {
* * [Directive.CHILDREN_VISIBILITY]
* * [Directive.DIRECT_CHILDREN_VISIBILITY]
*/
final Function module;
final DirectiveBinderFn module;

/**
* Use map to define the mapping of DOM attributes to fields.
Expand Down Expand Up @@ -222,19 +210,15 @@ abstract class Directive {

const Directive({
this.selector,
this.children: Directive.COMPILE_CHILDREN,
this.visibility: Directive.LOCAL_VISIBILITY,
this.children,
this.visibility,
this.module,
this.map: const {},
this.exportExpressions: const [],
this.exportExpressionAttrs: const []
});

toString() => selector;
get hashCode => selector.hashCode;
operator==(other) =>
other is Directive && selector == other.selector;

Directive _cloneWithNewMap(newMap);
}

Expand Down Expand Up @@ -335,7 +319,7 @@ class Component extends Directive {
applyAuthorStyles,
resetStyleInheritance,
this.publishAs,
module,
DirectiveBinderFn module,
map,
selector,
visibility,
Expand Down Expand Up @@ -393,7 +377,7 @@ class Decorator extends Directive {
const Decorator({children: Directive.COMPILE_CHILDREN,
map,
selector,
module,
DirectiveBinderFn module,
visibility,
exportExpressions,
exportExpressionAttrs})
Expand Down Expand Up @@ -446,7 +430,7 @@ class Controller extends Decorator {
children: Directive.COMPILE_CHILDREN,
this.publishAs,
map,
module,
DirectiveBinderFn module,
selector,
visibility,
exportExpressions,
Expand Down Expand Up @@ -595,8 +579,5 @@ class Formatter {

const Formatter({this.name});

int get hashCode => name.hashCode;
bool operator==(other) => name == other.name;

toString() => 'Formatter: $name';
}
2 changes: 1 addition & 1 deletion lib/core/formatter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class FormatterMap {
final Injector _injector;

FormatterMap(this._injector, MetadataExtractor extractMetadata) {
_injector.types.forEach((type) {
(_injector as ModuleInjector).types.forEach((type) {
extractMetadata(type)
.where((annotation) => annotation is Formatter)
.forEach((Formatter formatter) {
Expand Down
3 changes: 3 additions & 0 deletions lib/core/module.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export "package:angular/cache/module.dart" show
CacheRegister,
CacheRegisterStats;

export "package:angular/core_dom/directive_injector.dart" show
DirectiveInjector;

export "package:angular/core_dom/module_internal.dart" show
Animation,
AnimationResult,
Expand Down
Loading