What is the difference between dart: html and dart: dom?

I start with some examples of Darth. Then I wanted to query the DOM with document.query('#someId') , as described here , but there seemed to be no query method in the document. Also, creating a new element using `new Element.tag ('p') does not work.

Then I find out that it will work when I change the imported package from dart:dom to dart:html . But using both of them gives me a bunch of duplicate definition of _XYZ .

So interesting:

  • what's the difference between dart:html and dart:dom package
  • which i should use
  • Why can not I use both
+8
dart package dart-html
source share
4 answers

Updating all answers and probably making this question more inapplicable is that dart: dom is deprecated.

See this post on the dartlang website.

+6
source share

Answers a little out of order

  • Which one should I use : you should use dart:html , it provides the cleanest abstraction on top of the DOM.

  • why I don’t use both : it should not be strictly unnecessary, but you can actually go to the basic dart:dom implementations from dart:html using the dirty hack described here . A better and cleaner solution is to use the Dart ability to rename imports, i.e. #import('dart:dom', prefix: 'dom'); as described by @munificent below.

  • what distinguishes between dart: html and dart: dom package . I tend to think about the difference between the two, like JQuery ( dart:html ) versus JS DOM ( dart:dom ) manipulation.

The Dart team is struggling to make the dart:html API easy and unsurprising (in a good way) to use, because we are used to using libraries such as jQuery (dom manipulation), Tree.js (WebGL programming) and D3 (SVG drawing) . In addition, they also try to adhere to the same API style in all these areas of functionality, so that the SVG or WebGL API uses similar constructs, such as the DOM API, thereby ensuring that all parts are well aligned.

Update : as of May 2012, dart: dom is now deprecated and will be removed.

+10
source share
Lars did a great job with your question. I will just add to:

why can't i use both

You can, really. The problem is that both libraries use the same names for several things (mainly window ). When you import both of these, these names collide that Dart does not allow. To fix this, you can import one of them with a prefix:

 #import('dart:html'); #import('dart:dom', prefix: 'dom'); 

Then, when you reference the name imported from dart:html , you simply use the name. If you need a DOM, you prefix it:

 window // dart:html window dom.window // dart:dom window 
+7
source share

Short answer to add to the excellent answers already received: Use dart: html when you can. Use dart: dom when you should (and enter the error if you need).

0
source share

All Articles