Skip to content

Commit

Permalink
fix(store): Expose ActionType interface from store/src/models.
Browse files Browse the repository at this point in the history
ActionType is useful for extracting the response type of the new action creators.

feat(store): add verbose error message for undefined feature state in development mode (ngrx#2078)

Closes ngrx#1897

docs(store-devtools): add recipe to exclude store-devtools from the build (ngrx#2073)

Closes ngrx#1521

fix(store): add DefaultProjectorFn to public API (ngrx#2090)

Allows you to fully type the selector without reaching into the src folder

ci: fix filters on tags for publishing to npm and deployment of docs (ngrx#2091)

* refactor(data): use createEffect function instead of @effect decorator
  • Loading branch information
jordanpowell88 committed Nov 8, 2019
2 parents 9dc79bb + bdac544 commit badf605
Show file tree
Hide file tree
Showing 137 changed files with 1,832 additions and 587 deletions.
49 changes: 29 additions & 20 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ jobs:
- ~/.cache/yarn
- ~/.cache/Cypress
- node_modules
# required since `publish-*` jobs have tag filters AND requires `test`
# https://circleci.com/docs/2.0/workflows/#executing-workflows-for-a-git-tag
filters:
tags:
only: /.*/

schematics-core-check:
<<: *run_in_browser
Expand Down Expand Up @@ -211,7 +216,9 @@ jobs:
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$npm_TOKEN" > ~/repo/.npmrc
- run: yarn run publish:stable
- run:
name: Publish stable to npm
command: ./node_modules/.bin/ts-node ./build/publish-stable.ts

publish-next:
<<: *run_in_node
Expand All @@ -224,7 +231,9 @@ jobs:
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$npm_TOKEN" > ~/repo/.npmrc
- run: yarn run publish:next
- run:
name: Publish next to npm
command: ./node_modules/.bin/ts-node ./build/publish-next.ts

cleanup-previews:
<<: *run_in_node
Expand Down Expand Up @@ -282,27 +291,27 @@ workflows:
filters:
branches:
only: master
# - publish-stable:
# requires:
# - test
# filters:
# branches:
# ignore: /.*/
# tags:
# only: /\d+\.\d+\.\d+(?!-\w+\.\d)/
# - deploy-docs-stable:
# requires:
# - test
# filters:
# branches:
# ignore: /.*/
# tags:
# only: /\d+\.\d+\.\d+(?!-\w+\.\d)/
- publish-next:
- publish-stable:
requires:
- test
filters:
tags:
only: /8\.\d+\.\d+(?!-\w+\.\d)/
branches:
ignore: /.*/
- deploy-docs-stable:
requires:
- test
filters:
tags:
only: /\d+\.\d+\.\d+(-\w+\.\d)/
only: /8\.\d+\.\d+(?!-\w+\.\d)/
branches:
ignore: /.*/
- publish-next:
requires:
- test
filters:
tags:
only: /8\.\d+\.\d+(-\w+\.\d)/
branches:
ignore: /.*/
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
<a name="8.4.0"></a>

# [8.4.0](https://github.com/ngrx/platform/compare/8.3.0...8.4.0) (2019-10-09)

### Bug Fixes

- **schematics:** fixed the schematics/action spec template ([#2092](https://github.com/ngrx/platform/issues/2092)) ([ed3b1f9](https://github.com/ngrx/platform/commit/ed3b1f9)), closes [#2082](https://github.com/ngrx/platform/issues/2082)
- **store:** improve consistency of memoized selector result when projection fails ([#2101](https://github.com/ngrx/platform/issues/2101)) ([c63941c](https://github.com/ngrx/platform/commit/c63941c)), closes [#2100](https://github.com/ngrx/platform/issues/2100)

### Features

- **effects:** throw error when forRoot() is used more than once ([b46748c](https://github.com/ngrx/platform/commit/b46748c))
- **schematics:** add createEffect migration schematic ([#2136](https://github.com/ngrx/platform/issues/2136)) ([9eb1bd5](https://github.com/ngrx/platform/commit/9eb1bd5))
- **store:** add refreshState method to mock store ([#2148](https://github.com/ngrx/platform/issues/2148)) ([30e876f](https://github.com/ngrx/platform/commit/30e876f)), closes [#2121](https://github.com/ngrx/platform/issues/2121)
- **store:** allow multiple on handlers for the same action in createReducer([#2103](https://github.com/ngrx/platform/issues/2103)) ([9a70262](https://github.com/ngrx/platform/commit/9a70262)), closes [#1956](https://github.com/ngrx/platform/issues/1956)
- **store:** cleanup selector after a test ([2964e2b](https://github.com/ngrx/platform/commit/2964e2b))
- **store:** throw error when forRoot() is used more than once ([4304865](https://github.com/ngrx/platform/commit/4304865))

<a name="8.3.0"></a>

# [8.3.0](https://github.com/ngrx/platform/compare/8.2.0...8.3.0) (2019-08-29)

### Bug Fixes

- **data:** use correct guard when handling optimistic update ([#2060](https://github.com/ngrx/platform/issues/2060)) ([34c0420](https://github.com/ngrx/platform/commit/34c0420)), closes [#2059](https://github.com/ngrx/platform/issues/2059)
- **store:** add DefaultProjectorFn to public API ([#2090](https://github.com/ngrx/platform/issues/2090)) ([2d37b48](https://github.com/ngrx/platform/commit/2d37b48))
- **store:** should not run schematics when not using named imports ([#2095](https://github.com/ngrx/platform/issues/2095)) ([7cadbc0](https://github.com/ngrx/platform/commit/7cadbc0)), closes [#2093](https://github.com/ngrx/platform/issues/2093)

### Features

- **store:** add verbose error message for undefined feature state in development mode ([#2078](https://github.com/ngrx/platform/issues/2078)) ([6946e2e](https://github.com/ngrx/platform/commit/6946e2e)), closes [#1897](https://github.com/ngrx/platform/issues/1897)

<a name="8.2.0"></a>

# [8.2.0](https://github.com/ngrx/platform/compare/8.1.0...8.2.0) (2019-07-31)
Expand Down
81 changes: 59 additions & 22 deletions modules/data/schematics-core/utility/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
NoopChange,
createReplaceChange,
ReplaceChange,
RemoveChange,
createRemoveChange,
} from './change';
import { Path } from '@angular-devkit/core';

Expand Down Expand Up @@ -650,7 +652,7 @@ export function replaceImport(
importFrom: string,
importAsIs: string,
importToBe: string
): ReplaceChange[] {
): (ReplaceChange | RemoveChange)[] {
const imports = sourceFile.statements
.filter(ts.isImportDeclaration)
.filter(
Expand All @@ -663,32 +665,67 @@ export function replaceImport(
return [];
}

const changes = imports
.map(p => (p.importClause!.namedBindings! as ts.NamedImports).elements)
.reduce((imports, curr) => imports.concat(curr), [] as ts.ImportSpecifier[])
.map(specifier => {
if (!ts.isImportSpecifier(specifier)) {
return { hit: false };
const importText = (specifier: ts.ImportSpecifier) => {
if (specifier.name.text) {
return specifier.name.text;
}

// if import is renamed
if (specifier.propertyName && specifier.propertyName.text) {
return specifier.propertyName.text;
}

return '';
};

const changes = imports.map(p => {
const importSpecifiers = (p.importClause!.namedBindings! as ts.NamedImports)
.elements;

const isAlreadyImported = importSpecifiers
.map(importText)
.includes(importToBe);

const importChanges = importSpecifiers.map((specifier, index) => {
const text = importText(specifier);

// import is not the one we're looking for, can be skipped
if (text !== importAsIs) {
return undefined;
}

if (specifier.name.text === importAsIs) {
return { hit: true, specifier, text: specifier.name.text };
// identifier has not been imported, simply replace the old text with the new text
if (!isAlreadyImported) {
return createReplaceChange(
sourceFile,
specifier!,
importAsIs,
importToBe
);
}

// if import is renamed
if (
specifier.propertyName &&
specifier.propertyName.text === importAsIs
) {
return { hit: true, specifier, text: specifier.propertyName.text };
const nextIdentifier = importSpecifiers[index + 1];
// identifer is not the last, also clean up the comma
if (nextIdentifier) {
return createRemoveChange(
sourceFile,
specifier,
specifier.getStart(sourceFile),
nextIdentifier.getStart(sourceFile)
);
}

return { hit: false };
})
.filter(({ hit }) => hit)
.map(({ specifier, text }) =>
createReplaceChange(sourceFile, specifier!, text!, importToBe)
);
// there are no imports following, just remove it
return createRemoveChange(
sourceFile,
specifier,
specifier.getStart(sourceFile),
specifier.getEnd()
);
});

return importChanges.filter(Boolean) as (ReplaceChange | RemoveChange)[];
});

return changes;
return changes.reduce((imports, curr) => imports.concat(curr), []);
}
9 changes: 9 additions & 0 deletions modules/data/schematics-core/utility/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ export function createReplaceChange(
);
}

export function createRemoveChange(
sourceFile: ts.SourceFile,
node: ts.Node,
from = node.getStart(sourceFile),
to = node.getEnd()
): RemoveChange {
return new RemoveChange(sourceFile.fileName, from, to);
}

export function createChangeRecorder(
tree: Tree,
path: string,
Expand Down
2 changes: 0 additions & 2 deletions modules/data/spec/actions/entity-action-factory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {
EntityAction,
EntityActionOptions,
EntityActionPayload,
EntityOp,
EntityActionFactory,
MergeStrategy,
CorrelationIdGenerator,
} from '../../';

class Hero {
Expand Down
1 change: 0 additions & 1 deletion modules/data/spec/actions/entity-action-operators.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Action } from '@ngrx/store';
import { Actions } from '@ngrx/effects';

import { Subject } from 'rxjs';

Expand Down
6 changes: 1 addition & 5 deletions modules/data/spec/actions/entity-cache-changes-set.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
ChangeSet,
ChangeSetOperation,
changeSetItemFactory as cif,
} from '../../';
import { ChangeSetOperation, changeSetItemFactory as cif } from '../../';

describe('changeSetItemFactory', () => {
const hero = { id: 1, name: 'Hero 1' };
Expand Down
2 changes: 1 addition & 1 deletion modules/data/spec/dataservices/data-service-error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HttpErrorResponse } from '@angular/common/http';
import { DataServiceError, RequestData } from '../../';
import { DataServiceError } from '../../';

describe('DataServiceError', () => {
describe('#message', () => {
Expand Down
3 changes: 1 addition & 2 deletions modules/data/spec/dataservices/default-data.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TestBed } from '@angular/core/testing';

import { HttpClient, HttpResponse } from '@angular/common/http';
import { HttpClient } from '@angular/common/http';
import {
HttpClientTestingModule,
HttpTestingController,
Expand All @@ -14,7 +14,6 @@ import {
DefaultDataService,
DefaultDataServiceFactory,
DefaultHttpUrlGenerator,
EntityHttpResourceUrls,
HttpUrlGenerator,
DefaultDataServiceConfig,
DataServiceError,
Expand Down
5 changes: 0 additions & 5 deletions modules/data/spec/dataservices/entity-data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ import { Observable } from 'rxjs';
import { Update } from '@ngrx/entity';

import {
createEntityDefinition,
EntityDefinition,
EntityMetadata,
EntityMetadataMap,
ENTITY_METADATA_TOKEN,
DefaultDataService,
DefaultDataServiceFactory,
HttpUrlGenerator,
Expand Down
13 changes: 2 additions & 11 deletions modules/data/spec/effects/entity-cache-effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,8 @@
import { TestBed } from '@angular/core/testing';
import { Action } from '@ngrx/store';
import { Actions } from '@ngrx/effects';

import {
asapScheduler,
Observable,
of,
merge,
ReplaySubject,
Subject,
throwError,
} from 'rxjs';
import { first, mergeMap, observeOn, tap } from 'rxjs/operators';
import { observeOn } from 'rxjs/operators';
import { asapScheduler, ReplaySubject, Subject } from 'rxjs';

import {
EntityCacheEffects,
Expand Down
2 changes: 1 addition & 1 deletion modules/data/spec/effects/entity-effects.marbles.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { TestBed } from '@angular/core/testing';

import { cold, hot, getTestScheduler } from 'jasmine-marbles';
import { Observable, of, Subject } from 'rxjs';
import { Observable } from 'rxjs';

import { Actions } from '@ngrx/effects';
import { Update } from '@ngrx/entity';
Expand Down
2 changes: 1 addition & 1 deletion modules/data/spec/effects/entity-effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Action } from '@ngrx/store';
import { Actions } from '@ngrx/effects';
import { Update } from '@ngrx/entity';

import { Observable, of, merge, ReplaySubject, throwError, timer } from 'rxjs';
import { of, merge, ReplaySubject, throwError, timer } from 'rxjs';
import { delay, first, mergeMap } from 'rxjs/operators';

import {
Expand Down
17 changes: 9 additions & 8 deletions modules/data/spec/entity-data.module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
Store,
StoreModule,
} from '@ngrx/store';
import { Actions, Effect, EffectsModule } from '@ngrx/effects';
import { Actions, EffectsModule, createEffect } from '@ngrx/effects';

// Not using marble testing
import { TestBed } from '@angular/core/testing';

import { Observable, of, Subject } from 'rxjs';
import { map, skip, tap } from 'rxjs/operators';
import { Observable } from 'rxjs';
import { map, skip } from 'rxjs/operators';

import {
EntityCache,
Expand All @@ -35,11 +35,12 @@ const EC_METAREDUCER_TOKEN = new InjectionToken<

@Injectable()
class TestEntityEffects {
@Effect()
test$: Observable<Action> = this.actions.pipe(
// tap(action => console.log('test$ effect', action)),
ofEntityOp(persistOps),
map(this.testHook)
test$: Observable<Action> = createEffect(() =>
this.actions.pipe(
// tap(action => console.log('test$ effect', action)),
ofEntityOp(persistOps),
map(this.testHook)
)
);

testHook(action: EntityAction) {
Expand Down
Loading

0 comments on commit badf605

Please sign in to comment.