-
Notifications
You must be signed in to change notification settings - Fork 0
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
Address TODO - LanguageBehavior is now offered by the generic PropertiesFromAncestorBehavior so use it #2
Open
slawomir-brzezinski-at-interxion
wants to merge
1
commit into
master
Choose a base branch
from
Use-PropertiesFromAncestorBehavior
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+87
−91
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v1.0.x | ||
v1.1.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<link rel="import" href="../../polymer/polymer.html" /> | ||
<dom-module id="container-with-lang-choice"> | ||
<template> | ||
<label> | ||
Interface Language: | ||
<select id="languageSelect" value="{{lang::input}}"></select> | ||
</label> | ||
<content select="*"></content> | ||
</template> | ||
</dom-module> | ||
<script> | ||
Polymer({ | ||
is: "container-with-lang-choice", | ||
properties: { | ||
lang: { | ||
notify: true, | ||
reflectToAttribute: true, | ||
}, | ||
availableLanguagesExpr: { | ||
type: String, | ||
observer: '_availableLanguagesExprChanged', | ||
}, | ||
availableLanguages: { | ||
type: Array, | ||
observer: '_availableLanguagesChanged', | ||
}, | ||
}, | ||
_availableLanguagesExprChanged: function (availableLanguagesExpr) { | ||
this.availableLanguages = eval(availableLanguagesExpr); | ||
}, | ||
_availableLanguagesChanged: function (availableLanguages) { | ||
// adding options here instead in <template> to suport IE11 - https://github.com/Polymer/polymer/issues/1735 | ||
|
||
this.$.languageSelect.innerHTML = ''; | ||
|
||
for (var i = 0; i < availableLanguages.length; ++i) { | ||
var option = document.createElement('option'); | ||
option.innerText = availableLanguages[i]; | ||
this.$.languageSelect.appendChild(option); | ||
} | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Global variables suck. I can't see a reason to change this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well. Global variables are not verboten. Global variable here is just an easy way to access things can be made available before any element is created, where the usage [requires it]/[would benefit from it]. By correctly representing scopes of variance, they aid in understanding complexity and encapsulating variance - if something exists with intention to be always same for all instances, there's no reason it should pollute the properties of each instance, where a user could break these intentions.
Even Polymer prescribes using global variables, not only for behaviors, but for elements as well, fore example to have a custom constructor.
Similarly, global variables are natural for usages where components are declared as vanilla JS classes, (arguably, where Polymer is heading) since a named class declaration essentially creates a variable of that name. Using ES6 module with the class as 'default export' could save from this, but it's only an option. And with ES6 classes, IMO best way to represent this would be a
static get
, just like the properties declaration in Polymer 2.0, which also don't get copied to instances.Here, the reason for the global variable is because usages, such as this
<container-with-lang-choice>
, benefit from having available the list of supported languages. If we movedPapyrusDetails.resources
anywhere else, like on the instance of element, we will need rewrite this pretty simple code to something harder to understand. I'm keen to see how such an implementation would stack up.