Giter Club home page Giter Club logo

misbehave's Introduction

misbehave

Turn Polymer v1 components into behaviors

Build Status

Usage

Misbehave adds a method element.toBehavior() to all Polymer components which exports a behavior definition that can be used to effectively extend a component. The misbehave library should be included as an HTML import after Polymer.

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../misbehave/misbehave.html">
<link rel="import" href="base-component.html">

<script>

  Polymer({

    is: 'ext-component',

    // ext-component now effectively extends the Polymer component base-component
    behaviors: [
      document.createElement('base-component').toBehavior()
    ]

  });

</script>

misbehave's People

Contributors

devinivy avatar

Stargazers

 avatar  avatar Lucas Parzych avatar  avatar Filip avatar Kevin Donahue avatar

Watchers

James Cloos avatar  avatar  avatar

misbehave's Issues

Tests broken in extended components

Here's an example:
extend paper-button using misbehave:

<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../misbehave/misbehave.html">
<link rel="import" href="../paper-button/paper-button.html">

<dom-module id="nd-button">
    <template strip-whitespace>
        <style include="paper-material-shared-styles">
      :host {
        @apply(--layout-inline);
        @apply(--layout-center-center);
        position: relative;
        box-sizing: border-box;
        min-width: 5.14em;
        margin: 0 0.29em;
        background: transparent;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
        -webkit-tap-highlight-color: transparent;
        font: inherit;
        text-transform: uppercase;
        outline-width: 0;
        border-radius: 3px;
        -moz-user-select: none;
        -ms-user-select: none;
        -webkit-user-select: none;
        user-select: none;
        cursor: pointer;
        z-index: 0;
        padding: 0.7em 0.57em;
        @apply(--paper-font-common-base);
        @apply(--paper-button);
      }
      :host([hidden]) {
        display: none !important;
      }
      :host([raised].keyboard-focus) {
        font-weight: bold;
        @apply(--paper-button-raised-keyboard-focus);
      }
      :host(:not([raised]).keyboard-focus) {
        font-weight: bold;
        @apply(--paper-button-flat-keyboard-focus);
      }
      :host([disabled]) {
        background: #eaeaea;
        color: #a8a8a8;
        cursor: auto;
        pointer-events: none;
        @apply(--paper-button-disabled);
      }
      :host([animated]) {
        @apply(--shadow-transition);
      }
      paper-ripple {
        color: var(--paper-button-ink-color);
      }
    </style>
        <content></content>
    </template>

<script>
Polymer({
        is: 'nd-button',

        behaviors: [
            document.createElement('paper-button').toBehavior()
        ]
    });
</script>

</dom-module>

Now copy the paper-button tests from https://github.com/PolymerElements/paper-button/tree/master/test and replace paper-button with nd-button and run the tests.
You'll see the click event test fails with Error: done() called multiple times error.

I see that the keybindings array contains duplicate bindings

Check here:
iron-a11y-keys-behavior/iron-a11y-keys-behavior.html > _onKeyBindingEvent: function(keyBindings, event) - line # 455

Need help fixing this.

Extending custom elements that extend <template>

The toBehavior() method doesn't appear on any element that extends template:

>>> document.createElement("template", "dom-repeat").toBehavior();
TypeError: toBehavior is not a function.

>>> document.createElement("input", "iron-input").toBehavior();
[[Object], [Object]]

Custom elements that extend elements like input or 'div' appear to work fine, and newly defined extensions to template also do not work, suggesting that this is only the template element, though I have not exhaustively tested all non-template elements.

http://jsbin.com/bidamuw/edit?html,console

Enhance behavior tests

I experienced a weird thing, where properties within behaviors were not being used. Make sure we understand if this is misbehave's problem or not.

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.