Dispatch Utility? #2397
TheWrightDev
started this conversation in
General
Replies: 1 comment
-
|
Hi there
I definitely wouldn't do it as a static property like that. I don't think
that would actually work.
It needs to be constructed as part of the construction of a service or
component so that it has access to the injection context.
I would create it as a private property in your component.
I would also not recommend the facade pattern (if you are trying to follow
that) to abstract this call because it is just extra work for very little
gain.
Kind regards,
Mark
…On Wed, 4 Feb 2026 at 00:20, TheWrightDev ***@***.***> wrote:
I was just hoping to get a little guidance the interesting dispatch
utility <https://www.ngxs.io/concepts/store#dispatch-utility>function?
Are there any important differences to be aware of (performance or
otherwise) when using this when compared to this.store.dispatch()?
Can / Should these be created ahead of time similar to the .query file
pattern and so all actions can quickly be dispatched without importing
store?
e.g.
// example-actions.ts
export namespace ExampleActions {
class Greet {
static readonly type = 'Greet';
constructor(public greeting: string) {}
}
}
// example-actions.util.ts
export class ExampleUtil {
static greet = dispatch(ExampleActions.Greet);
}
// example-component.ts with no store inject.
...
ExampleUtil.greet('Hello World')
...
—
Reply to this email directly, view it on GitHub
<#2397>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAO3U2MGRNBMFAHI6WGYX5L4KENKVAVCNFSM6AAAAACT4EWRYOVHI2DSMVQWIX3LMV43ERDJONRXK43TNFXW4OZZGQZDKMJVGQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I was just hoping to get a little guidance the interesting dispatch utility function?
Are there any important differences to be aware of (performance or otherwise) when using this when compared to
this.store.dispatch()?Can / Should these be created ahead of time similar to the .query file pattern and so all actions can quickly be dispatched without importing
store?e.g.
Beta Was this translation helpful? Give feedback.
All reactions