Dart in prod

  ngDart 


  

     

   
@bwnyasse

About Me ?


  •  Passionate Agile Developer ! 

  •  DevOps Enthusiast  

  •  Startup Addict 

@bwnyasse

1- What is Dart ?

 

  • 1st Appeared  : GoTo conference Denmark /  Octobre 2011


  • Tool-Friendly Language ( not only for Structured Web Apps )  

  • Object Oriented & Functional Programming Language

  • Dart code : easy to read & fun to learn 

  • ECMA-408 Standard

1-  What is Dart ?


1- What is Dart ? 

 DART CODE  : Quick Overview   ::  Optional Typing   / named Params ...


// Snippet Code @bwnyasse : Dart Meetup - GDG Toulouse

// Define a function.
whatIsYourFavoriteMeetup({name, where: 'AtHome', creationD}) =>
// print with String interpolaion
print("$name is my fav meetup at $where, created the $creationD.");


// Top-level required function
main() {
String meetupName = "GDG Toulouse";

// Without specifying the type
var cDate = new DateTime(2012, DateTime.DECEMBER, 9);

whatIsYourFavoriteMeetup(
name: meetupName,
creationD: cDate
);
}

1- What is Dart ? 

 DART CODE  : Quick Overview    :: Librairies & Visibility



// Snippet Code @bwnyasse : Dart Meetup - GDG Toulouse

import 'dart:html';
import 'package:gdgtoulouse/lib1.dart';
import 'package:gdgtoulouse/lib2.dart' as lib2;
import 'package:gdgtoulouse/lib3.dart' as lib3 hide GDGElement;


// Top-level required function
main() {

GDGElement el1 = new GDGElement(); // GDGElement from lib1.

lib2.GDGElement el2 = new lib2.GDGElement(); // GDGElement from lib2.

// new lib3.GDGElement(); !! ERROR !!
}


1- What is Dart ? 

 DART CODE  : Quick Overview    :: Asynchronous  Async/Await


// Snippet Code @bwnyasse : Dart Meetup - GDG Toulouse

import 'dart:html';

final PATH = 'https://www.dartlang.org/f/dailyNewsDigest.txt';

// Imagine that this function is more complex and slow. :)
gatherNewsReportsIsSlow() async => await HttpRequest.getString(PATH);

printDailyNewsDigestInAsync() async {

try {
String news = await gatherNewsReportsIsSlow();
print(news);
} catch (e) {
// ... handle error ...
}
}

main() => printDailyNewsDigestInAsync();


1- What is Dart ? 

 DART CODE  : Quick Overview   :: Named constructor ... Null Aware .....  

// Snippet Code @bwnyasse :  Dart Meetup - GDG Toulouse

class Element {

var type;

Element();
Element.withType(this.type); // Named constructor

someMethod() => "Something";
}


// Top-level required function
main() {

Element el;

el?.type; // if ( el != null ) el.type
el?.someMethod(); // if ( el != null ) el.someMethod()

el ??= new Element.withType("GDG meetup");; // if ( el == null ) ...

}

1- What is Dart ? 

 DART CODE  : Quick Overview   ::  Collection iteration



// Snippet Code @bwnyasse : Dart Meetup - GDG Toulouse

// Top-level required function
main() {

List myList = [1, 2, 3, 4, 5];

myList.forEach((v) => print(v));

List moduloTwoList = myList.where((v) => v%2 == 0);

print(moduloTwoList);

}

2- State of Dart Lang in 2017


2- State of Dart Lang in 2017

3- what ? .... Angular with DART ?  



    3- Angular with DART !   

    No reason to doubt, with Misko answer ! ( Jan. 2014 )
                 

     ... while rewriting AngularDart we have chose to take advantage of these language features. We have also learned from our mistakes on AngularJS and taken the opportunity to correct them, such as much improved Directive API. Finally we have take advantage of the latest browser technologies and based AngularDart on top of Shadow DOM.

    All of the learnings we have gained in building AngularDart, will be applied back to AngularJS v2. This is only expected since AngularDart is younger than AngularJS.

    ... 

    share edit flag

    from Misko Hevery ( Father of AngularJS)  answer 
    Source: http://stackoverflow.com/questions/21055756/what-is-the-difference-between-angularjs-and-angulardart

    3-  Angular with DART !

      Comparaison in Angular 1 

    <toggle button="Toggle">
    <p>Inside</p>
    </toggle>

    ng-JS ng-Dart

    directive("toggle", function(){
    return {
    restrict: 'E',
    replace: true,
    transclude: true,
    scope: {button: '@'},
    template: "<button...
    controller: function($scope)
    ...
    @Component(
    selector: "toggle",
    publishAs: 'tgl',
    template: "<button ....",
    cssUrl: 'toggle.css'
    )
    class Toggle extends ShadowRoot... {
    @NgAttr("button")
    String button;
    ...

    3- Angular with DART !

      Same Template binding in Angular 2

    with TS
    import { Component } from '@angular/core';

    @Component({
    selector: 'my-fav-meetup',
    template: `<h1>My Fav Meetup is {{name}}</h1>`
    })
    export class FavMeetupComponent {name= 'GDG Toulouse'; }

    with Dart
    import 'package:angular2/core.dart';

    @Component(
    selector: 'my-fav-meetup',
    template: '<h1>My Fav Meetup is {{name}}</h1>')
    class FavMeetupComponent {
    var name = 'GDG Toulouse';
    }

    3- Angular with DART !


    3-  Angular with DART !

    Notable Differences in Angular 2
     LAZY Loading 
    •     TS/JS :   ngModule
    •     Dart :   AsyncRoute, DynamicComponentLoader 

    Browser Fallback
    •     TS/JS :   polyfills 
    •     Dart :    dart:html  

    3rd Party Libraries
  • TS/JS :   zones.js, Rx.js 
  • Dart :    no need ...  
  • 3- what ? .... Angular with DART ? 


    @antonmoiseev ( Book co-author : ' Angular 2 Development with TypeScript ' ) : 

    " I don't urge you to give up developing Angular applications with JavaScript or TypeScript and immediately move to the Dart Side ! Dart isn't perfect and has its own issues . However the development ergonomics and overall experience is something I miss a lot in the JavaScript world. Hopefully the JavaScript ecosystem will be closing the gap overtime and the development will become more productive "

    from  ' Comparing the Upgrade Process of Dart and TypeScript Apps to Angular 2 beta
    Source :  http://antonmoiseev.com/2015/12/22/compare-ts-and-dart-angular2-beta0-upgrades/

    Quick Live DEMO 



    STAGEHAND :   Scallfolding Angular 2 Dart 


    +

     
    PUB :    get , compile ( dart2JS ) + build 

    .... 

    4- So, Dart in Production ?  


    4- So, Dart in Production ?  

      DEMO
    from

    'Official List : Who use dart ' 

     Google Apps /   Pick & School  / SoundTrap

    to 

     ' a simple MIPIH app'

    Castor

    4- So, Dart in Production ?  

      Google AdSense / AdWords / Fiber

    4- So, Dart in Production ?  

      DEMO : 


    4- So, Dart in Production ?  


    5- Interop : Dart <--> Javascript 

     Use  package:js

    name: gdgtoulouse
    description: Snippets Collection displayed during the meetup.
    author: bwnyasse

    environment:
    sdk: '>= 1.13.0 <2.0.0'

    dependencies:
    js: any # This packages requires Dart SDK 1.13.0.

    Basic Example
    import "package:js/js.dart";

    /// An 'external' function : Body is defined somewhere else

    // Calls invoke JavaScript `JSON.stringify(obj)`.
    @JS("JSON.stringify")
    external String stringify(obj);


    5- Interop : Dart <--> Javascript 

     Use   package:js

    Classes & Namespaces Example : 

    @JS('google.maps')
    library maps;

    import "package:js/js.dart";

    // `new LatLng(...)` invokes JavaScript `new google.maps.LatLng(...)`
    @JS("LatLng")
    class LatLng {
    external LatLng(num lat, num lng);
    }

    // `new Map` invokes JavaScript `new google.maps.Map(location)`
    @JS()
    class Map {
    external Map(LatLng location);
    external Location getLocation();
    }

    5- Interop : Dart <--> Javascript 

    Passing ' Functions' to JS with   allowInterop

    // Javascript Cordova FacebookConnectPlugin getLoginStatus API
    facebookConnectPlugin.getLoginStatus(Function success, Function failure)
    Wrapper in Dart

    // Define in Dart
    @JS("facebookConnectPlugin")
    class Facebook {
    external static getLoginStatus(Function success, Function failure);
    }
    Call it 
    Facebook.getLoginStatus(
    allowInterop((success) => print('Success login status: ${success}')),
    allowInterop((fail) => print('Login failure: ${fail}'))
    );

    T5- Interop : Dart <--> Javascript 

    DEMO with LED
    import 'package:chartjs/chartjs.dart';
    ...

    @override
    ngAfterContentInit() async {
    ...
    ctx = (querySelector('#cpu-stats-chart') as CanvasElement).context2D;
    initCpuChart();
    ...
    }

    initCpuChart() {
    LinearChartData data = new LinearChartData(labels: cpuPercentReadData, datasets: <ChartDataSets>[
    new ChartDataSets(
    label: "cpu percent",
    backgroundColor: "rgba(151,187,205,0.5)",
    ...)
    ]);
    ChartConfiguration config = new ChartConfiguration(type: 'line', data: data, options: new ChartOptions(responsive: true));
    Chart cpuChart = new Chart(ctx, config);

    5- Interop : Dart <--> Javascript 

    DEMO with LED
      

    Annex Links

    THANK YOU - QUESTIONS ? 


    GDG Dart

    By Boris-Wilfried Nyasse

    GDG Dart

    • 1,360