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

Angular Signal Store #195

Merged
merged 110 commits into from
Jan 27, 2024
Merged

Angular Signal Store #195

merged 110 commits into from
Jan 27, 2024

Conversation

spierala
Copy link
Owner

@spierala spierala commented Jul 3, 2023

See the RFC for more information about the MiniRx Signal Store.

A pre-release version (build from this PR code) has been published on NPM: https://www.npmjs.com/package/@mini-rx/signal-store

This PR also contains a new library: @mini-rx/common: common contains shared code which is used by Signal Store and will be used by the original mini-rx-store in the future. @mini-rx/common will be installed as a dependency of Signal Store.

The Signal Store API is very similar to the original mini-rx-store, these are the main differences:

  • effect functions are renamed to rxEffect (to avoid confusion with the Angular Signal effect function)
  • rxEffect in FeatureStore/ComponentStore supports Signal as trigger (next to Observable and raw value)
  • no setInitialState anymore in FeatureStore/ComponentStore for lazy state initialisation. An initialState is required, which is more inline with native Angular Signals.
  • select methods return Signal instead of Observable
  • connect method was added to FeatureStore/ComponentStore to easily connect the stores with external Signals/Observables
  • setState does not accept an Observable anymore (use connect instead)
  • memoized selectors from createSelector, createFeatureStateSelector use Angular computed internally for memoization. The selector creation functions return a function which takes a Signal and returns a Signal.

You can find more info about the changed APIs in this blogpost: https://dev.to/this-is-angular/minirx-signal-store-for-angular-api-preview-4e16

mini-rx and others added 30 commits May 6, 2023 21:31
@carlos-ds
Copy link
Collaborator

Getting an upstream dependency conflict error when running npm install. Perhaps you'll want to fix this?

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @angular-devkit/[email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/jest
npm ERR!   dev jest@"29.4.3" from the root project
npm ERR!   peer jest@"^29.0.0" from [email protected]
npm ERR!   node_modules/jest-preset-angular
npm ERR!     dev jest-preset-angular@"13.1.1" from the root project
npm ERR!   1 more (ts-jest)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional jest@"^29.5.0" from @angular-devkit/[email protected]
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR!   dev @angular-devkit/build-angular@"16.1.1" from the root project
npm ERR!   peer @angular-devkit/build-angular@">= 14.0.0 < 17.0.0" from @nx/[email protected]
npm ERR!   node_modules/@nx/angular
npm ERR!     @nx/angular@"16.4.0" from the root project
npm ERR!     1 more (@nrwl/angular)
npm ERR!   1 more (jest-preset-angular)
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/jest
npm ERR!   peerOptional jest@"^29.5.0" from @angular-devkit/[email protected]
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"16.1.1" from the root project
npm ERR!     peer @angular-devkit/build-angular@">= 14.0.0 < 17.0.0" from @nx/[email protected]
npm ERR!     node_modules/@nx/angular
npm ERR!       @nx/angular@"16.4.0" from the root project
npm ERR!       1 more (@nrwl/angular)
npm ERR!     1 more (jest-preset-angular)
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

@spierala
Copy link
Owner Author

Getting an upstream dependency conflict error when running npm install. Perhaps you'll want to fix this?

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @angular-devkit/[email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/jest
npm ERR!   dev jest@"29.4.3" from the root project
npm ERR!   peer jest@"^29.0.0" from [email protected]
npm ERR!   node_modules/jest-preset-angular
npm ERR!     dev jest-preset-angular@"13.1.1" from the root project
npm ERR!   1 more (ts-jest)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional jest@"^29.5.0" from @angular-devkit/[email protected]
npm ERR! node_modules/@angular-devkit/build-angular
npm ERR!   dev @angular-devkit/build-angular@"16.1.1" from the root project
npm ERR!   peer @angular-devkit/build-angular@">= 14.0.0 < 17.0.0" from @nx/[email protected]
npm ERR!   node_modules/@nx/angular
npm ERR!     @nx/angular@"16.4.0" from the root project
npm ERR!     1 more (@nrwl/angular)
npm ERR!   1 more (jest-preset-angular)
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/jest
npm ERR!   peerOptional jest@"^29.5.0" from @angular-devkit/[email protected]
npm ERR!   node_modules/@angular-devkit/build-angular
npm ERR!     dev @angular-devkit/build-angular@"16.1.1" from the root project
npm ERR!     peer @angular-devkit/build-angular@">= 14.0.0 < 17.0.0" from @nx/[email protected]
npm ERR!     node_modules/@nx/angular
npm ERR!       @nx/angular@"16.4.0" from the root project
npm ERR!       1 more (@nrwl/angular)
npm ERR!     1 more (jest-preset-angular)
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

@carlos-ds
The repo uses yarn. Thanks for your PR updating the contribution guidelines for yarn!


for (let i = 0; i < reducerKeyLength; i++) {
const key = reducerKeys[i];
const reducer: any = reducers[key];
Copy link
Collaborator

@carlos-ds carlos-ds Jan 5, 2024

Choose a reason for hiding this comment

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

Is there a reason why this is explicitly typed as any ? That seems unnecessary and incorrect, since it is inferred as Reducer<any>

Copy link
Owner Author

Choose a reason for hiding this comment

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

Reducer is indeed better than any.

@@ -0,0 +1,87 @@
import { deepFreeze } from './deep-freeze';

// Created a cool set of unit tests with ChatGPT: https://chat.openai.com/share/f2a078c9-e996-4d4e-8c4c-725ca2e9cafd
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps this comment can be removed?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I prefer to be transparent about copy-pasted stuff from ChatGPT or stack-overflow.

The comment text I adjusted a little bit now.

return 42;
};
expect(() => deepFreeze(fn)).not.toThrow();
// Test that the function object is frozen
Copy link
Collaborator

@carlos-ds carlos-ds Jan 5, 2024

Choose a reason for hiding this comment

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

This comment seems obsolete? Same for the other comments that state 'Test that ... is/are frozen'

Copy link
Owner Author

Choose a reason for hiding this comment

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

I removed two not useful comments. The others have at least a little bit extra information which could be useful.

// Prevent effect to unsubscribe from the actions stream
export function defaultEffectsErrorHandler<T>(
observable$: Observable<T>,
retryAttemptLeft = 10
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think retryAttemptsLeft would be better in a grammatical sense

Copy link
Owner Author

Choose a reason for hiding this comment

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

yes, retryAttemptsLeft it is :)

@spierala spierala merged commit 1dd2e02 into master Jan 27, 2024
1 check passed
@spierala spierala deleted the signal-store branch January 27, 2024 12:09
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.

5 participants