All Projects → ReginFell → dart-sealed

ReginFell / dart-sealed

Licence: Apache-2.0 License
Codegen implementation for using with sealed annotation

Programming Languages

dart
5743 projects
objective c
16641 projects - #2 most used programming language
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to dart-sealed

vertx-codegen
Vert.x code generator for asynchronous polyglot APIs
Stars: ✭ 95 (+331.82%)
Mutual labels:  codegen
easybundler
A code generator for Android Bundles
Stars: ✭ 53 (+140.91%)
Mutual labels:  codegen
graphql-codegen-vscode
vscode extension which runs graphql-codegen whenever you save a query/mutation
Stars: ✭ 41 (+86.36%)
Mutual labels:  codegen
go2dts
A simple cli-tools to transform golang `struct` and `const` to typescript `interface` and `type`
Stars: ✭ 44 (+100%)
Mutual labels:  codegen
CQRSAzure
CQRS on Windows Azure
Stars: ✭ 25 (+13.64%)
Mutual labels:  codegen
micronaut-openapi-codegen
OpenAPI codegen for Micronaut
Stars: ✭ 26 (+18.18%)
Mutual labels:  codegen
react-native-xaml
A React Native Windows library to use XAML / WinUI controls
Stars: ✭ 55 (+150%)
Mutual labels:  codegen
codegen-ace
디미고 이과반 입학과제 코드젠 도우미📓
Stars: ✭ 16 (-27.27%)
Mutual labels:  codegen
genqlient
a truly type-safe Go GraphQL client
Stars: ✭ 532 (+2318.18%)
Mutual labels:  codegen
impast
A library for package AST importing
Stars: ✭ 26 (+18.18%)
Mutual labels:  codegen
UmaSupporter.WebClient
🏃🏽‍♀️ 우마무스메 육성 도우미 '우마서포터'의 프론트엔드 애플리케이션입니다.
Stars: ✭ 14 (-36.36%)
Mutual labels:  codegen
atbuild
Use JavaScript to generate JavaScript
Stars: ✭ 26 (+18.18%)
Mutual labels:  codegen
vtprotobuf
A Protocol Buffers compiler that generates optimized marshaling & unmarshaling Go code for ProtoBuf APIv2
Stars: ✭ 418 (+1800%)
Mutual labels:  codegen
revgen
Speed up go:generate by auto detecting code changes
Stars: ✭ 20 (-9.09%)
Mutual labels:  codegen
next-ts-graphql-apollo-starter
An opiniated Next powered starter which include support for Apollo with GraphQL SSR support, codegen, styled component / system, framer motion and Cypress
Stars: ✭ 18 (-18.18%)
Mutual labels:  codegen
apollo-typed-documents
Get type safety for your apollo documents.
Stars: ✭ 21 (-4.55%)
Mutual labels:  codegen
CreateAPI
Delightful code generator for OpenAPI specs
Stars: ✭ 176 (+700%)
Mutual labels:  codegen
idris-codegen-wasm
WebAssembly Code Generation Backend for Idris Compiler
Stars: ✭ 79 (+259.09%)
Mutual labels:  codegen
contentful-typescript-codegen
Generate TypeScript interfaces from a Contentful environment
Stars: ✭ 164 (+645.45%)
Mutual labels:  codegen
hwt
VHDL/Verilog/SystemC code generator, simulator API written in python/c++
Stars: ✭ 145 (+559.09%)
Mutual labels:  codegen

ᶘ ᵒᴥᵒᶅ

SealedCodegen - 'when' operator generator for @sealed classes

Getting started

  1. Add these dependencies
dev_dependencies:
  build_runner: ^1.0.0
  sealed_generator: 1.0.1
  1. Mark any class you want with @sealed annotation (meta: ^1.1.7) and add part '.g.dart' to the header of you file
import 'package:meta/meta.dart';

part 'result.g.dart';

@sealed
class Result<T> with SealedResult<T> {}

class Success<T> extends Result<T> {
  T value;

  Success(this.value);
}
  1. run:
flutter packages pub run build_runner build

Generator will create a class OriginalClassNameSealed for you to use

class SealedResult<T> {
  R when<R>({
      @required R Function(Success<T>) success,
      @required R Function(Failure<T>) failure,
    }) {
    if (this is Success<T>) {
      return success(this as Success<T>);
    }
    if (this is Failure<T>) {
      return failure(this as Failure<T>);
    }
    throw new Exception(
        'If you got here, probably you forgot to regenerate the classes? Try running flutter packages pub run build_runner build');
  }
}
  1. Add with(or extends) to your sealed class, for e.g. class Result extends(with) ResultSealed

Using

Just create an instance of you sealed class and call when on it, for example:

    var resultWidget = result.when(
        success: (event) => Text(event.value),
        failure: (event) => Text("Failure"),
        idle: (event) => Text("idle"),
      );

And that's it, you are ready to use sealed classses with some sort of when

It is a very early version of the library, mostly a proof of concept, so contributions are highly welcomed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].