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

feat(store): add createActionGroup function #3381

Merged

Conversation

markostanimirovic
Copy link
Member

@markostanimirovic markostanimirovic commented Apr 15, 2022

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Closes #3337

What is the new behavior?

const authApiActions = createActionGroup({
  source: 'Auth API',
  events: {
    'Login Success': props<{ userId: number; token: string }>(),
    'Login Failure': props<{ error: string }>(),
    'Logout Success': emptyProps(),
    'Logout Failure': (error: Error) => ({ error }),
  },
});

authApiActions.loginSuccess({ userId: 10, token: 'ngrx' });
authApiActions.loginFailure({ error: 'Login Failure!' });
authApiActions.logoutSuccess();
authApiActions.logoutFailure(new Error('Logout Failure!'));

Does this PR introduce a breaking change?

[ ] Yes
[x] No

@markostanimirovic markostanimirovic added the WIP Not ready for review label Apr 15, 2022
@netlify
Copy link

netlify bot commented Apr 15, 2022

Deploy Preview for ngrx-io canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit d885389
🔍 Latest deploy log https://app.netlify.com/sites/ngrx-io/deploys/626b136e85eb120009631713

@markostanimirovic markostanimirovic force-pushed the feat/store/action-group branch from 3226f65 to ab015d6 Compare April 15, 2022 12:34
@markostanimirovic markostanimirovic force-pushed the feat/store/action-group branch from ab015d6 to bcc5d2c Compare April 18, 2022 11:24
@markostanimirovic markostanimirovic removed the WIP Not ready for review label Apr 18, 2022
} from '@ngrx/store';
import { TypedAction } from './models';

// Generating API docs for the `createActionGroup` function is solved by moving its types
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was the same bug with generating API docs for the createActionGroup function as there was for the createFeature - template literal types. I moved its types to another file to make API generation work.

@brandonroberts brandonroberts merged commit 2cdecb3 into ngrx:master May 1, 2022
brandonroberts pushed a commit that referenced this pull request May 2, 2022
@Xapuu
Copy link

Xapuu commented Apr 28, 2023

I've been doing a version of this for years on my own in each NGRX project that I've worked on, so I'm beyond happy to find out that this is part of the core lib now 🎉
Just wanted to say thanks for adding this feature.

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

Successfully merging this pull request may close these issues.

4 participants