Skip to content

Commit

Permalink
feat!: got most parts of code generation working; generating shitty code
Browse files Browse the repository at this point in the history
  • Loading branch information
wxxedu committed Feb 22, 2024
1 parent f26799c commit 8803bd4
Show file tree
Hide file tree
Showing 12 changed files with 592 additions and 197 deletions.
4 changes: 2 additions & 2 deletions example/integration_test/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class Something {
@Serializable(StringSerializer())
final AtomOption<String> atomTwo;

final Link<Trivial> linkOne;
final Ln<Trivial> linkOne;

final LinkOption<Trivial> linkTwo;

final Multilinks<Something> linkThree;

@Backlink('linkThree')
@Ln('linkThree')
final Backlinks<Something> backlink;

@Transient()
Expand Down
2 changes: 1 addition & 1 deletion example/integration_test/integration_test.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generator/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Flutter dust generator

Code generator for the Dart side of dust.
Code generator for the Dart side of dust.open
14 changes: 14 additions & 0 deletions generator/example/lib/example.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:dust/dust.dart';

part 'example.dust.dart';

@Model()
class Todo with _$Todo {
Todo._();

factory Todo({
required String title,
String? description,
@Dft(false) bool completed,
}) = _Todo;
}
4 changes: 1 addition & 3 deletions generator/example/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import 'package:dust/dust.dart';
part 'example.dust.dart';

@Model()
class Todo with _$Todo {
abstract class Todo with _$Todo {
Todo._();

factory Todo({
required String title,
String? description,
@DustDft(false) bool completed,
}) = _Todo;
}
86 changes: 86 additions & 0 deletions generator/example/lib/example.dust.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// GENERATED CODE - DO NOT MODIFY BY HAND.dust

part of 'example.dart';

// **************************************************************************
// DustGenerator
// **************************************************************************

mixin _$Todo {
$TodoRepository get $repository => const $TodoRepository();

Atom<String> get title$ => throw UnimplementedError();
String get title => title$.get(null);
set title(String value) => title$.set(value);

AtomOption<String> get description$ => throw UnimplementedError();
String? get description => description$.get(null);
set description(String? value) => description$.set(value);

Atom<bool> get completed$ => throw UnimplementedError();
bool get completed => completed$.get(null);
set completed(bool value) => completed$.set(value);
}

class _Todo extends Todo {
_Todo._(this.title$, this.description$, this.completed$) : super._();

factory _Todo({
required String title,
String? description,
bool completed = false,
}) =>
$TodoRepository().create() as _Todo;

@override
final Atom<String> title$;

@override
final AtomOption<String> description$;

@override
final Atom<bool> completed$;
}

class $TodoRepository implements Repository<Todo> {
const $TodoRepository();

static bool $init = false;

Todo create() {
final id = Dust.instance.randomId();
final node = get(id);
$write(id);
return node.get(null)!;
}

void $write(Id id) {}

@override
void delete(Todo model) {
// TODO: implement delete
}

@override
NodeOption<Todo> get(Id id) {
// TODO: implement get
throw UnimplementedError();
}

@override
Id id(Todo model) {
// TODO: implement id
throw UnimplementedError();
}

@override
Schema init() {
$init = true;
return const Schema(
stickyNodes: [],
stickyAtoms: [],
stickyEdges: [],
acyclicEdges: [],
);
}
}
145 changes: 97 additions & 48 deletions generator/example/lib/example.dust.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion generator/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
path: ../../

dev_dependencies:
lints: ^2.1.0
lints: ^3.0.0
test: ^1.24.0
dust_generator:
path: ../
Expand Down
Loading

0 comments on commit 8803bd4

Please sign in to comment.