draft 0.0.2 copy "draft: ^0.0.2" to clipboard
draft: ^0.0.2 copied to clipboard

Immer, but for dart. Convert between immutable and mutable objects.

Draft #

Immer, but for dart. Convert between immutable and mutable objects.

⚠️ This package is in its early stages and the API will change.

Usage #

Draft is inspired by immer.

import 'package:draft_annotation/draft_annotation.dart';

part 'example.draft.dart';

@draft
class Foo {
  final int value;

  const Foo({
    required this.value,
  });
}

void main() {
  final foo1 = Foo(value: 1);

  // Use the produce method
  final foo2 = foo1.produce((draft) {
    draft.value += 1;
  });
  assert(foo2.value == 2);

  // Or create drafts inline
  final fooDraft = foo.draft();
  fooDraft.value = 10;
  final foo3 = fooDraft.save();
  assert(foo3.value == 10);
}

See the examples directory for more info.

Set up #

First install draft and build runner, if you haven't already.

dart pub add dev:build_runner dev:draft draft_annotation

Next define your drafts.

// example.dart

import 'package:draft_annotation/draft_annotation.dart';

part 'example.draft.dart';

@draft
class Foo {
  final int value;

  const Foo({
    required this.value,
  });
}

Then run the build runner.

dart run build_runner build --delete-conflicting-outputs
0
likes
0
points
40
downloads

Publisher

verified publisherjosiahsaunders.com

Weekly Downloads

Immer, but for dart. Convert between immutable and mutable objects.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, build, draft_annotation, source_gen

More

Packages that depend on draft