Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1224)

Side by Side Diff: lib/html_import_annotation.dart

Issue 882823003: Adds @HtmlImport with both dynamic and transformer based implementations. Still need an HtmlInliner… (Closed) Base URL: git@github.com:dart-lang/web-components.git@master
Patch Set: assign logger Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 library web_components.html_import_annotation;
5
6 import 'dart:async';
7 import 'dart:html';
8 import 'package:initialize/initialize.dart';
9 import 'src/normalize_path.dart';
10
11 /// Annotation for a dart library which injects an html import into the
12 /// current html document. The imported file must not contain any dart script
13 /// tags, as they cannot be dynamically loaded.
14 class HtmlImport implements Initializer<LibraryIdentifier> {
15 final String filePath;
16
17 const HtmlImport(this.filePath);
18
19 Future initialize(LibraryIdentifier library) {
20 var element = new LinkElement()
21 ..rel = 'import'
22 ..href = normalizeHtmlImportPath(filePath, library.package, library.path);
23 document.head.append(element);
24 var completer = new Completer();
25 var listeners = [
26 element.on['load'].listen((_) => completer.complete()),
27 element.on['error'].listen((_) {
28 print('Error loading html import from path `$filePath`');
29 completer.complete();
30 }),
31 ];
32 return completer.future.then((_) {
33 listeners.forEach((listener) => listener.cancel());
34 });
35 }
36 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698