Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to specify polymer expression globals #13470

Closed
justinfagnani opened this issue Sep 20, 2013 · 17 comments
Closed

Make it easier to specify polymer expression globals #13470

justinfagnani opened this issue Sep 20, 2013 · 17 comments
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug

Comments

@justinfagnani
Copy link
Contributor

Right now it's pretty difficult to specify the globals available to expressions in a PolymerElement. This is what's currently required:

class MyElement extends PolymerElement {
  var _mySyntax = new PolymerExpressions(globals: {
    'enumerate': enumerate,
    'appName': 'My App',
  });

  DocumentFragment instanceTemplate(Element template) =>
      template.createInstance(this, _mySyntax);
}

We'd like to require less boilerplate and at the same time make it easier to statically analyze so that IDEs could offer warnings and code completion within HTML templates.

A solution could be to allow elements to directly declare their globals, and automatically create a PolymerExpressions object using those globals. To make it more declarative and add type annotations, the globas can be a plain Dart object, instead of a map:

class MyGlobals {
  List enumerate(List l) => enumerate(l);
  String appName = 'My App';
}

class MyElement extends PolymerElement {
  var globals = new MyGlobals();
}

@justinfagnani
Copy link
Contributor Author

Issue #13480 has been merged into this issue.

@sigmundch
Copy link
Member

Added this to the M8 milestone.

@sigmundch
Copy link
Member

Removed this from the M8 milestone.
Added this to the Later milestone.

@sigmundch
Copy link
Member

Removed this from the Later milestone.
Added this to the M9 milestone.

@clayberg
Copy link

Removed this from the M9 milestone.
Added this to the 1.1 milestone.

@DartBot
Copy link

DartBot commented Nov 15, 2013

This comment was originally written by @butlermatt


I don't mind globals being a map, it makes it fairly easy to add to it anyways if it was accessible.

If I could do something like this:

class MyElement extends PolymerElement {
  MyElement.created() : super.created() {
    Polymer.Globals['uppercase'] = myFunc;
  }

  String myFunc(s) => s.toUpperCase();
}

I'm assuming Globals would be a static variable accessible to any custom element within my app (eg any custom element that my app imports)

@justinfagnani
Copy link
Contributor Author

I don't think that "globals" should really be global like that, you could really mess with other elements that expect certain globals values. I think the safer way to share a set of globals among elements is to share a superclass or mixin.

@sigmundch
Copy link
Member

Removed this from the 1.1 milestone.
Added this to the 1.2 milestone.

@DartBot
Copy link

DartBot commented Jan 28, 2014

This comment was originally written by @zoechi


May I ask what is new?

@jmesserly
Copy link

Removed Area-Polymer label.
Added Area-Pkg, Pkg-PolymerExpressions labels.

@jmesserly
Copy link

Removed Library-PolymerExpressions label.

@kasperl
Copy link

kasperl commented Jun 4, 2014

Removed this from the 1.2 milestone.
Added this to the 1.6 milestone.

@sigmundch
Copy link
Member

Removed this from the 1.6 milestone.
Added Polymer-P-1 label.

@sigmundch
Copy link
Member

Removed Polymer-P-1 label.
Added Polymer-Milestone-Next label.

@sigmundch
Copy link
Member

Removed Polymer-Milestone-Next label.
Added PolymerMilestone-Next label.

@DartBot
Copy link

DartBot commented Oct 20, 2014

This comment was originally written by @mareksuscak


This is by the way already possible through the mixin (although you have to define mixin for every Polymer component but explicit is better than implicit), see here: http://stackoverflow.com/a/25910776/596625

@DartBot
Copy link

DartBot commented Jun 5, 2015

This issue has been moved to dart-archive/polymer-dart#481.

@DartBot DartBot closed this as completed Jun 5, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

7 participants