Skip to content

Commit

Permalink
docs: improved docs for withEntitiesRemoteScrollPagination, and fixed…
Browse files Browse the repository at this point in the history
… old names
  • Loading branch information
Gabriel Guerrero authored and gabrielguerrero committed Apr 22, 2024
1 parent b3724b3 commit b4986d6
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,37 +42,3 @@ export const ProductsBranchStore = signalStore(
}),
withLogger('branchStore'),
);
// const collection = 'products';
// export const ProductsBranchStore2 = signalStore(
// withEntities({
// entity,
// collection,
// }),
// withCallStatus({ initialValue: 'loading', collection }),
// withEntitiesRemoteFilter({
// entity,
// defaultFilter: { search: '' },
// collection,
// }),
// withEntitiesRemoteScrollPagination({
// bufferSize: 30,
// entity,
// collection,
// }),
// withEntitiesLoadingCall({
// collection,
// fetchEntities: async ({ productsRequest, productsFilter }) => {
// const res = await lastValueFrom(
// inject(BranchService).getBranches({
// search: productsFilter().search,
// skip: productsRequest().startIndex,
// take: productsRequest().size,
// }),
// );
// return { entities: res.resultList, total: res.total };
// },
// }),
// withLogger('branchStore'),
// );
// const store = new ProductsBranchStore2();
// getInfiniteScrollDataSource({ store, collection, entity });
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ export const ProductsRemoteStore = signalStore(
pageSize: 5,
pagesToCache: 2,
}),
// withEntitiesRemoteScrollPagination({
// bufferSize: 5,
// collection,
// entity
// }),
withEntitiesRemoteSort({
entity,
collection,
Expand Down
95 changes: 58 additions & 37 deletions libs/ngrx-traits/signals/api-docs.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ import {
/**
* Generates necessary state, computed and methods for locally filtering entities in the store,
* the generated filter[collenction]Entities method will filter the entities based on the filter function
* and is debounced by default. Requires withEntities to be used.
* and is debounced by default.
*
* Requires withEntities to be used.
*
* @param config
* @param config.filterFn - The function that will be used to filter the entities
Expand All @@ -65,7 +67,7 @@ import {
* }),
* );
*
* // generates the following signals
* // generates the following signals
* store.productsFilter // { search: string }
* // generates the following computed signals
* store.isProductsFilterChanged // boolean
Expand Down Expand Up @@ -95,7 +97,9 @@ export function withEntitiesLocalFilter<
/**
* Generates necessary state, computed and methods for locally filtering entities in the store,
* the generated filter[collenction]Entities method will filter the entities based on the filter function
* and is debounced by default. Requires withEntities to be used.
* and is debounced by default.
*
* Requires withEntities to be used.
*
* @param config
* @param config.filterFn - The function that will be used to filter the entities
Expand Down Expand Up @@ -155,6 +159,7 @@ export function withEntitiesLocalFilter<
methods: NamedEntitiesFilterMethods<Collection, Filter>;
}
>;

export function withEntitiesLocalFilter<
Entity extends { id: string | number },
Collection extends string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ import {
* the generated filter[collection]Entities method will filter the entities by calling set[collection]Loading()
* and you should either create an effect that listens toe [collection]Loading can call the api with the [collection]Filter params
* or use withEntitiesLoadingCall to call the api with the [collection]Filter params
* and is debounced by default. Requires withEntities and withCallStatus to be present before this function.
* and is debounced by default.
*
* Requires withEntities and withCallStatus to be present before this function.
* @param config
* @param config.defaultFilter - The default filter to be used
* @param config.entity - The entity type to be used
Expand Down Expand Up @@ -79,9 +81,9 @@ import {
* // effect(() => {
* // if (isProductsLoading()) {
* // inject(ProductService)
* // .getProducts({
* // .getProducts({
* // search: productsFilter().name,
* // })
* // })
* // .pipe(
* // takeUntilDestroyed(),
* // tap((res) =>
Expand Down Expand Up @@ -131,7 +133,9 @@ export function withEntitiesRemoteFilter<
* the generated filter[collection]Entities method will filter the entities by calling set[collection]Loading()
* and you should either create an effect that listens toe [collection]Loading can call the api with the [collection]Filter params
* or use withEntitiesLoadingCall to call the api with the [collection]Filter params
* and is debounced by default. Requires withEntities and withCallStatus to be present before this function.
* and is debounced by default.
*
* Requires withEntities and withCallStatus to be present before this function.
* @param config
* @param config.defaultFilter - The default filter to be used
* @param config.entity - The entity type to be used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe('withEntitiesLoadingCall', () => {
});
}));

it('should set[Collection]LoadResult if fetchEntities returns an a {entities: Entity[], total: number} ', fakeAsync(() => {
it('should set[Collection]Result if fetchEntities returns an a {entities: Entity[], total: number} ', fakeAsync(() => {
TestBed.runInInjectionContext(() => {
const Store = signalStore(
withEntities({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ import { getWithEntitiesRemotePaginationKeys } from '../with-entities-pagination
* to the store using the setAllEntities method or the setEntitiesResult method
* if it exists (comes from withEntitiesRemotePagination),
* if an error occurs it will set the error to the store using set[Collection]Error with the error.
*
* Requires withEntities and withCallStatus to be present in the store.
*
* @param config - Configuration object
* @param config.fetchEntities - A function that fetches the entities from a remote source the return type
* @param config.collection - The collection name
Expand Down Expand Up @@ -156,7 +158,9 @@ export function withEntitiesLoadingCall<
* to the store using the setAllEntities method or the setEntitiesResult method
* if it exists (comes from withEntitiesRemotePagination),
* if an error occurs it will set the error to the store using set[Collection]Error with the error.
*
* Requires withEntities and withCallStatus to be present in the store.
*
* @param config - Configuration object
* @param config.fetchEntities - A function that fetches the entities from a remote source the return type
* @param config.collection - The collection name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {

/**
* Generates necessary state, computed and methods for local pagination of entities in the store.
*
* Requires withEntities to be present in the store.
* @param config
* @param config.pageSize - The number of entities to show per page
Expand All @@ -54,7 +55,7 @@ import {
* entity,
* collection,
* pageSize: 5,
* }));
* }),
*
* // generates the following signals
* store.productsPagination // { currentPage: 0, pageSize: 5 }
Expand Down Expand Up @@ -83,6 +84,7 @@ export function withEntitiesLocalPagination<
>;
/**
* Generates necessary state, computed and methods for local pagination of entities in the store.
*
* Requires withEntities to be present in the store.
* @param config
* @param config.pageSize - The number of entities to show per page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ import {
* Generates necessary state, computed and methods for remote pagination of entities in the store.
* When the page changes, it will try to load the current page from cache if it's not present,
* it will call set[collection]Loading(), and you should either create an effect that listens to [collection]Loading
* and call the api with the [collection]PagedRequest params and use set[Collection]LoadResult to set the result
* and call the api with the [collection]PagedRequest params and use set[Collection]Result to set the result
* and changing the status errors manually
* or use withEntitiesLoadingCall to call the api with the [collection]PagedRequest params which handles setting
* the result and errors automatically. Requires withEntities and withCallStatus to be present before this function.
* the result and errors automatically.
*
* Requires withEntities and withCallStatus to be present before this function.
* @param config
* @param config.pageSize - The number of entities to show per page
* @param config.currentPage - The current page to show
Expand All @@ -66,7 +68,9 @@ import {
* @param config.collection - The name of the collection
*
* @example
* export const ProductsRemoteStore = signalStore(
* const entity = type<Product>();
* const collection = 'products';
* export const store = signalStore(
* { providedIn: 'root' },
* // required withEntities and withCallStatus
* withEntities({ entity, collection }),
Expand Down Expand Up @@ -96,7 +100,7 @@ import {
* },
* }),
* // withEntitiesLoadingCall is the same as doing the following:
* // withHooks(({ productsLoading, setProductsError, setProductsLoadResult, ...state }) => ({
* // withHooks(({ productsLoading, setProductsError, setProductsResult, ...state }) => ({
* // onInit: async () => {
* // effect(() => {
* // if (isProductsLoading()) {
Expand All @@ -110,7 +114,7 @@ import {
* // tap((res) =>
* // patchState(
* // state,
* // setProductsLoadResult(res.resultList, res.total),
* // setProductsResult({ entities: res.resultList, total: res.total } ),
* // ),
* // ),
* // catchError((error) => {
Expand All @@ -130,7 +134,7 @@ import {
* store.productsPagedRequest // { startIndex: number, size: number, page: number }
* // generates the following methods
* store.loadProductsPage({ pageIndex: number, forceLoad?: boolean }) // loads the page and sets the requestPage to the pageIndex
* store.setProductsLoadResult(entities: Product[], total: number) // appends the entities to the cache of entities and total
* store.setProductsResult(entities: Product[], total: number) // appends the entities to the cache of entities and total
*/
export function withEntitiesRemotePagination<
Entity extends { id: string | number },
Expand All @@ -155,10 +159,12 @@ export function withEntitiesRemotePagination<
* Generates necessary state, computed and methods for remote pagination of entities in the store.
* When the page changes, it will try to load the current page from cache if it's not present,
* it will call set[collection]Loading(), and you should either create an effect that listens to [collection]Loading
* and call the api with the [collection]PagedRequest params and use set[Collection]LoadResult to set the result
* and call the api with the [collection]PagedRequest params and use set[Collection]Result to set the result
* and changing the status errors manually
* or use withEntitiesLoadingCall to call the api with the [collection]PagedRequest params which handles setting
* the result and errors automatically. Requires withEntities and withCallStatus to be present before this function.
* the result and errors automatically.
*
* Requires withEntities and withCallStatus to be present before this function.
* @param config
* @param config.pageSize - The number of entities to show per page
* @param config.currentPage - The current page to show
Expand Down Expand Up @@ -199,7 +205,7 @@ export function withEntitiesRemotePagination<
* },
* }),
* // withEntitiesLoadingCall is the same as doing the following:
* // withHooks(({ productsLoading, setProductsError, setProductsLoadResult, ...state }) => ({
* // withHooks(({ productsLoading, setProductsError, setProductsResult, ...state }) => ({
* // onInit: async () => {
* // effect(() => {
* // if (isProductsLoading()) {
Expand All @@ -213,7 +219,7 @@ export function withEntitiesRemotePagination<
* // tap((res) =>
* // patchState(
* // state,
* // setProductsLoadResult(res.resultList, res.total),
* // setProductsResult({ entities: res.resultList, total: res.total } ),
* // ),
* // ),
* // catchError((error) => {
Expand All @@ -233,7 +239,7 @@ export function withEntitiesRemotePagination<
* store.productsPagedRequest // { startIndex: number, size: number, page: number }
* // generates the following methods
* store.loadProductsPage({ pageIndex: number, forceLoad?: boolean }) // loads the page and sets the requestPage to the pageIndex
* store.setProductsLoadResult(entities: Product[], total: number) // appends the entities to the cache of entities and total
* store.setProductsResult(entities: Product[], total: number) // appends the entities to the cache of entities and total
*/

export function withEntitiesRemotePagination<
Expand Down Expand Up @@ -262,7 +268,7 @@ export function withEntitiesRemotePagination<
* Generates necessary state, computed and methods for remote pagination of entities in the store.
* When the page changes, it will try to load the current page from cache if it's not present,
* it will call set[collection]Loading(), and you should either create an effect that listens to [collection]Loading
* and call the api with the [collection]PagedRequest params and use set[Collection]LoadResult to set the result
* and call the api with the [collection]PagedRequest params and use set[Collection]Result to set the result
* and changing the status errors manually
* or use withEntitiesLoadingCall to call the api with the [collection]PagedRequest params which handles setting
* the result and errors automatically. Requires withEntities and withCallStatus to be used.
Expand Down Expand Up @@ -307,7 +313,7 @@ export function withEntitiesRemotePagination<
* },
* }),
* // withEntitiesLoadingCall is the same as doing the following:
* // withHooks(({ productsLoading, setProductsError, setProductsLoadResult, ...state }) => ({
* // withHooks(({ productsLoading, setProductsError, setProductsResult, ...state }) => ({
* // onInit: async () => {
* // effect(() => {
* // if (isProductsLoading()) {
Expand All @@ -321,7 +327,7 @@ export function withEntitiesRemotePagination<
* // tap((res) =>
* // patchState(
* // state,
* // setProductsLoadResult(res.resultList, res.total),
* // setProductsResult({ entities: res.resultList, total: res.total } ),
* // ),
* // ),
* // catchError((error) => {
Expand All @@ -341,7 +347,7 @@ export function withEntitiesRemotePagination<
* store.productsPagedRequest // { startIndex: number, size: number, page: number }
* // generates the following methods
* store.loadProductsPage({ pageIndex: number, forceLoad?: boolean }) // loads the page and sets the requestPage to the pageIndex
* store.setProductsLoadResult(entities: Product[], total: number) // appends the entities to the cache of entities and total
* store.setProductsResult(entities: Product[], total: number) // appends the entities to the cache of entities and total
*/
export function withEntitiesRemotePagination<
Entity extends { id: string | number },
Expand Down
Loading

0 comments on commit b4986d6

Please sign in to comment.