Coder Social home page Coder Social logo

aqoviaelements / properties-from-ancestor-behavior Goto Github PK

View Code? Open in Web Editor NEW
2.0 9.0 1.0 99 KB

Polymer mixin (behavior) for a web component to take a property value from the closest ancestor that has it

HTML 100.00%
html-elements polymer polymer1 polymer2 polymer-elements web-components

properties-from-ancestor-behavior's People

Contributors

slawomir-brzezinski-at-interxion avatar zlamma avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

zlamma

properties-from-ancestor-behavior's Issues

Add support for different attribute/property name in ancestor

Consider allowing:

PropertiesFromAncestorBehavior({
            language: {
                ancestorPropertyAlias: 'lang',
            },
        })

To allow boilerplate-less integration when some 3rd party behaviors that we want to use in our component impose a different attribute name than our ancestors already provide.

One fine example is HTML language specification. Adding this feature would allow PropertiesFromAncestorBehavior to be used to smoothly marry the HTML's blessed lang attribute/property with the Polymer's blessed AppLocalizeBehavior's language property.

(unless Polymer's component changes the property name - PolymerElements/app-localize-behavior#98)

Add support for receiving a boolean that is initially false (e.g. get notified about <fieldset disabled>)

Suggestion:
Allow to mimic the way native HTML control receive the ubiquitous disabled flag from ancestor <fieldset>:

<fieldset disabled>
    <input type="text" name="some-standard-textbox-control" />
    <select id="some-standard-select-control">...</select>
    <my-crazy-form-control1/>
    <my-crazy-form-control2/>
    <button id="some-standard-button-control" type="submit">Submit</button>
</fieldset>

(all the native controls will be disabled - note we did not have to pass any disabled arguments except for the ancestor).

Currently, receving the ancestor's disabled attribute will only work if the fieldset is disabled from the start (so has the disabled attribute).

To allow this to work where the fieldset initially has no such attribute and dynamically react to disabling inside the web controls, we can allow specifying a selector that allows to find the ancestor to bind:

PropertiesFromAncestorBehavior({
            disabled: {
                type: Boolean,
                ancestorMatches: 'fieldset',
            },
        })

and then listen to attribute changes on that ancestor (using MutationObserver) to receive the change to true.

This would make it easier to create components that match succinctness of the native HTML elements.

Add support for upward data flow - changing the ancestor value by changing the property in descendant

We currently don't need this feature, so it might not get implemented - please react with 'thumbs up' here to give us feedback that you'd like it.

Since, during reading in descendant, we're already abstracting the fact that the property comes from the ancestor, we might as well not require a leaky abstraction to change the value.

This should be relatively easy to implement in web-component ancestors (which already fire 'my-prop1-changed' events), but will be more tricky for native DOM nodes (need to not fall into recursive call; need to respect the serialization rules using serializeValueToAttribute. Maybe we should also set a property, to save on serialization & subsequent deserialization in children.), but this variant might actually be pretty valuable - it would allow creating elements that are very dynamic, while looking like 'pure static HTML' structure (e.g. no JavaScript security concern or Polymer knowledge needed - just put your global app parameters in attributes of outermost elements and your web components inside just look like HTML).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.