Code Monkey home page Code Monkey logo

Comments (5)

adrai avatar adrai commented on May 26, 2024

to have a normal event you have to handle it in the cmd handle section: https://github.com/adrai/node-cqrs-domain#command

from node-cqrs-domain.

sbiaudet avatar sbiaudet commented on May 26, 2024

Yes I know the normal way ;)

If you have business rules defined and a business rules fail on a command, the command is rejected without applying events and it's normal. But in my process I want applying business rules in async and only check if aggregate is valid or not. Even if it is not valid I want applying events.

Perhaps we could have an implementation like that :


module.exports = require('cqrs-domain').defineBusinessRule({
  // optional, default is file name without extension
  name: 'nameEquality',

  // optional
  description: 'firstname should never be equal lastname',

  // optional, default is false
  async: true,

  // optional, default Infinity, all business rules will be sorted by this value
  priority: 1
}, function (){ });


module.exports = require('cqrs-domain').defineCommand({
  // optional, default is file name without extension
  name: 'enterNewPerson',

  // optional, default 0
  version: 1,

  // optional, default false
  asyncBusinessRules: true,

  // optional, if not defined it will use what is defined as default in aggregate or pass the whole command
  payload: 'payload'
}, function (data, aggregate) { });

domain.onBusinessRulesError(function (aggregate, callback) {
  bus.emit('businnessRulesError', aggregate.BusinesRulesError[0], function ack () {
    callback();
  });
});

from node-cqrs-domain.

adrai avatar adrai commented on May 26, 2024

right now the business rules can be async (no problem) but on error applying the events smells wrong... :-(

from node-cqrs-domain.

sbiaudet avatar sbiaudet commented on May 26, 2024

I understand, but it's like CQRS paradigm. You accept a delay between command and view-builders because in distributed environnement, data presented to the user is potentially obsolete.

With complex business rule sometimes you could apply it in background and notify after your user that something is wrong. You UI can be faster and more fluid. User can enter lot of data in one time ("power typed") and after he solve errors in invalidated aggregate.

from node-cqrs-domain.

adrai avatar adrai commented on May 26, 2024

Why not using sagas instead?

from node-cqrs-domain.

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.