Saturday, January 5, 2013

Getting Started with My Own Dart Web Components

‹prev | My Chain | next›

I am back to trying to understand web components in Dart tonight. I pick back up with last night's pubspec.yaml with a dependency on web_ui:
name: scripts
dependencies:
  hipster_mvc: any
  web_ui: any
  unittest: any
Today it works:
➜  app git:(web-components) ✗ pub install
Resolving dependencies...
Downloading web_ui 0.2.10+2...
Downloading logging 0.2.9+7...
Downloading js 0.0.13...
Downloading html5lib 0.2.2+1...
Downloading args 0.2.9+7...
Dependencies installed!
Yesterday's woes were apparently just a result of bad replication on the Dart Pub server. It's definitely working now.

Next, I try to replace the pure Hipster MVC implementation my Dart Comics sample app. Instead, I would like to see if I can figure out web components. I start with the following <element> template in my web page:
<body>
  <element name="x-hipster-collection" constructor="HipsterCollectionComponent" extends="div">
    <template>
      <h2>Template</h2>
      <ul iterate="model in collection">
        <li>{{model['title']}}</li>
      </ul>
    </template>
    <script type="application/dart">
      import 'package:web_ui/web_ui.dart';
      import 'package:scripts/Collections.Comics.dart' as Collections;

      class HipsterCollectionComponent extends WebComponent {
        var collection = new Collections.Comics();

        HipsterCollectionComponent() {
          collection.fetch();
        }
      }
    </script>
  </element>
  <!-- ... -->
</body>
Next I add an x-hipster-collection element and try to kick start it:
  <div is="x-hipster-collection"></div>
  <script type="application/dart">
    main(){}
  </script>
  <script>
    navigator.webkitStartDart();
  </script>
But when I load this up in Dartium, I get an error in the Dart console:
Internal error: Dart_Invoke: did not find top-level function 'main'.
That seems odd, especially since there is quite explicitly a top-level main() function in the HTML. If I remove the webkitStartDart() call, then I get no error, but nothing else happens either.

Eventually, I read the tools article. I install the extension that is listed in that article, then try to compile my application's entry point. Unfortunately, I get a fairly lengthy stacktrace that starts with:
➜  app git:(web-components) ✗ dart --package-root=packages/ packages/web_ui/dwc.dart --out out/ web/index.html
Unhandled exception:
FutureUnhandledException: exception while executing Future
  NoSuchMethodError : method not found: 'add'
  Receiver: null
  Arguments: [" "]
original stack trace:
  #0      Object._noSuchMethod (dart:core-patch:1360:3)
  #1      Object.noSuchMethod (dart:core-patch:1361:25)
  #2      Message.toString (file:///home/chris/repos/dart-comics/app/packages/web_ui/src/messages.dart:47:31)
  #3      print (dart:core-patch:1369:29)
...
Stumped, I call it a night there. Hopefully I can figure out what I am doing wrong tomorrow.


Day #621

No comments:

Post a Comment