Skip to content

Commit

Permalink
Merge pull request dart-archive#52 from dart-lang/when-polymer-ready
Browse files Browse the repository at this point in the history
added @whenPolymerReady which will invoke a function once polymer is ready
  • Loading branch information
jakemac53 committed Apr 9, 2015
2 parents b6518f2 + f300c7e commit 5033927
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 9 deletions.
1 change: 1 addition & 0 deletions .status
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ test/template_attr_template_test: Skip #uses dart:html
test/template_distribute_dynamic_test: Skip #uses dart:html
test/two_way_bind_test: Skip #uses dart:html
test/unbind_test: Skip # uses dart:html
test/when_polymer_ready_test: Skip # uses dart:html
build/test/*: Skip # tests that don't need to be ran after pub-build

[ $ie ]
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
#### 0.16.1
* Added `@whenPolymerReady` annotation for functions. This will call the
function once `Polymer.onReady` completes, reducing the boilerplate in entry
points to the following:

import 'package:polymer/polymer.dart';
export 'package:polymer/init.dart';

@whenPolymerReady
void onReady() {
/// Custom setup code here.
}

#### 0.16.0+7
* Switch to using `initWebComponents` internally which gives better guarantees
around development time ordering of initializers. This should fix most
Expand Down
1 change: 1 addition & 0 deletions lib/polymer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export 'auto_binding.dart';

part 'src/declaration.dart';
part 'src/events.dart';
part 'src/initializers.dart';
part 'src/instance.dart';
part 'src/job.dart';
part 'src/loader.dart';
Expand Down
27 changes: 27 additions & 0 deletions lib/src/initializers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
part of polymer;

/// Automatically registers a polymer element.
class CustomTag implements Initializer<Type> {
final String tagName;
const CustomTag(this.tagName);

@override
initialize(Type t) => Polymer.register(tagName, t);
}

/// Calls a zero argument [Function] after [Polymer.onReady] completes.
typedef dynamic _ZeroArg();
class _WhenPolymerReady implements Initializer<_ZeroArg> {
const _WhenPolymerReady();

@override
void initialize(_ZeroArg f) {
Polymer.onReady.then((_) => f());
}
}

const whenPolymerReady = const _WhenPolymerReady();

8 changes: 0 additions & 8 deletions lib/src/loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@

part of polymer;

/// Annotation used to automatically register polymer elements.
class CustomTag implements Initializer<Type> {
final String tagName;
const CustomTag(this.tagName);

initialize(Type t) => Polymer.register(tagName, t);
}

/// Initializes a polymer application as follows:
/// * if running in development mode, set up a dirty-checking zone that polls
/// for observable changes
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: polymer
version: 0.16.0+7
version: 0.16.1
author: Polymer.dart Authors <[email protected]>
description: >
Polymer.dart is a new type of library for the web, built on top of Web
Expand Down Expand Up @@ -80,6 +80,7 @@ transformers:
- test/two_way_bind_test.html
- test/unbind_test.html
- test/web_components_less_test.html
- test/when_polymer_ready_test.html

environment:
sdk: '>=1.4.0 <2.0.0'
35 changes: 35 additions & 0 deletions test/when_polymer_ready_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

library polymer.test.when_polymer_ready_test;

import 'dart:async';
import 'dart:html';

import 'package:polymer/polymer.dart';
import 'package:unittest/unittest.dart';
import 'package:unittest/html_config.dart';

final Completer done = new Completer();

@CustomTag('x-a')
class XA extends PolymerElement {
XA.created() : super.created();
}

main() {
useHtmlConfiguration();

test('whenPolymerReady functions get called when polymer is ready', () {
expect(querySelector('x-a') is XA, isFalse);
initPolymer();
return done.future;
});
}

@whenPolymerReady
void whenReady() {
expect(querySelector('x-a') is XA, isTrue);
done.complete();
}
21 changes: 21 additions & 0 deletions test/when_polymer_ready_test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<!--
Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
for details. All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
-->
<html>

<head>
<title>whenPolymerReady</title>
<script src="packages/unittest/test_controller.js"></script>
</head>
<body>

<x-a></x-a>

<polymer-element name="x-a"><template>hello!</template></polymer-element>

<script type="application/dart" src="when_polymer_ready_test.dart"></script>
</body>
</html>

0 comments on commit 5033927

Please sign in to comment.