Dart examples
This site is an example of different features of the Dart language. I
put it together as an excercise while learning Dart. Dart is not only a
languge, it's a platform and developement tool-chain. Partially the next
evolutionary stage of Google Web Toolkit (GWT), Dart is also meant an
ambitious replacement for JavaScript, the standing Web programming
langauge.
All pages including the home include all kind of features and effects
implemented in Dart. To name few: Hiding sections enhancing usability,
animations dramatizing algorithm inner working and simple toys and easter
eggs. The point of this site is to explore dart and all it's features.
Additionally, the code is meant to be read much as examples are. The code
should is written in a particular style, noticable hrough the axamples.
TODOs:
Notes:
- Dart syntax
-
#symbols
- Symbol class is similar to symbols in Ruby. The syntax allows for
ad-hoc enumaration, which does not suffer from non-extendibility like
Java's enums
function(can, have, {optional, arguments : withDefaulValue}
- Enclose optional function arguments into brackets, default value
may follow after a colon.
static Named.constructors()
- Static functions are also named constructors. Calls to them are
prepended with
new
keyword. The resulting value is a new
object as if using a constructor
Constructior(a, b) : initializers = a, list = b { /*...*/ }
- Final fields have to be initialized before constructor body
executes. This is achieved using constructor initialize, which are put
after semicolon just before constructor body.
@Annotations
-
- Dart has annotations with syntax similar to Java annotations.
- Dart API
-
- Dart has no arrays
- There is Iterable class, Collection extends it. Set, List and Queue
List<T>
methods throws RangeError
- Use add() method to add elements. A list can be indexed only for
reading or setting items, not to add new items.
- Unit testing framework
-
- For writing unit tests, there is the unittest package, which can be
put into dev_dependencies in pubspec.yaml file. Tests are defined using
the test() method taking test name and test function as parameter. The
test() methods are called from main() function and for browser apps the
test script is included into a blank html page, which will be filled with
test results.
- Expectation matchers
- Expectations in tests are modelled similarly to hamcrest matchers in
Java. There's plenty of expectation matchers.
- Test PASS, FAIL and ERROR
- A test can PASS, or FAIL the expectations. Alternativelly, if an
exception is thrown during test execution, the test can result in ERROR.
- Dart libraries
-
- Polymer - reusable HTML components
- Polymer is a dart library, which allows to create custom HTML
tags, with login and markup isolated fromthe rest of application.
Polymer needs to be imported into HTML page and initialized. The HTML
page then can import and reference custom tags. A custom tag has
<template<
and <script<
.
- Polymer -
<template>
tag
- Template tag in a polymner component HTML can include a style tag
and arbitrary HTML tags, whch create the component visual appearence.
- Polymer - template
{{expression}}
- Template tag in a polymner component HTML can include a
<style<
tag
and arbitrary HTML tags, whch create the component visual
appearence.
- Polymer - declarative
on-event=""
handlers
<template>
tag in a polymner component HTML
can include a style tag and arbitrary HTML tags, whch create the
component visual appearence.
- Polymer - script
- The script defines a class annotated with
@CustomTag
.
The annotation takes element name as option. The class may extend
PolymentElement class, override it's methods and provide new methods
and behaviour to the component.
$['selector']
instead of
querySelector()
- Use
$['selector']
to access component DOM