Skip to content
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

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

Closed
jlg7 opened this issue Apr 26, 2015 · 2 comments
Closed

Comments

@jlg7
Copy link

jlg7 commented Apr 26, 2015

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

@kevinpschaaf
Copy link
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.

@jlg7
Copy link
Author

jlg7 commented Apr 28, 2015

@kevinpschaaf - TYVM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants