-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Polymer "inheritance" proposal - expose more mixins!! #2510
Comments
From @kristianmandrup on September 30, 2015 13:44 After some research into Polymer.Base
* @method extend
* @param {Object} prototype Target object to copy properties to.
* @param {Object} api Source object to copy properties from.
* @return {Object} prototype object that was passed as first argument.
*/
extend: function(prototype, api) {
/**
* Copies props from a source object to a target object.
*
* Note, this method uses a simple `for...in` strategy for enumerating
* properties. To ensure only `ownProperties` are copied from source
* to target and that accessor implementations are copied, use `extend`.
*
* @method mixin
* @param {Object} target Target object to copy properties to.
* @param {Object} source Source object to copy properties from.
* @return {Object} Target object that was passed as first argument.
*/
mixin: function(target, source) {
for (var i in source) {
target[i] = source[i];
}
return target;
},
copyOwnProperty: function(name, source, target) {
Polymer.Base.chainObject = function(object, inherited) { |
Eric, wow. Thanks. That's cool. |
I have been trying to do this for a while and I finally got a version working. Here's the link: https://plnkr.co/edit/S3hwK5?p=preview. This certainly has limitations and I have only tested these with paper-elements, but it works for me so far. Below is the mixin for quick review:
|
@jaichandra |
The above code certainly has performance limitations. I would need help figuring out a much cleaner way in Polymer to ensure each component does this template merge only once. |
I created this Polymer extension years ago. var myElement = Polymer.findRegistered('my-element');
// Each key: properties, props, methods act as a mixin.
// properties - properties object
// props - all attributes (non-functions)
// methods: - all own functions
// behaviors: - all own functions and attributes
var myExtension = Polymer.extend({
parent: myElement,
// properties: myElement.properties,
// props: myElement.props,
// methods: myElement.methods,
// behaviors: myElement.behaviors
}, {
is: 'ext-element',
});
Polymer(myExtension); |
@kristianmandrup I got the performance issue fixed. Updated above code with latest. |
This has shipped with the native API of |
From @kristianmandrup on September 30, 2015 7:45
I fully understand why you wen't away from full components inheritance. A crude weapon indeed.
However it would be VERY convenient if all elements exposed their style, properties and behaviour as mixins for other elements to build on.
This IS currently possible, so it is only a matter of enhancing existing elements to follow this pattern to allow for better composition.
This would also help to solve the "problem" with the content selector limitation: googlearchive/core-selector#39
Example
paper-scroll-header-panel
You could of course see a behavior as a full set of properties and methods which form a logical unit. Then expose methods and properties as separate mixin units as well. Then allow full inheritance as a convenience, which simply inherits all behaviors and the shared styles exposed by the elements as well.
Provide full flexibility and granular control.
Cheers!
Copied from original issue: googlearchive/polymer-patterns#46
The text was updated successfully, but these errors were encountered: