Skip to content

Commit

Permalink
feat(lib): update to rtk 2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
SaulMoro committed Feb 15, 2024
1 parent 2e62fc8 commit f2d81fb
Show file tree
Hide file tree
Showing 9 changed files with 2,313 additions and 1,679 deletions.
4 changes: 2 additions & 2 deletions e2e/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"outDir": "../out-tsc/e2e",
"module": "commonjs",
"target": "es2018",
"types": ["node"],
},
"types": ["node"]
}
}
3,823 changes: 2,200 additions & 1,623 deletions package-lock.json

Large diffs are not rendered by default.

82 changes: 41 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,86 +28,86 @@
},
"private": true,
"dependencies": {
"@angular/animations": "~17.1.0",
"@angular/common": "~17.1.0",
"@angular/compiler": "~17.1.0",
"@angular/core": "~17.1.0",
"@angular/forms": "~17.1.0",
"@angular/platform-browser": "~17.1.0",
"@angular/platform-browser-dynamic": "~17.1.0",
"@angular/router": "~17.1.0",
"@angular/animations": "~17.2.1",
"@angular/common": "~17.2.1",
"@angular/compiler": "~17.2.1",
"@angular/core": "~17.2.1",
"@angular/forms": "~17.2.1",
"@angular/platform-browser": "~17.2.1",
"@angular/platform-browser-dynamic": "~17.2.1",
"@angular/router": "~17.2.1",
"@ngneat/lib": "~5.0.0",
"@ngrx/effects": "17.1.0",
"@ngrx/router-store": "17.1.0",
"@ngrx/store": "17.1.0",
"@reduxjs/toolkit": "~2.0.1",
"@reduxjs/toolkit": "~2.2.1",
"rxjs": "~7.8.1",
"tslib": "~2.6.2",
"zone.js": "~0.14.3"
"zone.js": "~0.14.4"
},
"devDependencies": {
"@angular-builders/jest": "~17.0.0",
"@angular-devkit/build-angular": "~17.1.0",
"@angular-eslint/builder": "~17.2.0",
"@angular-eslint/eslint-plugin": "~17.2.0",
"@angular-eslint/eslint-plugin-template": "~17.2.0",
"@angular-eslint/schematics": "~17.2.0",
"@angular-eslint/template-parser": "~17.2.0",
"@angular/cli": "~17.1.0",
"@angular/compiler-cli": "~17.1.0",
"@commitlint/cli": "^18.4.4",
"@commitlint/config-conventional": "^18.4.4",
"@angular-builders/jest": "~17.0.1",
"@angular-devkit/build-angular": "~17.2.0",
"@angular-eslint/builder": "~17.2.1",
"@angular-eslint/eslint-plugin": "~17.2.1",
"@angular-eslint/eslint-plugin-template": "~17.2.1",
"@angular-eslint/schematics": "~17.2.1",
"@angular-eslint/template-parser": "~17.2.1",
"@angular/cli": "~17.2.0",
"@angular/compiler-cli": "~17.2.1",
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "^18.6.2",
"@ngrx/store-devtools": "17.1.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@tailwindcss/forms": "^0.5.7",
"@testing-library/angular": "^14.5.1",
"@testing-library/jest-dom": "^6.2.0",
"@testing-library/angular": "^15.2.0",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/user-event": "^14.5.2",
"@types/events": "^3.0.3",
"@types/jest": "^29.5.11",
"@types/node": "^18.19.8",
"@types/jest": "^29.5.12",
"@types/node": "^18.19.16",
"@types/node-fetch": "^2.6.11",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"all-contributors-cli": "^6.26.1",
"angular-cli-ghpages": "1.0.7",
"cpx": "^1.5.0",
"cross-env": "^7.0.3",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-jest": "^27.8.0",
"eslint-plugin-jest-dom": "^5.1.0",
"eslint-plugin-jsdoc": "^46.10.1",
"eslint-plugin-jsdoc": "^48.1.0",
"eslint-plugin-ngrx": "^2.1.4",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-rxjs": "^5.0.3",
"eslint-plugin-tailwindcss": "^3.14.0",
"eslint-plugin-tailwindcss": "^3.14.2",
"eslint-plugin-testing-library": "^6.2.0",
"git-cz": "^4.9.0",
"husky": "^8.0.3",
"husky": "^9.0.11",
"jest": "^29.7.0",
"jest-preset-angular": "~13.1.6",
"jsonc-parser": "^3.2.0",
"lint-staged": "^15.2.0",
"jest-preset-angular": "~14.0.2",
"jsonc-parser": "^3.2.1",
"lint-staged": "^15.2.2",
"msw": "^1.3.2",
"ng-packagr": "~17.1.0",
"ng-packagr": "~17.2.0",
"node-fetch": "^2.7.0",
"postcss": "^8.4.33",
"prettier": "^3.2.4",
"postcss": "^8.4.35",
"prettier": "^3.2.5",
"prettier-plugin-organize-attributes": "1.0.0",
"prettier-plugin-tailwindcss": "^0.5.11",
"protractor": "~7.0.0",
"semantic-release": "^22.0.12",
"stylelint": "^16.1.0",
"semantic-release": "^23.0.2",
"stylelint": "^16.2.1",
"stylelint-config-recommended-scss": "^14.0.0",
"stylelint-config-standard": "^36.0.0",
"stylelint-config-standard-scss": "^13.0.0",
"stylelint-scss": "^6.0.0",
"stylelint-scss": "^6.1.0",
"tailwindcss": "^3.4.1",
"ts-jest": "^29.1.1",
"ts-jest": "^29.1.2",
"ts-node": "~10.9.2",
"typescript": "~5.2.2"
},
Expand Down
2 changes: 1 addition & 1 deletion projects/ngrx-rtk-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"peerDependencies": {
"@angular/core": ">= 17.0.0 < 18",
"@ngrx/store": ">= 17.0.0 < 18",
"@reduxjs/toolkit": "~2.0.1"
"@reduxjs/toolkit": "~2.2.1"
},
"dependencies": {
"tslib": "^2.0.0"
Expand Down
29 changes: 22 additions & 7 deletions projects/ngrx-rtk-query/src/lib/build-hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DestroyRef, computed, effect, inject, isDevMode, signal, untracked } from '@angular/core';
import type { Action } from '@ngrx/store';
import type { Action, DefaultProjectorFn, MemoizedSelector } from '@ngrx/store';
import type { SubscriptionSelectors } from '@reduxjs/toolkit/dist/query/core/buildMiddleware/types';
import type {
Api,
Expand Down Expand Up @@ -156,8 +156,16 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
refetchOnMountOrArgChange,
skip = false,
pollingInterval = 0,
skipPollingIfUnfocused = false,
} = typeof options === 'function' ? options() : options;
return { refetchOnReconnect, refetchOnFocus, refetchOnMountOrArgChange, skip, pollingInterval };
return {
refetchOnReconnect,
refetchOnFocus,
refetchOnMountOrArgChange,
skip,
pollingInterval,
skipPollingIfUnfocused,
};
});
const subscriptionArg = computed(() => {
const subscriptionArg = typeof arg === 'function' ? arg() : arg;
Expand All @@ -177,8 +185,8 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
);
const stableSubscriptionOptions = computed(
() => {
const { refetchOnReconnect, refetchOnFocus, pollingInterval } = subscriptionOptions();
return { refetchOnReconnect, refetchOnFocus, pollingInterval };
const { refetchOnReconnect, refetchOnFocus, pollingInterval, skipPollingIfUnfocused } = subscriptionOptions();
return { refetchOnReconnect, refetchOnFocus, pollingInterval, skipPollingIfUnfocused };
},
{ equal: shallowEqual },
);
Expand Down Expand Up @@ -274,8 +282,9 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
refetchOnReconnect,
refetchOnFocus,
pollingInterval = 0,
skipPollingIfUnfocused = false,
} = typeof options === 'function' ? options() : options;
return { refetchOnReconnect, refetchOnFocus, pollingInterval };
return { refetchOnReconnect, refetchOnFocus, pollingInterval, skipPollingIfUnfocused };
},
{ equal: shallowEqual },
);
Expand Down Expand Up @@ -424,10 +433,16 @@ export function buildHooks<Definitions extends EndpointDefinitions>({

const requestId = computed(() => promiseRef()?.requestId);
const selectDefaultResult = (requestId?: string) => select({ fixedCacheKey, requestId });
const mutationSelector = (requestId?: string) =>
const mutationSelector = (
requestId?: string,
): MemoizedSelector<RootState<Definitions, any, any>, any, DefaultProjectorFn<any>> =>
selectFromResult
? createSelector(selectDefaultResult(requestId), selectFromResult)
: selectDefaultResult(requestId);
: (selectDefaultResult(requestId) as MemoizedSelector<
RootState<Definitions, any, any>,
any,
DefaultProjectorFn<any>
>);

const currentState = computed(() => useSelector(mutationSelector(requestId()), { equal: shallowEqual }));
const originalArgs = computed(() => (fixedCacheKey == null ? promiseRef()?.arg.originalArgs : undefined));
Expand Down
2 changes: 1 addition & 1 deletion projects/ngrx-rtk-query/src/lib/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export const angularHooksModule = ({
return {
name: angularHooksModuleName,
init(api, { serializeQueryArgs }, context) {
const anyApi = api as any as Api<any, Record<string, any>, string, string, AngularHooksModule>;
const anyApi = api as any as Api<any, Record<string, any>, any, any, AngularHooksModule>;
const { buildQueryHooks, buildMutationHook, usePrefetch } = buildHooks({
api,
moduleOptions: { hooks, createSelector },
Expand Down
34 changes: 34 additions & 0 deletions projects/ngrx-rtk-query/src/lib/types/hooks-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ export type UseQuery<D extends QueryDefinition<any, any, any, any>> = <
options?: UseQueryOptions<D, R> | Signal<UseQueryOptions<D, R>>,
) => Signal<UseQueryHookResult<D, R>>;

export type TypedUseQuery<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = UseQuery<
QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>
>;

export type UseQueryOptions<
D extends QueryDefinition<any, any, any, any>,
R extends Record<string, any> = UseQueryStateDefaultResult<D>,
Expand Down Expand Up @@ -156,6 +160,10 @@ export type UseQuerySubscription<D extends QueryDefinition<any, any, any, any>>
options?: UseQuerySubscriptionOptions | Signal<UseQuerySubscriptionOptions>,
) => UseQuerySubscriptionResult<D>;

export type TypedUseQuerySubscription<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = UseQuerySubscription<
QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>
>;

export type UseQuerySubscriptionResult<D extends QueryDefinition<any, any, any, any>> = Pick<
QueryActionCreatorResult<D>,
'refetch'
Expand Down Expand Up @@ -196,6 +204,10 @@ export type LazyQueryTrigger<D extends QueryDefinition<any, any, any, any>> = {
(arg: QueryArgFrom<D>, extra?: { preferCacheValue?: boolean }): QueryActionCreatorResult<D>;
};

export type TypedLazyQueryTrigger<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = LazyQueryTrigger<
QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>
>;

export type UseLazyQueryLastPromiseInfo<D extends QueryDefinition<any, any, any, any>> = {
lastArg: QueryArgFrom<D>;
extra?: Parameters<LazyQueryTrigger<D>>[1];
Expand Down Expand Up @@ -231,6 +243,10 @@ export type UseLazyQuery<D extends QueryDefinition<any, any, any, any>> = <
lastArg: Signal<QueryArgFrom<D>>;
};

export type TypedUseLazyQuery<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = UseLazyQuery<
QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>
>;

export type UseLazyQueryOptions<
D extends QueryDefinition<any, any, any, any>,
R extends Record<string, any> = UseQueryStateDefaultResult<D>,
Expand Down Expand Up @@ -258,10 +274,20 @@ export type UseLazyQuerySubscription<D extends QueryDefinition<any, any, any, an
options?: SubscriptionOptions | Signal<SubscriptionOptions>,
) => readonly [LazyQueryTrigger<D>, Signal<QueryArgFrom<D> | UninitializedValue>];

export type TypedUseLazyQuerySubscription<
ResultType,
QueryArg,
BaseQuery extends BaseQueryFn,
> = UseLazyQuerySubscription<QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>>;

export type QueryStateSelector<R extends Record<string, any>, D extends QueryDefinition<any, any, any, any>> = (
state: UseQueryStateDefaultResult<D>,
) => R;

export type TypedUseQueryState<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = UseQueryState<
QueryDefinition<QueryArg, BaseQuery, string, ResultType, string>
>;

/**
* A hook that reads the request status and cached data from the Redux store. The component will re-render
* as the loading status changes and the data becomes available.
Expand Down Expand Up @@ -444,6 +470,10 @@ export type UseMutation<D extends MutationDefinition<any, any, any, any>> = <
state: Signal<UseMutationStateResult<D, R>>;
};

export type TypedUseMutation<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = UseMutation<
MutationDefinition<QueryArg, BaseQuery, string, ResultType, string>
>;

export type MutationTrigger<D extends MutationDefinition<any, any, any, any>> = {
/**
* Triggers the mutation and returns a Promise.
Expand Down Expand Up @@ -474,6 +504,10 @@ export type MutationTrigger<D extends MutationDefinition<any, any, any, any>> =
(arg: QueryArgFrom<D>): MutationActionCreatorResult<D>;
};

export type TypedMutationTrigger<ResultType, QueryArg, BaseQuery extends BaseQueryFn> = MutationTrigger<
MutationDefinition<QueryArg, BaseQuery, string, ResultType, string>
>;

export type GenericPrefetchThunk = (
endpointName: any,
arg: any,
Expand Down
8 changes: 8 additions & 0 deletions projects/ngrx-rtk-query/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ export { createApi } from './lib/create-api';
export {
LazyQueryOptions,
QueryOptions,
TypedLazyQueryTrigger,
TypedMutationTrigger,
TypedUseLazyQuery,
TypedUseLazyQuerySubscription,
TypedUseMutation,
TypedUseMutationResult,
TypedUseQuery,
TypedUseQueryHookResult,
TypedUseQueryState,
TypedUseQueryStateResult,
TypedUseQuerySubscription,
TypedUseQuerySubscriptionResult,
} from './lib/types';
export { angularHooksModule, angularHooksModuleName };
8 changes: 4 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
"paths": {
"ngrx-rtk-query": ["projects/ngrx-rtk-query/src/public-api.ts"],
"@app/*": ["src/app/*"],
"@environments/*": ["src/environments/*"],
"@environments/*": ["src/environments/*"]
},
"useDefineForClassFields": false,
"useDefineForClassFields": false
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true,
"strictTemplates": true
},
"exclude": ["node_modules", "**/node_modules/*", "tmp"],
"exclude": ["node_modules", "**/node_modules/*", "tmp"]
}

0 comments on commit f2d81fb

Please sign in to comment.