Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V4 API for run(), call(), spawn() #912

Open
cowboyd opened this issue Sep 26, 2024 · 2 comments
Open

V4 API for run(), call(), spawn() #912

cowboyd opened this issue Sep 26, 2024 · 2 comments

Comments

@cowboyd
Copy link
Member

cowboyd commented Sep 26, 2024

One of the things happening in v4 is that we're aligning call() to be more similar to Function.prototype.call() This would imply that the signature for call() would be:

call(fn, thisObj, ...args)

The question is 1) is this desirable? and 2) what should we do with the other "call-like" functions in Effection: run() and spawn(). We could align them like this;

// v3
spawn(fn);
run(fn);

//v4?
spawn(fn, thisObj, ...args);
run(fn, thisObj, ...args);

On the one hand, this has a nice alignment with vanilla js, but on the other, it's annoying in that we don't really ever use this. Still, this is supposed to feel like native JS building blocks, so I'm not sure what the best way to go is.

On the other hand, I've been toying with the idea of deprecating scope.run() and replacing it by passing scope as a parameter to run() This would re-enforce the idea that this is an entry point from javascript and something you should do with care.

run(fn, { scope })

Which is better?

@iplaylf2
Copy link

it's annoying in that we don't really ever use this.

Conversely, when using NestJS and Effection together, I often need to use this, which can be quite inconvenient.

import { globalScope } from '..'

@Controller('receiver')
export class ReceiverController {
  @Inject()
  private readonly passport!: Passport
  
  @Inject()
  private readonly pushService!: PushService

  @Delete()
  public [`@Delete()`](): Promise<void> {
    return globalScope.run(function*(this: ReceiverController) {
      const receiver = yield * this.pushService.getClaimerReceiver(this.passport.id)
  
      if (null === receiver) {
        return
      }
  
      yield * this.pushService.deleteReceiver(receiver)
    }.bind(this))
  }
}

@cowboyd
Copy link
Member Author

cowboyd commented Oct 16, 2024

@iplaylf2 Thanks so much for your comment. This is a great data point!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants