Skip to content

error using mixins as computed property or in template methods in 0.8.0-rc.7 #1456

Description

@jlg7

Hi,

What is the official determination of using mixins as computed property or template methods? This sample was working early on in 0.8-preview:

<link rel="import" href="bower_components/polymer/polymer.html">
<link rel="import" href="sample-element-mixin.html">

<dom-module id="sample-element">
  <link rel="stylesheet" type="css" href="sample-element.css">
  <template>
    <div>
      <section hidden$="{{hideApp}}">
        <div hidden$="{{!isChromeRuntime}}">
            <h1>Configuration</h1>
            <div>Hide App:</div><span>{{config.showDefaults.hideApp}}</span>
        </div>
      </section>
  </template>
</dom-module>
<script>
    Polymer({

      mixins:[SampleElementMixin],

      is:'sample-element',

      properties:{

        config:{
          type:Object,
          value:function(){ return {"showDefaults":{
            "hideApp":true
          }};}
        },
        hideApp:{
          type:Boolean,
          value:false
        },
        isChromeRuntime:{
          type:Boolean,
          computed:'computeIsChromeRuntime(config)',
          observer:'isChromeRuntimeChanged'
        }
      },
      created:function(){
        if(this._data)
          console.log("created",this.isChromeRuntime);
      },
      ready:function(){
        console.log("ready",this.isChromeRuntime);
      },
      attached:function(){
        console.log("attached",this.isChromeRuntime);
      },
      isChromeRuntimeChanged:function(val){
          console.log("changed",val);
      }
    });
</script>

....

<script>
  SampleElementMixin={

    computeIsChromeRuntime:function(config){
      return "chrome" in window && "runtime" in window.chrome;
    }

  }
</script>

In 0.8.0-rc.7, it does not seem that the mixin methods are available when the properties are computed, I am seeing errors like so:

screenshot 2015-04-26 at 15 47 49

Activity

  1. kevinpschaaf commented on Apr 28, 2015

    @kevinpschaaf
    Member

    In v0.8.0-rc.7, the mixin feature was deprecated and replaced by the more powerful behaviors feature.
    https://github.com/Polymer/polymer/blob/v0.8.0-rc.7/PRIMER.md#behaviors

    mixins are a subset of behaviors, so you can basically just rename your mixins block to behaviors.

    You are correct in that behaviors can supply computing functions for computed properties or inline computed functions in templates. With the added functionality of behaviors, they can also define properties that will be added to the prototype.

  2. jlg7 commented on Apr 28, 2015

    @jlg7
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions