1.2.6 • Published 4 years ago

rimo v1.2.6

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Usage

import { AggregageRoot } from 'rimo'

// Create an aggregate root
class User extends AggregateRoot<{ email: string }> {
  get email() {
    return this.props.email
  }
}

// Define inputs and/or outputs
class CreateUserInput {
  @IsNotEmpty()
  @IsEmail()
  email!: string

  static populate = (data: any) => {
    return Object.assign(new CreateUserInput(), data)
  }
}

// Create a use case
import { CommandHandler, Use } from 'rimo'

class CreateUserCommand implements CommandHandler<CreateUserInput, User> {
  @Use(ValidateCommand)
  async handle(input: CreateUserInput): Promise<User> {
    const user: User = new User(input)
    // persist user, do other stuff
    return user
  }
}

// Keep your use cases clean with the help of middlewares
// to do things like validation
import { Middleware } from 'rimo'

class ValidateCommand implements Middleware<CreateUserInput> {
  async use(event: CreateUserInput) {
    const errors = await validate(event)
    if (errors.length > 0) {
      throw new Error('validation error')
    }
  }
}

// Use the stupid simple, yet powerful, pub/sub mechanism that Rimo
// provides to keep your application components nicely decoupled!
import { AfterCommand, CommandRunner } from 'rimo'

class CreateUserSubscriber {
  @AfterCommand(CreateUserCommand)
  async afterCreateUser(user: User, runner: CommandRunner) {
    // SendWelcomeEmail is another use case
    await runner.run(SendWelcomeEmail, user)
  }
}

Credits

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind are welcome!

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago