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
2 changes: 1 addition & 1 deletion benchmark/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ packages:
di:
description: di
source: hosted
version: "1.0.0"
version: "2.0.0-alpha.1"
html5lib:
description: html5lib
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 @@ -8,6 +8,7 @@ dev_dependencies:
benchmark_harness: '>=1.0.0'
unittest: '>=0.10.1 <0.12.0'
mock: '>=0.10.0 <0.12.0'
di: '>=2.0.0-alpha.1'
transformers:
- angular
- $dart2js:
Expand Down
14 changes: 8 additions & 6 deletions benchmark/web/tree.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:di/di.dart';
import 'package:di/di_dynamic.dart';
import 'package:angular/angular.dart';
import 'package:angular/core_dom/module_internal.dart';
import 'package:angular/application_factory.dart';
Expand Down Expand Up @@ -246,15 +247,16 @@ class NgFreeTreeClass implements ShadowRootAware {

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

var module = new Module()
..type(TreeComponent)
..type(TreeUrlComponent)
..type(NgFreeTree)
..type(NgFreeTreeScoped)
..type(NgFreeTreeClass)
..factory(ScopeDigestTTL, (i) => new ScopeDigestTTL.value(15))
..bind(TreeComponent)
..bind(TreeUrlComponent)
..bind(NgFreeTree)
..bind(NgFreeTreeScoped)
..bind(NgFreeTreeClass)
..bind(ScopeDigestTTL, toFactory: () => new ScopeDigestTTL.value(15))
..bind(CompilerConfig, toValue: new CompilerConfig.withOptions(elementProbeEnabled: false));

var injector = applicationFactory().addModule(module).run();
Expand Down
14 changes: 10 additions & 4 deletions bin/parser_generator_for_spec.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import 'dart:io' as io;

import 'package:di/di.dart';
import 'package:di/dynamic_injector.dart';
import 'package:di/di_dynamic.dart';
import 'package:angular/cache/module.dart';
import 'package:angular/core/parser/lexer.dart';
import 'package:angular/core/parser/parser.dart';
import 'package:angular/tools/parser_getter_setter/generator.dart';

main(arguments) {
Module module = new Module()..bind(Parser, toImplementation: DynamicParser);
setupModuleTypeReflector();
Module module = new Module()
..bind(Lexer)
..bind(ParserGetterSetter)
..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
15 changes: 9 additions & 6 deletions lib/application.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import 'package:angular/routing/module.dart';
import 'package:angular/introspection_js.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 @@ -95,6 +96,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 @@ -103,7 +105,6 @@ class AngularModule extends Module {
install(new PerfModule());
install(new RoutingModule());

bind(MetadataExtractor);
bind(Expando, toValue: elementExpando);
}
}
Expand Down Expand Up @@ -150,7 +151,7 @@ abstract class Application {
modules.add(ngModule);
ngModule..bind(VmTurnZone, toValue: zone)
..bind(Application, toValue: this)
..bind(dom.Node, toFactory: (i) => i.getByKey(new Key(Application)).element);
..bind(dom.Node, toFactory: (Application app) => app.element, inject: [Application]);
}

/**
Expand All @@ -171,9 +172,11 @@ abstract class Application {
ExceptionHandler exceptionHandler = injector.getByKey(EXCEPTION_HANDLER_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, null, injector, rootElements);
} catch (e, s) {
exceptionHandler(e, s);
}
Expand All @@ -186,5 +189,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
25 changes: 9 additions & 16 deletions lib/application_factory_static.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +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';
Expand All @@ -46,9 +45,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 +55,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 +75,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);
}
2 changes: 2 additions & 0 deletions lib/cache/cache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class UnboundedCache<K, V> implements Cache<K, V> {
CacheStats stats() => new CacheStats(capacity, size, _hits, _misses);
// Debugging helper.
String toString() => "[$runtimeType: size=${_entries.length}, items=$_entries]";
int get length => -1;
void clear() {}
}


Expand Down
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
7 changes: 6 additions & 1 deletion lib/change_detection/dirty_checking_change_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,12 @@ class DuplicateMap {
final map = new HashMap<dynamic, _DuplicateItemRecordList>();

void put(ItemRecord record, [ItemRecord insertBefore = null]) {
map.putIfAbsent(record.item, () => new _DuplicateItemRecordList()).add(record, insertBefore);
var key = record.item;
_DuplicateItemRecordList duplicates = map[key];
if (duplicates == null) {
duplicates = map[key] = new _DuplicateItemRecordList();
}
duplicates.add(record, insertBefore);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions lib/change_detection/prototype_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ class PrototypeMap<K, V> implements Map<K,V> {
}
// todo(vbe) include prototype ?
V putIfAbsent(key, fn) => self.putIfAbsent(key, fn);

toString() => self.toString();
}
37 changes: 24 additions & 13 deletions lib/change_detection/watch_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
}

Watch watch(AST expression, ReactionFn reactionFn) {
WatchRecord<_Handler> watchRecord =
_cache.putIfAbsent(expression.expression,
() => expression.setupWatch(this));
WatchRecord<_Handler> watchRecord = _cache[expression.expression];
if (watchRecord == null) {
_cache[expression.expression] = watchRecord = expression.setupWatch(this);
}
return watchRecord.handler.addReactionFn(reactionFn);
}

Expand All @@ -161,8 +162,10 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
_fieldCost++;
fieldHandler.watchRecord = watchRecord;

WatchRecord<_Handler> lhsWR = _cache.putIfAbsent(lhs.expression,
() => lhs.setupWatch(this));
WatchRecord<_Handler> lhsWR = _cache[lhs.expression];
if (lhsWR == null) {
lhsWR = _cache[lhs.expression] = lhs.setupWatch(this);
}

// We set a field forwarding handler on LHS. This will allow the change
// objects to propagate to the current WatchRecord.
Expand All @@ -178,8 +181,10 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
var watchRecord = _changeDetector.watch(null, null, collectionHandler);
_collectionCost++;
collectionHandler.watchRecord = watchRecord;
WatchRecord<_Handler> astWR = _cache.putIfAbsent(ast.expression,
() => ast.setupWatch(this));
WatchRecord<_Handler> astWR = _cache[ast.expression];
if (astWR == null) {
astWR = _cache[ast.expression] = ast.setupWatch(this);
}

// We set a field forwarding handler on LHS. This will allow the change
// objects to propagate to the current WatchRecord.
Expand Down Expand Up @@ -230,26 +235,32 @@ class WatchGroup implements _EvalWatchList, _WatchGroupList {
invokeHandler.watchRecord = evalWatchRecord;

if (lhsAST != null) {
var lhsWR = _cache.putIfAbsent(lhsAST.expression,
() => lhsAST.setupWatch(this));
var lhsWR = _cache[lhsAST.expression];
if (lhsWR == null) {
lhsWR = _cache[lhsAST.expression] = lhsAST.setupWatch(this);
}
lhsWR.handler.addForwardHandler(invokeHandler);
invokeHandler.acceptValue(lhsWR.currentValue);
}

// Convert the args from AST to WatchRecords
for (var i = 0; i < argsAST.length; i++) {
var ast = argsAST[i];
WatchRecord<_Handler> record =
_cache.putIfAbsent(ast.expression, () => ast.setupWatch(this));
WatchRecord<_Handler> record = _cache[ast.expression];
if (record == null) {
record = _cache[ast.expression] = ast.setupWatch(this);
}
_ArgHandler handler = new _PositionalArgHandler(this, evalWatchRecord, i);
_ArgHandlerList._add(invokeHandler, handler);
record.handler.addForwardHandler(handler);
handler.acceptValue(record.currentValue);
}

namedArgsAST.forEach((Symbol name, AST ast) {
WatchRecord<_Handler> record = _cache.putIfAbsent(ast.expression,
() => ast.setupWatch(this));
WatchRecord<_Handler> record = _cache[ast.expression];
if (record == null) {
record = _cache[ast.expression] = ast.setupWatch(this);
}
_ArgHandler handler = new _NamedArgHandler(this, evalWatchRecord, name);
_ArgHandlerList._add(invokeHandler, handler);
record.handler.addForwardHandler(handler);
Expand Down
4 changes: 3 additions & 1 deletion lib/core/annotation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export "package:angular/core/annotation_src.dart" show
ShadowRootAware,

Formatter,
Injectable,
DirectiveBinder,
DirectiveBinderFn,

Directive,
Component,
Controller,
Decorator,
Visibility,

DirectiveAnnotation,
NgAttr,
Expand Down
Loading