Giter Site home page Giter Site logo

Comments (13)

idream3 avatar idream3 commented on September 7, 2024

If we implement an array notation for the signals as I saw at one point you @christianalfoni were tossing about then we can just concat ourselves rather than adding more API.

const $actionGroup = [
  action1,
  action2,
  [action3]
];

controller.signal('somethingHappened', [ someAction, anotherAction ].concat($actionGroup));

from cerebral.

christianalfoni avatar christianalfoni commented on September 7, 2024

Haha, that is just brilliant :D

from cerebral.

christianalfoni avatar christianalfoni commented on September 7, 2024

I will keep this open until it is documented ;-)

from cerebral.

christianalfoni avatar christianalfoni commented on September 7, 2024

that reminds me that we should support having an array at "top level" too. So:

controller.signal('somethingHappened', someAction, anotherAction);
// is the same as
controller.signal('somethingHappened', [ someAction, anotherAction ]);

from cerebral.

idream3 avatar idream3 commented on September 7, 2024

Another feature ticket perhaps :)

from cerebral.

christianalfoni avatar christianalfoni commented on September 7, 2024

Changed this issue instead... though, hm, I think we have to require the top level to be an array. Because:

controller.signal('somethingHappened', [asyncAction]);
controller.signal('somethingHappened', [syncAction].concat(otherActions));

They are not compatible... so yeah, that will break the API. But again, a quick fix and easy to throw error on it.

Cause it have to be:

controller.signal('somethingHappened', [ [asyncAction] ]);
controller.signal('somethingHappened', [syncAction].concat(otherActions));

from cerebral.

idream3 avatar idream3 commented on September 7, 2024

I see what you mean. Hmm, could start to look messy. I wonder if other people have suggestions...

from cerebral.

christianalfoni avatar christianalfoni commented on September 7, 2024

Yeah, lets keep it open and await more feedback. But signals are most commonly typed like this:

controller.signal('somethingHappened', [ 
  [asyncAction] 
]);

controller.signal('somethingHappened', [
  syncAction
].concat(otherActions));

So it is not that bad ;-)

from cerebral.

idream3 avatar idream3 commented on September 7, 2024

Ahh yes, the new line provides the visual separation :)

from cerebral.

garth avatar garth commented on September 7, 2024

If top level actions must be provided as an array then why not accept multiple arrays without the need for concat()?

controller.signal('somethingHappened', [ 
  [asyncAction] 
], otherActionsArray);

controller.signal('somethingHappened', [
  syncAction
], otherActionsArray);

Just need to enforce that all arguments must be arrays.

from cerebral.

christianalfoni avatar christianalfoni commented on September 7, 2024

Jup, that I was also thinking about that. In that scenario it makes sense just to add it as a second argument, but:

controller.signal('somethingHappened', [ 
  [asyncAction, {
    [SUCCESS]: [mySpecialAction].concat(otherSuccessActions)
  }]
], otherActionsArray);

So yeah, lets change to multiple arrays instead of multiple functions as arguments to the signal?

from cerebral.

idream3 avatar idream3 commented on September 7, 2024

Can we use the ES6 spread operator for this perhaps?

const otherActions = [
   action,
  otherAction
];

controller.signal('somethingHappened', [firstAction, ...otherActions] );

Example above:

controller.signal('somethingHappened', [ 
  [asyncAction, {
    [SUCCESS]: [mySpecialAction, ...otherSuccessActions]
  }],
...otherActionsArray ]);

Second example: http://odetocode.com/blogs/scott/archive/2014/09/02/features-of-es6-part-5-the-spread.aspx

from cerebral.

christianalfoni avatar christianalfoni commented on September 7, 2024

Of course we can, haha, I have not got this new syntax into my intuition system yet ;-)

So we do not need top level array at all, you can use spread for arguments too

controller.signal('somethingHappened', controller.signal('somethingHappened', 
  firstAction, 
  ...otherActions
);

Let me update the other issue with this, and close this one. #46

from cerebral.

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.