Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/Kraken Bundle #866

Merged
merged 48 commits into from Dec 7, 2021
Merged

Feat/Kraken Bundle #866

merged 48 commits into from Dec 7, 2021

Conversation

answershuto
Copy link
Member

@answershuto answershuto commented Nov 10, 2021

  • 处理 window.open 等跳转问题
  • 重构 load 传参接口设计以及逻辑,保证有 url(或 path),保证 parseURL 等处理没问题。
  • history 与 bundleURL 重复设计问题是,所有历史页面(url 以及 bundleContent 等)都放到 history 中统一管理。
  • 重构 KrakenBundle 逻辑,提供开发者自定义传入 bundle 用以初始化,以代替原本 content 或者 url 等传参,Bundle 初始化不依赖上下文,可以通过 url、path 或者 js context 等初始化,resolve 处理加载等逻辑时再传递上下文,bundle 可以在任意上下文中执行,eval 执行 js 或者 html。URIParser 统一在基类的 resolve 中处理掉。
  • bundle resove 基类统一处理 parseURL。
  • 增加 assets 协议。

API:

Kraken({
  bundle: KrakenBundle.fromHref('http://127.0.0.1:3300/kraken_debug_server.js'),
})

close #861

@answershuto answershuto changed the title [WIP]Fix/window open Fix/window open Nov 16, 2021
@wssgcg1213
Copy link
Member

fromURL 会比 fromHref 好一点

@wssgcg1213
Copy link
Member

href 是 Hypertext Reference 的简写

@answershuto
Copy link
Member Author

answershuto commented Nov 23, 2021

assets 跟 url 放一起了,未来还会有 file(如果有) 等,统一当作 href 处理,内部根据协议再去判断,而不是传入的时候区分好,因为比如 src="xxxxxxx" 的情况是直接new bundle 的。 @wssgcg1213

@@ -82,7 +83,7 @@ void main() async {
var kraken = krakenMap[i] = Kraken(
viewportWidth: 360,
viewportHeight: 640,
bundleContent: 'console.log("Starting integration tests...")',
bundle: KrakenBundle.fromWithContent('console.log("Starting integration tests...")'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fromWithContent 应该是 fromContent

@@ -226,34 +217,66 @@ class Kraken extends StatefulWidget {
defineElement(tagName.toUpperCase(), creator);
}

loadHref(KrakenBundle bundle) async {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不对呀,

void loadBundle(KrakenBundle bundle)

: super(url) {
this.content = content;
}

RawBundle.fromByteCode(Uint8List byteCode, Uri url) : super(url) {
RawBundle.fromByteCode(Uint8List byteCode, String url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fromBytecode 吧,
image
这个单词不是个组合词, 之前的用法就有问题

@@ -192,6 +207,11 @@ class NetworkAssetBundle extends AssetBundle {
Future<ByteData> load(String key) async {
final HttpClientRequest request = await httpClient.getUrl(_urlFromKey(key));
request.headers.set('Accept', getAcceptHeader());
if (additionalHttpHeaders != null) {
additionalHttpHeaders?.forEach((key, value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additionalHttpHeaders?.forEach(request.headers.set);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 ?. 多余了, 跟前面的判空是一个逻辑

: super(url);

Map<String, String>? additionalHttpHeaders = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有其他人用, 这个可以私有的

@@ -622,27 +631,45 @@ class KrakenController {
historyModule.href = value;
}

set bundleContent(String? value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bundle 已经抽象掉了, 应该 set bundle(KrakenBundle bundle);

bundle = KrakenBundle.fromWithContent(bundleContent, url: bundleURL);
} else {
bundle = KrakenBundle.fromUrl(bundleURL);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你看这里的一堆判断就很恶心了, 抽象成 bundle 的目的就是消灭这些判断的, 直接 load bundle 就行了


import 'package:kraken/dom.dart';
import 'package:kraken/kraken.dart';
import 'package:kraken/module.dart';

class HistoryItem {
HistoryItem(this.href, this.state, this.needJump);
HistoryItem(this.href, this.state, this.needJump, { this.bundleContent, this.bundleByteCode });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.bundle


Uri targetUri = Uri.parse(targetUrl);
Uri? sourceUri = sourceUrl != null ? Uri.parse(sourceUrl) : null;
Uri sourceUri = Uri.parse(sourceUrl);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

@@ -22,6 +23,7 @@ void launch({
String? bundleURL,
String? bundlePath,
String? bundleContent,
Uint8List? bundleByteCode,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1

@answershuto answershuto merged commit f95b2e7 into main Dec 7, 2021
@answershuto answershuto deleted the fix/window_open branch December 7, 2021 02:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

跳转功能失效
4 participants