2013-01-18 69 views
2

最新編輯:何時移除Dart Web組件的生命週期方法?

這是網絡用戶界面的開放式問題:https://github.com/dart-lang/web-ui/issues/245

以前:

我試圖找出如何從web component lifecycle methods得到removed()是調用。仔細查看下面示例中生成的代碼,我看到replaceElement()之後有一個autogenerated.dispatch();的調用,我希望它會調用removed(),但是我沒有看到我的print語句輸出。

也許相關:我瀏覽規範試圖瞭解build.dart輸出爲生命週期方法做了什麼。也許規格已過時?即使composeChildren()在自動生成的代碼build.dart中被調用,我仍然看不到composeChildren()規範(在this web-ui issue comment中提到)的instantiation section中列出的composeChildren()

這個問題背後的原因是我對Dart webapp的興趣,它能夠以編程方式(通過規範中的實例化指令)加載和卸載單個父級HTML文件中的Web組件,而不必在HTML中聲明Web組件。我正在運行web_ui-0.2.11。謝謝!


WebComponent的:

<!DOCTYPE html> 
<html><body> 
<element name="x-lifecycle-test" constructor="LifecycleTest" extends="div"> 
    <template> {{foo}} </template> 
    <script type="application/dart"> 
    import 'dart:html'; 
    import 'package:web_ui/web_ui.dart'; 
    var foo = "testing lifecycle methods"; 
    class LifecycleTest extends WebComponent{ 
     inserted() => print("inserted"); 
     removed() => print("removed"); 
    } 
    </script> 
</element> 
</body></html> 

父HTML文件:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"><title>Lifecycle</title> 
    <link rel="components" href="lifecycle_test.html"> 
    </head> 
    <body> 
    <div> 
     <button on-click="replaceElement()">replace element</button> 
    </div> 
    <div id='holder'> 
     <x-lifecycle-test></x-lifecycle-test> 
    </div> 

    <script type="application/dart"> 
     import 'dart:html'; 
     void replaceElement() { 
     query('#holder').replaceWith(new DivElement() 
             ..id = 'holder' 
             ..text = 'replaced'); 
     } 
     main() {} 
    </script> 
    <script type='text/javascript' src="https://dart.googlecode.com/svn/branches/bleeding_edge/dart/client/dart.js"></script> 
    </body> 
</html> 

回答