如何在一个HTML中执行两个dart代码 [英] How can I execute two dart code in one HTML

查看:156
本文介绍了如何在一个HTML中执行两个dart代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试建立一个Dart应用程序。



这是我想要的过程。



在第一次连接时,用户有一个加载页面。在这段时间,他有一个动画,在后台,大dart文件(来自dart2js dart)。



一旦结束,下载的脚本



感谢您对这个程序的可能性有任何想法吗?





EDIT:

  importdart:async 
@lazy
import'test.dart'as foo;

const lazy = const DeferredLibrary('test');

void main(){
foo.init(); //假定抛出NoSuchMethodError。
lazy.load()。then(onFooLoaded);
}

void onFooLoaded(_){
foo.init();
}

test.dart



< pre class =lang-dart prettyprint-override> 库测试;

void init(){
print(coucou);
}


解决方案

基本上这个功能存在一段时间,但我还没有使用它自己。由于一些开放的问题,这个功能似乎有限的使用。我看到一个通知,即几个错误或缺少的功能已修复,但我不能告诉当前状态。



有关更多信息,请参阅

- < a href =https://api.dartlang.org/apidocs/channels/be/dartdoc-viewer/dart:async.DeferredLibrary =nofollow> https://api.dartlang.org/apidocs/channels/ be dartdoc-viewer / dart:async.DeferredLibrary

- http://blog.sethladd.com/2013/04/lazy-load-libraries-in-dart.html

- https://code.google.com/p/dart/issues/detail?id= 10171
- Dart中的代码拆分

- https://code.google.com/p/dart/issues / detail?id = 3940

- https://code.google.com/p/dart/issues/detail?id=9483



更新



我试过它,它在Chrome(不是在Dartium)中有一些小的改动。



test.dart

  library some_lib_name; //< == missing missing 

void init(){
print(coucou);
}

index.dart



< pre class =lang-dart prettyprint-override> const lazy = const DeferredLibrary('some_lib_name'); //使用库名而不是文件名


I'm trying to build an Dart App.

This is the process that I would like to have.

At the first connection, the user have a loading page. During this time, he has an animation, and in background, the big dart file is downloaded (came from dart2js for dart).

Once it's over, the downloaded script is execute and the app cans start to work.

Any idea about the possibility of this process ?

Thank you. EDIT:

import "dart:async";
@lazy
import 'test.dart' as foo;

const lazy = const DeferredLibrary('test');

void main() {
  foo.init(); // Supposed to throw a NoSuchMethodError.
  lazy.load().then(onFooLoaded);
}

void onFooLoaded(_) {
  foo.init();
}

test.dart

library test;

void init() {
  print("coucou");
}

解决方案

It's called deferred loading. Basically this feature exists a while already but I haven't used it myself yet. Because of some open issues this feature seemed of limited use. I saw a notice that several bugs or missing feature were fixed but I can't tell the current status.

For more information see
- https://api.dartlang.org/apidocs/channels/be/dartdoc-viewer/dart:async.DeferredLibrary
- http://blog.sethladd.com/2013/04/lazy-load-libraries-in-dart.html
- https://code.google.com/p/dart/issues/detail?id=10171 - Code Splitting in Dart
- https://code.google.com/p/dart/issues/detail?id=3940
- https://code.google.com/p/dart/issues/detail?id=9483

Update

I tried it and it works in Chrome (not in Dartium) with a few small changes

test.dart

library some_lib_name; // <== was missing

void init() {
  print("coucou");
}

index.dart

const lazy = const DeferredLibrary('some_lib_name'); // use the library name not the file name

这篇关于如何在一个HTML中执行两个dart代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆