Skip to content

Add support for ngrx store 6 -> 7 migration #66

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/rxjsPipeableOperatorsOnlyRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,21 @@ function findImportedRxjsOperators(sourceFile: ts.SourceFile): Set<string> {
* @param startIndex Position where the {@link Lint.Replacement} can be inserted
*/
function createImportReplacements(operatorsToAdd: Set<string>, startIndex: number): Lint.Replacement[] {
return [...Array.from(operatorsToAdd.values())].map(operator =>
Lint.Replacement.appendText(startIndex, `\nimport {${operator}} from 'rxjs/operators/${operator}';\n`)
);
return [...Array.from(operatorsToAdd.values())].map(operator => {
let importPath: string;
if (NGRX_EFFECT_OPERATORS.has(operator)) {
importPath = '@ngrx/effects';
}
if (NGRX_STORE_OPERATORS.has(operator)) {
importPath = '@ngrx/store';
} else {
importPath = `rxjs/operators/${operator}`;
}
return Lint.Replacement.appendText(
startIndex,
`\nimport {${operator}} from '${importPath}';\n`
);
});
}

/**
Expand Down Expand Up @@ -296,6 +308,10 @@ function replaceWithPipeableOperators(
const separatorReplacements = notStart ? [Lint.Replacement.appendText(currentNode.getEnd(), ',')] : [];
return [operatorReplacement, ...separatorReplacements, ...moreReplacements];
}

const NGRX_STORE_OPERATORS = new Set(['select']);
const NGRX_EFFECT_OPERATORS = new Set(['ofType']);

/**
* Set of all instance operators, including those renamed as part of lettable
* operator migration. Source:(RxJS v5)
Expand Down Expand Up @@ -409,7 +425,9 @@ const RXJS_OPERATORS = new Set([
'flatMapTo',
'finally',
'switch',
'let'
'let',
...Array.from(NGRX_STORE_OPERATORS),
...Array.from(NGRX_EFFECT_OPERATORS)
]);
/**
* Represents the mapping for pipeable version of some operators whose name has
Expand Down
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ export function isObservable(type: ts.Type, tc: ts.TypeChecker): boolean {
if (tsutils.isTypeReference(type)) {
type = type.target;
}
if (type.symbol !== undefined && type.symbol.name === 'Observable') {
if (
type.symbol !== undefined &&
(type.symbol.name === 'Observable' || type.symbol.name === 'Store')
Copy link
Author

Choose a reason for hiding this comment

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

FWIW Store, despite being Observable-like doesn't actually resolve to the Observable type.

) {
return true;
}
if (tsutils.isUnionOrIntersectionType(type)) {
Expand Down