Using dart to create a javascript library

后端 未结 2 1271
感情败类
感情败类 2021-01-13 13:22

The problem

I\'m currently working on a JavaScript library, and in order to reduce the amount of bugs I thought that my library might benefit from using Dart\'s sta

2条回答
  •  半阙折子戏
    2021-01-13 13:57

    Wrap dart class into custom element, the Dart object auto expose to javascript. Assume we have 2 Dart Classes, SlickGrid Class contains Column class in Dart

    class SlickGrid{
       List columns;
    }
    
    class Column{}
    
    class GridWrap extends HtmlElement {
          ShadowRoot shadowRoot;
          SlickGrid grid;  // here is your cool object
    }
    

    compile to javascript, and register custom element, then open javascript console,

    //this is SlickGrid object
    var grid= document.querySelector('cj-grid').grid; 
    // this is dart Column Object
    var column = grid.columns.$index(0,0);  
    // call toString function in dart object that produce json string...
    column.toString$0()  
    

提交回复
热议问题