Coder Social home page Coder Social logo

Comments (8)

solnic avatar solnic commented on June 30, 2024

Hmm I'm wondering whether it'd make sense to add Operation class to dry-transaction. Folks could just do class DoSomething < Dry::Transaction::Operation. WDYT?

from dry-web-roda.

GustavoCaso avatar GustavoCaso commented on June 30, 2024

Sorry to interrupt but what do you mean with Operation are talking about Transaction operations like step, tee, map etc...

from dry-web-roda.

timriley avatar timriley commented on June 30, 2024

@GustavoCaso we're talking about typical "functional objects" here, the kind you build hundreds of when you're making a large app (hence the idea of having the basic functionality provided by a shared superclass). For example

class CreateComment < Some::Shared:Operation
  def call(attrs)
    # ...
  end
end

@solnic nice idea to put it in dry-transaction. The reason I didn't initially consider providing this via a gem was that the notion of what an "operation" is might differ from app to app, so by dry-web-roda generating one for you, it was more of a hint that you should consider it for your own app.

That said, if all we'd be looking to do initially is include those 2 mixins, then it does make sense that this could be a Dry::Transaction::Operation. And that might make adoption of operations/transactions just that little bit easier for people, too.

OK! So if we did that, I still have one question: even if Dry::Transaction::Operation exists, is there still merit in generating something like this in new dry-web-roda apps?

module MyApp
  class Operation < Dry::Transaction::Operation
    # shared logic goes here
  end
end

I guess if the class if going to be empty, maybe not, but perhaps worth having as a placeholder just in case there's some shared behaviour that an app wants to provide?

from dry-web-roda.

GustavoCaso avatar GustavoCaso commented on June 30, 2024

Thanks @timriley for explaining 😄

So if understood correctly Dry::Transaction::Operation will be such an interface to MyApp::Operation adding some shared method across all operations?

from dry-web-roda.

timriley avatar timriley commented on June 30, 2024

@GustavoCaso At this point we're basically just talking about this:

module Dry
  module Transaction
    class Operation
      include Dry::Monads::Either::Mixin
      include Dry::Matcher.for(:call, with: Dry::Matcher::EitherMatcher)
    end
  end
end

😄

from dry-web-roda.

GustavoCaso avatar GustavoCaso commented on June 30, 2024

Nice I got it 👍

from dry-web-roda.

solnic avatar solnic commented on June 30, 2024

OK! So if we did that, I still have one question: even if Dry::Transaction::Operation exists, is there still merit in generating something like this in new dry-web-roda apps?

Yes, I would say it should be a general good practice (just like we do with rom repos), because it gives you a place to inject stuff like loggers, notifiers, integrate with anything that's specific to your app. It also makes it easier to swap implementations for many classes once there's just one abstract class that you own.

from dry-web-roda.

timriley avatar timriley commented on June 30, 2024

Fixed in #45

from dry-web-roda.

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.