Giter Site home page Giter Site logo

Comments (8)

adrai avatar adrai commented on May 16, 2024

yes, you can pass extra infos via command.meta to the event

from node-cqrs-domain.

vishant-dhandha avatar vishant-dhandha commented on May 16, 2024

Is there any other way to achieve this??
i mean inside domain.defineCommand() i want to use my custom method to append data to event.. here is my code structure..

module.exports = require('cqrs-domain').defineCommand({
    name: 'createNarration', 
    payload: 'payload'
}, function (data, aggregate) {
       require('/path/to/myfile.js').append(data, "createNarration", function(err, res){
        if(err){
           cosnole.log(err);
        }else{
           // Not working :Type Error is generated..
            aggregate.apply('narrationCreated', data);
        }
    });
})

If my code structure is like below, its working fine..

module.exports = require('cqrs-domain').defineCommand({
    name: 'createNarration', 
    payload: 'payload'
}, function (data, aggregate) {
    //Working fine but i want to append info to data..
    aggregate.apply('narrationCreated', data);   
})

But i am using my custom method to fill data before event created. Though data is filled with my custom info but,
The problem here i am facing is after appending data to events ,aggregate.apply can not apply data to event ..
Error is like

 aggregate.apply('narrationCreated', data);
           ^
TypeError: Object #<Object> has no method 'apply'
    at /home/vishant/Documents/cqrs-sample-vishant/domain/domainFiles/masters/narration/commands/createNarration.js:12:23
    at module.exports.append (/home/vishant/BizOs/bizosprojects/commonfeatures/eventdenormalizerservice/utility/commandappenderutil.js:155:13)
    at _asyncMap (/home/vishant/BizOs/bizosprojects/commonfeatures/node_modules/async/lib/async.js:254:17)
    at async.eachSeries.iterate (/home/vishant/BizOs/bizosprojects/commonfeatures/node_modules/async/lib/async.js:157:25)
    at _asyncMap (/home/vishant/BizOs/bizosprojects/commonfeatures/node_modules/async/lib/async.js:251:21)
    at async.series.results (/home/vishant/BizOs/bizosprojects/commonfeatures/node_modules/async/lib/async.js:615:34)
    at module.exports.append.async.series.data.error (/home/vishant/BizOs/bizosprojects/commonfeatures/eventdenormalizerservice/utility/commandappenderutil.js:150:17)
    at async.series.results (/home/vishant/BizOs/bizosprojects/commonfeatures/node_modules/async/lib/async.js:610:21)
    at _asyncMap (/home/vishant/BizOs/bizosprojects/commonfeatures/node_modules/async/lib/async.js:249:17)
    at async.eachSeries.iterate (/home/vishant/BizOs/bizosprojects/commonfeatures/node_modules/async/lib/async.js:149:13)

Process finished with exit code 8

_F.Y.I. aggregate object has all the attribute & methods except 1 that is apply method_

from node-cqrs-domain.

vishant-dhandha avatar vishant-dhandha commented on May 16, 2024

This is what i was trying to say.. I have replicate the issue ..
I have added a custom function to your cqrs-sample project.. Below is my commit to your repo..

vishant-dhandha/cqrs-sample@20a0f24

Here i have added async http call to fetch some info & append to the 'data'..

At aggregate.apply('itemCreated', data); data contains my desired info but some how server stopped with TypeError: Object #Object has no method 'apply'

from node-cqrs-domain.

adrai avatar adrai commented on May 16, 2024

this is not possible... the whole apply part is completely sync...
can't you extend your command before it enters the domain.handle?

from node-cqrs-domain.

vishant-dhandha avatar vishant-dhandha commented on May 16, 2024

I want to make a async call, if that async call successfully returned then and then only the event should be generated.
How could i make out this?

Saga is the solution for that???

from node-cqrs-domain.

adrai avatar adrai commented on May 16, 2024
asynccall(function (err, extenstion) {

  if (!err) {
    command.myExtension = extension;
    domain.handle(command);
  }

});

from node-cqrs-domain.

adrai avatar adrai commented on May 16, 2024

I have an idea:
Would it be ok for you, if you define a precondition for that command in which you make your async requests and save the resulting data in a sort of clipboard on the aggregate and afterwards in de command just get that saved data and extend your event?

from node-cqrs-domain.

vishant-dhandha avatar vishant-dhandha commented on May 16, 2024

Yes , this (precondition) solved my problem..
thank you

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.