Skip to content

Commit 5639c1e

Browse files
feat(store): add provideStore and provideState functions for standalone APIs (#3539)
Closes #3526
1 parent 63df014 commit 5639c1e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1116
-226
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ jobs:
172172
- write_master_hash
173173
- run:
174174
name: Run Affected E2E Tests
175-
command: yarn nx affected --target=e2e --base=$(cat ~/project/master.txt) --head=$CIRCLE_SHA1 --parallel --exclude=docs-app
175+
command: yarn nx affected --target=e2e --base=$(cat ~/project/master.txt) --head=$CIRCLE_SHA1 --parallel=1 --exclude=docs-app
176176

177177
deploy:
178178
<<: *run_in_node

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,5 @@ example-dist/
7575
*.tgz
7676
modules/*/schematics-core/testing
7777
!modules/schematics-core/testing
78+
79+
.angular

angular.json

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,127 @@
798798
"schematics": {},
799799
"tags": []
800800
},
801+
"standalone-app": {
802+
"projectType": "application",
803+
"root": "projects/standalone-app",
804+
"sourceRoot": "projects/standalone-app/src",
805+
"prefix": "ngrx",
806+
"architect": {
807+
"build": {
808+
"builder": "@angular-devkit/build-angular:browser",
809+
"outputs": ["{options.outputPath}"],
810+
"options": {
811+
"outputPath": "dist/projects/standalone-app",
812+
"index": "projects/standalone-app/src/index.html",
813+
"main": "projects/standalone-app/src/main.ts",
814+
"polyfills": "projects/standalone-app/src/polyfills.ts",
815+
"tsConfig": "projects/standalone-app/tsconfig.app.json",
816+
"assets": [
817+
"projects/standalone-app/src/favicon.ico",
818+
"projects/standalone-app/src/assets"
819+
],
820+
"styles": ["projects/standalone-app/src/styles.css"],
821+
"scripts": []
822+
},
823+
"configurations": {
824+
"production": {
825+
"budgets": [
826+
{
827+
"type": "initial",
828+
"maximumWarning": "500kb",
829+
"maximumError": "1mb"
830+
},
831+
{
832+
"type": "anyComponentStyle",
833+
"maximumWarning": "2kb",
834+
"maximumError": "4kb"
835+
}
836+
],
837+
"fileReplacements": [
838+
{
839+
"replace": "projects/standalone-app/src/environments/environment.ts",
840+
"with": "projects/standalone-app/src/environments/environment.prod.ts"
841+
}
842+
],
843+
"outputHashing": "all"
844+
},
845+
"development": {
846+
"buildOptimizer": false,
847+
"optimization": false,
848+
"vendorChunk": true,
849+
"extractLicenses": false,
850+
"sourceMap": true,
851+
"namedChunks": true
852+
}
853+
},
854+
"defaultConfiguration": "production"
855+
},
856+
"serve": {
857+
"builder": "@angular-devkit/build-angular:dev-server",
858+
"configurations": {
859+
"production": {
860+
"browserTarget": "standalone-app:build:production"
861+
},
862+
"development": {
863+
"browserTarget": "standalone-app:build:development"
864+
}
865+
},
866+
"defaultConfiguration": "development"
867+
},
868+
"extract-i18n": {
869+
"builder": "@angular-devkit/build-angular:extract-i18n",
870+
"options": {
871+
"browserTarget": "standalone-app:build"
872+
}
873+
},
874+
"lint": {
875+
"builder": "@nrwl/linter:eslint",
876+
"options": {
877+
"lintFilePatterns": [
878+
"projects/standalone-app/**/*.ts",
879+
"projects/standalone-app/**/*.html"
880+
]
881+
}
882+
},
883+
"test": {
884+
"builder": "@nrwl/jest:jest",
885+
"outputs": ["coverage/projects/standalone-app"],
886+
"options": {
887+
"jestConfig": "projects/standalone-app/jest.config.ts",
888+
"passWithNoTests": true
889+
}
890+
}
891+
},
892+
"tags": []
893+
},
894+
"standalone-app-e2e": {
895+
"root": "projects/standalone-app-e2e",
896+
"sourceRoot": "projects/standalone-app-e2e/src",
897+
"projectType": "application",
898+
"architect": {
899+
"e2e": {
900+
"builder": "@nrwl/cypress:cypress",
901+
"options": {
902+
"cypressConfig": "projects/standalone-app-e2e/cypress.json",
903+
"devServerTarget": "standalone-app:serve:development"
904+
},
905+
"configurations": {
906+
"production": {
907+
"devServerTarget": "standalone-app:serve:production"
908+
}
909+
}
910+
},
911+
"lint": {
912+
"builder": "@nrwl/linter:eslint",
913+
"outputs": ["{options.outputFile}"],
914+
"options": {
915+
"lintFilePatterns": ["projects/standalone-app-e2e/**/*.{js,ts}"]
916+
}
917+
}
918+
},
919+
"tags": [],
920+
"implicitDependencies": ["standalone-app"]
921+
},
801922
"store": {
802923
"projectType": "library",
803924
"root": "modules/store",

modules/store/spec/integration.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ describe('ngRx Integration spec', () => {
483483

484484
router.navigateByUrl('/feature-path').catch((err: TypeError) => {
485485
expect(err.message).toBe(
486-
'StoreModule.forRoot() called twice. Feature modules should use StoreModule.forFeature() instead.'
486+
'The root Store has been provided more than once. Feature modules should provide feature states instead.'
487487
);
488488
done();
489489
});

modules/store/spec/store.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ActionReducer,
1313
Action,
1414
} from '../';
15-
import { StoreConfig } from '../src/store_module';
15+
import { StoreConfig } from '../src/store_config';
1616
import { combineReducers } from '../src/utils';
1717
import {
1818
counterReducer,

modules/store/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export {
1313
SelectorWithProps,
1414
RuntimeChecks,
1515
FunctionWithParametersType,
16+
EnvironmentProviders,
1617
} from './models';
1718
export { createAction, props, union } from './action_creator';
1819
export { createActionGroup, emptyProps } from './action_group_creator';
@@ -52,13 +53,14 @@ export {
5253
USER_PROVIDED_META_REDUCERS,
5354
USER_RUNTIME_CHECKS,
5455
ACTIVE_RUNTIME_CHECKS,
56+
FEATURE_STATE_PROVIDER,
57+
ROOT_STORE_PROVIDER,
5558
} from './tokens';
5659
export {
5760
StoreModule,
5861
StoreRootModule,
5962
StoreFeatureModule,
60-
RootStoreConfig,
61-
StoreConfig,
62-
FeatureSlice,
6363
} from './store_module';
64+
export { RootStoreConfig, StoreConfig, FeatureSlice } from './store_config';
65+
export { provideStore, provideState } from './provide_store';
6466
export { ReducerTypes, on, createReducer } from './reducer_creator';

modules/store/src/models.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ImportedNgModuleProviders } from '@angular/core';
2+
13
export interface Action {
24
type: string;
35
}
@@ -173,3 +175,9 @@ export interface RuntimeChecks {
173175
*/
174176
strictActionTypeUniqueness?: boolean;
175177
}
178+
179+
/** An alias type of ImportedNgModuleProviders
180+
* that better describes where the providers
181+
* are allowed to be registered.
182+
*/
183+
export type EnvironmentProviders = ImportedNgModuleProviders;

0 commit comments

Comments
 (0)