Skip to content
This repository has been archived by the owner on Jan 20, 2018. It is now read-only.

Commit

Permalink
Move DomProxyMixin to this package
Browse files Browse the repository at this point in the history
R=sigmund@google.com

Review URL: https://codereview.chromium.org//1091903002
  • Loading branch information
jakemac53 committed Apr 17, 2015
1 parent 7f60b42 commit 5635905
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 8 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,23 @@
#### 0.11.2
* Copied `DomProxyMixin` from `custom_element_apigen` to this package and
renamed it `CustomElementProxyMixin`. This can be mixed into any class that
is using the `@CustomElementProxy` annotation and provides easy access to
the underlying javascript element via the `jsElement` getter. For instance
the following is a simple example of a dart class that wraps a custom
javascript element `foo-element` with a method `doFoo` and a property `foo`.

@CustomElementProxy('foo-element')
class FooElement extends HtmlElement with CustomElementProxyMixin {
FooElement.created() : super.created();

void doFoo(int arg1) => jsElement.callMethod('doFoo', [arg1]);

int get foo => jsElement['foo'];
void set foo(int newFoo) {
jsElement['foo'] = newFoo;
}
}

#### 0.11.1+3
* Switch `html5lib` package dependency to `html`.

Expand Down
8 changes: 4 additions & 4 deletions lib/build/mirrors_remover.dart
Expand Up @@ -17,9 +17,9 @@ class MirrorsRemoverTransformer extends Transformer {
@override
Future apply(Transform transform) async {
String source = await transform.primaryInput.readAsString();
source = source.replaceAll(
'mirror_initializer.dart', 'static_initializer.dart');
transform.addOutput(
new Asset.fromString(transform.primaryInput.id, source));
source =
source.replaceAll('mirror_initializer.dart', 'static_initializer.dart');
transform
.addOutput(new Asset.fromString(transform.primaryInput.id, source));
}
}
15 changes: 15 additions & 0 deletions lib/custom_element_proxy.dart
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
library web_components.custom_element_proxy;

import 'dart:js' as js;
import 'package:initialize/initialize.dart';
import 'interop.dart';

Expand All @@ -22,3 +23,17 @@ class CustomElementProxy implements Initializer<Type> {
registerDartType(tagName, t, extendsTag: extendsTag);
}
}

/// A simple mixin to make it easier to interoperate with the Javascript API of
/// a browser object. This is mainly used by classes that expose a Dart API for
/// Javascript custom elements.
class CustomElementProxyMixin {
js.JsObject _proxy;

js.JsObject get jsElement {
if (_proxy == null) {
_proxy = new js.JsObject.fromBrowserObject(this);
}
return _proxy;
}
}
7 changes: 4 additions & 3 deletions lib/src/init.dart
Expand Up @@ -23,8 +23,9 @@ Future initWebComponents({List<Type> typeFilter, InitializerFilter customFilter,
if (typeFilter != null || customFilter != null) {
return init.run(typeFilter: typeFilter, customFilter: customFilter);
} else {
return init.run(typeFilter: [HtmlImport])
.then((_) => init.run(typeFilter: [CustomElement, CustomElementProxy]))
.then((_) => initAll ? init.run() : null);
return init
.run(typeFilter: [HtmlImport])
.then((_) => init.run(typeFilter: [CustomElement, CustomElementProxy]))
.then((_) => initAll ? init.run() : null);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,5 +1,5 @@
name: web_components
version: 0.11.1+3
version: 0.11.2
author: Polymer.dart Authors <web-ui-dev@dartlang.org>
homepage: https://www.dartlang.org/polymer-dart/
description: >
Expand Down

0 comments on commit 5635905

Please sign in to comment.