Giter Site home page Giter Site logo

Comments (7)

drozzy avatar drozzy commented on April 28, 2024

How will this translate to non-execute version? Or will it just stay the same (which is ok I think)?

from commanded.

slashdotdash avatar slashdotdash commented on April 28, 2024

@drozzy Good catch, I think that also needs to change, proposal as below.

Current: Command handler receives default %BankAccount{} state

defmodule OpenAccountHandler do
  @behaviour Commanded.Commands.Handler

  def handle(%BankAccount{} = aggregate, %OpenAccount{account_number: account_number, initial_balance: initial_balance}) do
    BankAccount.open_account(aggregate, account_number, initial_balance)
  end
end

Proposal: Command handler receives no state

When there are no persisted events for the aggregate.

defmodule OpenAccountHandler do
  @behaviour Commanded.Commands.Handler

  def handle(%OpenAccount{account_number: account_number, initial_balance: initial_balance}) do
    BankAccount.open_account(account_number, initial_balance)
  end
end

from commanded.

drozzy avatar drozzy commented on April 28, 2024

Wouldn't that need to percolate down to the apply function?

It presently takes a state. Unless you do:

def apply(%AccountOpened{..}) do
   %InitialStateHere{}
end

from commanded.

slashdotdash avatar slashdotdash commented on April 28, 2024

@drozzy I'm undecided about changing the apply/2 function.

from commanded.

Freyskeyd avatar Freyskeyd commented on April 28, 2024

Is there any update on this issue?

Still undecided? Abandoned ?

from commanded.

pcarvsilva avatar pcarvsilva commented on April 28, 2024

@slashdotdash

I would prefer not using a apply but a create function, since the aggregate does not exists if it is not created.

It does makes more sense to say that a command was processed and created and event and and aggregate, that say that the aggregate already existed with nil fields

It would also help with pattern matching on execute(), if there's no aggregate it should return nil on the execute function and the default call should return {:error, :aggregate_not_created}

from commanded.

yordis avatar yordis commented on April 28, 2024

Prefer something like new or initial_state; otherwise, it would be confusing. Also, some folks are aligned around https://thinkbeforecoding.com/post/2021/12/17/functional-event-sourcing-decider in terms of naming things to some extent.

Being said, since structs allow you to have default values, I am wondering if this should be a feature.

from commanded.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.