2015-09-03 30 views
6

debugging Polymer 0.5的主要網站上的信息已過時,並且不適用於聚合物1.0如何調試Polymer project 1.x?

我想看到一些日誌,讓我做什麼:

<script> 
    window.Platform = {flags: {debug: true, log: 'bind,ready'}};  
</script> 
<script src="/node_modules/webcomponents.js/webcomponents.js" debug></script> 
<link rel="import" href="..."> 

進口內部:

<link rel="import" href="./bower_components/polymer/polymer.html"> 
<dom-module id="my-custom-element">...</dom-module> 

點擊的網址:http://localhost:8080/index.html?debug&log=bind,ready,events
最後我在控制檯上看不到任何日誌。

什麼是調試聚合物1.0的正確方法

回答

7

如果調試性質(例如數據綁定),然後讀取properties guide,並利用observers場。這裏有一個例子:

Polymer({ 
    is: 'portfolios-foobar', 

    properties: { 
    portfolios: { 
     type: Array, 
     value: [], 
     notify: true, 
     reflectToAttribute: true, 
     observer: 'logChange' 
    } 
    }, 
    logChange: function(newValue, oldValue) { 
    console.log('Changed! To:', newValue); 
    }, 

    addFolio: function(folio) { 
     this.push('portfolios', folio); 
    }, 

    observers: [ 
    'logFor(portfolios)', 
    'hackyObserver1(portfolios.*)', 
    'hackyObserver2(portfolios.splices)' 
    ], 

    logFor: function(newValue, oldValue) { 
    console.log('LogFor! To:', newValue); 
    }, 
    hackyObserver1: function(changes) { 
    console.log('One!', changes); 
    }, 
    hackyObserver2: function(changeRecord) { 
    console.log('Two! Splices!', changeRecord); 
    } 
}); 

而且聯聚合物後,你可以這樣做:

Polymer.log = console.log.bind(console); // Not part of the public API, may be broken. 

這將記錄被註冊的元素名稱。

相關問題