Skip to content
项目

关于

Svelte (v5.16.6) web framework ported to Dart.

网站与应用开发

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

svelte.dart

Experimenting, work in progress.

Svelte (v5.16.6) web framework (not yet) ported to Dart.

Package Description Version
svelte_ast Parser and utilities for SvelteDart template compiler. Pub Package

Dart port of the Svelte framework with no magic transofrmations.

WIP. EXPERIMENTAL. Third iteration.

<!-- app.svelte -->
<script>
  import 'dart:async';

  import 'package:svelte/svelte.dart';

  var step = prop<int>(1);

  var count = state<int>(0);
  var doubled = derived<int>(() => count() * 2);
  var quadrupled = derived<int>(() => doubled() * 2);

  void handleClick() {
    count.set(count() + step());
  }

  onMount(() {
    var timer = Timer.periodic(const Duration(seconds: 1), (timer) {
      count.increment();
    });

    return () {
      timer.cancel();
    };
  });
</script>

<button onclick={handleClick}>
  Clicked {count()} {count() == 1 ? 'time' : 'times'}
</button>

<p>{count()} * 2 = {doubled()}</p>
<p>{doubled()} * 2 = {quadrupled()}</p>

should be compiled to functional component:

import 'dart:async';

import 'package:svelte/svelte.dart';
import 'package:web/web.dart';

@Svelte()
Node app({Prop<int> step = const .value(1)}) {
  var count = state<int>(0);
  var doubled = derived<int>(() => count() * 2);
  var quadrupled = derived<int>(() => doubled() * 2);

  void handleClick(Event _) {
    count.set(count() + step());
  }

  onMount(() {
    final timer = Timer.periodic(const Duration(seconds: 1), (timer) {
      count.increment();
    });

    return () {
      timer.cancel();
    };
  });

  return Fragment(
    children: <Node>[
      Button(
        onClick: handleClick,
        children: <Node>[
          Text('Clicked ${count()} ${count() == 1 ? 'time' : 'times'}'),
        ],
      ),
      Paragraph(
        children: <Node>[
          Text('${count()} * 2 = ${doubled()}'),
        ],
      ),
      Paragraph(
        children: <Node>[
          Text('${doubled()} * 2 = ${quadrupled()}'),
        ],
      ),
    ],
  );
}

which should be compiled to this:

import 'dart:async';

import 'package:svelte/src/internal.dart' as $;
import 'package:svelte/svelte.dart';
import 'package:web/web.dart';

base class App extends Component {
  static final root = $.template<DocumentFragment>(
    '<button> </button> <p> </p> <p> </p>',
    1,
  );

  App({this.step = const .value(1)});

  Prop<int> step;

  @override
  void call(Node anchor) {
    var count = state<int>(0);
    var doubled = derived<int>(() => count() * 2);
    var quadrupled = derived<int>(() => doubled() * 2);

    void handleClick(Event _) {
      count.set(count() + step());
    }

    onMount(() {
      final timer = Timer.periodic(const Duration(seconds: 1), (timer) {
        count.increment();
      });

      return () {
        timer.cancel();
      };
    });

    var fragment = root();
    var button = $.firstChild<HTMLButtonElement>(fragment);
    var text = $.child<Text>(button);

    $.reset(button);

    var p = $.sibling<HTMLParagraphElement>(button, 2);
    var text1 = $.child<Text>(p);

    $.reset(p);

    var p1 = $.sibling<HTMLParagraphElement>(p, 2);
    var text2 = $.child<Text>(p1);

    $.reset(p1);

    $.templateEffect(() {
      $.setText(text, 'Clicked ${count()} ${count() == 1 ? 'time' : 'times'}');
      $.setText(text1, '${count()} * 2 = ${doubled()}');
      $.setText(text2, '${doubled()} * 2 = ${quadrupled()}');
    });

    $.event('click', button, handleClick);
    $.append(anchor, fragment);
  }
}

Status:

  • Parser
  • Runtime
    • internal 🔥
    • ...
  • DSL
  • Builder/Generator 🔥
    • .svelte > .svelte.dart
    • .svelte.dart > .dart
  • Examples (to test runtime and JS interop., not generated):
    • introduction
    • reactivity
    • props
    • logic
    • events
    • bindings
    • lifecycle 🔥
    • ...
  • ...
  • SSR
    • shelf
    • ...

探索相关项目

加载中…