Skip to content

Instantly share code, notes, and snippets.

@leonsenft
leonsenft / main.dart
Created January 31, 2020 18:33
Demonstrates that type inference is dependent on order of type parameters
class Value {}
class Renderer<T> {}
// When V is defined before R, type inference works in all cases.
class WorkingOrder<V extends Value, R extends Renderer<V>> {}
// When V is defined after R, type inference fails in some cases.
class BrokenOrder<R extends Renderer<V>, V extends Value> {}
@leonsenft
leonsenft / main.dart
Last active June 28, 2018 06:20
TypeError due to lack of inference
typedef PathFunction = String Function([List<String> segment]);
PathFunction createPathFunction() {
// The type of this default list is not inferred from context.
// Typing the LHS or applying type arguments to the RHS fixes this.
return ([args = const []]) {
return '/${args.join('/')}';
};
}
13724c13724
< var detectors, $length, i, t1;
---
> var detectors, $length, i;
13729,13738d13728
< if ($.$get$ChangeDetectionHost__enforceNoNewChanges())
< for (i = 0; i < $length; ++i) {
< t1 = detectors[i];
< $.AppViewUtils__throwOnChangesCounter = $.AppViewUtils__throwOnChangesCounter + 1;
< $.AppViewUtils_throwOnChanges = true;
16342c16342
< if (firstCheck) {
---
> if (firstCheck && !$.AppViewUtils_throwOnChanges) {
16362,16371c16362,16373
< if (firstCheck)
< this._RouterLinkActive_5_6.ngAfterViewInit$0();
< if (firstCheck)
< this._RouterLinkActive_8_6.ngAfterViewInit$0();
< if (firstCheck)
DartType resolveGenerics(DartType type) {
if (type is TypeParameterType) {
return type.resolveToBound(dynamicType); // T --> dynamic.
} else if (type is ParameterizedType) {
// [T, ...] --> [dynamic, ...]
final resolvedTypeArguments =
type.typeArguments.map(resolveTypeParameters).toList();
// Fails on nested unbounded type arguments.
// * List<T>.instantiate([dynamic]) --> List<dynamic>
// * List<Foo<T>>.instantiate([Foo<dynamic>]) --> List<Foo<T>>
@leonsenft
leonsenft / greet_component.dart
Last active August 21, 2017 20:02
An example AngularDart component.
import 'package:angular/angular.dart';
@Component(
selector: 'greet',
template: '<p>Hello {{name}}!</p>',
)
class GreetComponent {
String name;
}
import 'package:angular/angular.dart';
import 'my_button_directive.dart';
@Directive(selector: '[illegal-button]')
class IllegalButtonDirective extends MyButtonDirective {
@Input('notEnabled') // Changing the binding name causes a compile error.
set disabled(bool value) {
super.disabled = value;
}
@leonsenft
leonsenft / my_button_component.dart
Last active July 22, 2017 00:08
Button component leveraging metadata inheritance.
import 'package:angular/angular.dart';
import 'my_button_directive.dart';
@Component(
selector: 'my-button',
template: '<ng-content></ng-content>',
)
class MyButtonComponent extends MyButtonDirective {}
@leonsenft
leonsenft / my_button_component.dart
Last active July 21, 2017 22:04
Button component not leveraging metadata inheritance.
import 'package:angular/angular.dart';
import 'my_button_directive.dart';
@Component(
selector: 'my-button',
template: '<ng-content></ng-content>',
inputs: const ['disabled'],
outputs: const ['trigger'],
host: const {
@leonsenft
leonsenft / my_button_directive.dart
Last active July 22, 2017 00:09
Basic button directive.
import 'dart:async';
import 'dart:html';
import 'package:angular/angular.dart';
@Directive(selector: '[my-button]')
class MyButtonDirective {
final StreamController<UIEvent> _trigger = new StreamController<UIEvent>();
@Input()