From e9e1704941a30508bbc00326ce595857a026a824 Mon Sep 17 00:00:00 2001 From: Edric Chan Date: Sun, 30 Jun 2019 16:47:27 +0800 Subject: [PATCH] feat(lib): add support for `forRoot` pattern for all modules --- .../src/ytd-api-comment-threads.module.ts | 22 ++++++++++++++++--- .../comments/src/ytd-api-comments.module.ts | 22 ++++++++++++++++--- .../search/src/ytd-api-search.module.ts | 22 ++++++++++++++++--- .../videos/src/ytd-api-videos.module.ts | 22 ++++++++++++++++--- 4 files changed, 76 insertions(+), 12 deletions(-) diff --git a/projects/ngx-ytd-api-lib/commentThreads/src/ytd-api-comment-threads.module.ts b/projects/ngx-ytd-api-lib/commentThreads/src/ytd-api-comment-threads.module.ts index 6e933c1..0de1e89 100644 --- a/projects/ngx-ytd-api-lib/commentThreads/src/ytd-api-comment-threads.module.ts +++ b/projects/ngx-ytd-api-lib/commentThreads/src/ytd-api-comment-threads.module.ts @@ -1,5 +1,5 @@ -import { NgModule } from '@angular/core'; -import { NgxYtdApiCommonModule } from 'ngx-ytd-api/common'; +import { ModuleWithProviders, NgModule } from '@angular/core'; +import { NgxYtdApiCommonModule, NgxYtdApiStandardParams, NGX_YTD_API_DEFAULT_STANDARD_PARAMS } from 'ngx-ytd-api/common'; import { NgxYtdApiCommentThreadsService } from './ytd-api-comment-threads.service'; @NgModule({ @@ -10,4 +10,20 @@ import { NgxYtdApiCommentThreadsService } from './ytd-api-comment-threads.servic NgxYtdApiCommonModule ] }) -export class NgxYtdApiCommentThreadsModule { } +export class NgxYtdApiCommentThreadsModule { + /** + * Returns the module with the specified standard parameters + * @param defaultParams The default standard parameters + * @returns The module with the specified standard parameters + */ + static forRoot( + defaultParams: NgxYtdApiStandardParams + ): ModuleWithProviders { + return { + ngModule: NgxYtdApiCommentThreadsModule, + providers: [ + { provide: NGX_YTD_API_DEFAULT_STANDARD_PARAMS, useValue: defaultParams } + ] + }; + } +} diff --git a/projects/ngx-ytd-api-lib/comments/src/ytd-api-comments.module.ts b/projects/ngx-ytd-api-lib/comments/src/ytd-api-comments.module.ts index 5049b64..89802f4 100644 --- a/projects/ngx-ytd-api-lib/comments/src/ytd-api-comments.module.ts +++ b/projects/ngx-ytd-api-lib/comments/src/ytd-api-comments.module.ts @@ -1,5 +1,5 @@ -import { NgModule } from '@angular/core'; -import { NgxYtdApiCommonModule } from 'ngx-ytd-api/common'; +import { ModuleWithProviders, NgModule } from '@angular/core'; +import { NgxYtdApiCommonModule, NgxYtdApiStandardParams, NGX_YTD_API_DEFAULT_STANDARD_PARAMS } from 'ngx-ytd-api/common'; import { NgxYtdApiCommentsService } from './ytd-api-comments.service'; @NgModule({ imports: [ @@ -9,4 +9,20 @@ import { NgxYtdApiCommentsService } from './ytd-api-comments.service'; NgxYtdApiCommentsService ] }) -export class NgxYtdApiCommentsModule { } +export class NgxYtdApiCommentsModule { + /** + * Returns the module with the specified standard parameters + * @param defaultParams The default standard parameters + * @returns The module with the specified standard parameters + */ + static forRoot( + defaultParams: NgxYtdApiStandardParams + ): ModuleWithProviders { + return { + ngModule: NgxYtdApiCommentsModule, + providers: [ + { provide: NGX_YTD_API_DEFAULT_STANDARD_PARAMS, useValue: defaultParams } + ] + }; + } +} diff --git a/projects/ngx-ytd-api-lib/search/src/ytd-api-search.module.ts b/projects/ngx-ytd-api-lib/search/src/ytd-api-search.module.ts index 378d865..0e0bd40 100644 --- a/projects/ngx-ytd-api-lib/search/src/ytd-api-search.module.ts +++ b/projects/ngx-ytd-api-lib/search/src/ytd-api-search.module.ts @@ -1,5 +1,5 @@ -import { NgModule } from '@angular/core'; -import { NgxYtdApiCommonModule } from 'ngx-ytd-api/common'; +import { ModuleWithProviders, NgModule } from '@angular/core'; +import { NgxYtdApiCommonModule, NgxYtdApiStandardParams, NGX_YTD_API_DEFAULT_STANDARD_PARAMS } from 'ngx-ytd-api/common'; import { NgxYtdApiSearchService } from './ytd-api-search.service'; @NgModule({ @@ -10,4 +10,20 @@ import { NgxYtdApiSearchService } from './ytd-api-search.service'; NgxYtdApiSearchService ] }) -export class NgxYtdApiSearchModule { } +export class NgxYtdApiSearchModule { + /** + * Returns the module with the specified standard parameters + * @param defaultParams The default standard parameters + * @returns The module with the specified standard parameters + */ + static forRoot( + defaultParams: NgxYtdApiStandardParams + ): ModuleWithProviders { + return { + ngModule: NgxYtdApiSearchModule, + providers: [ + { provide: NGX_YTD_API_DEFAULT_STANDARD_PARAMS, useValue: defaultParams } + ] + }; + } +} diff --git a/projects/ngx-ytd-api-lib/videos/src/ytd-api-videos.module.ts b/projects/ngx-ytd-api-lib/videos/src/ytd-api-videos.module.ts index a0bea96..17639df 100644 --- a/projects/ngx-ytd-api-lib/videos/src/ytd-api-videos.module.ts +++ b/projects/ngx-ytd-api-lib/videos/src/ytd-api-videos.module.ts @@ -1,5 +1,5 @@ -import { NgModule } from '@angular/core'; -import { NgxYtdApiCommonModule } from 'ngx-ytd-api/common'; +import { ModuleWithProviders, NgModule } from '@angular/core'; +import { NgxYtdApiCommonModule, NgxYtdApiStandardParams, NGX_YTD_API_DEFAULT_STANDARD_PARAMS } from 'ngx-ytd-api/common'; import { NgxYtdApiVideosService } from './ytd-api-videos.service'; @NgModule({ @@ -10,4 +10,20 @@ import { NgxYtdApiVideosService } from './ytd-api-videos.service'; NgxYtdApiVideosService ] }) -export class NgxYtdApiVideosModule { } +export class NgxYtdApiVideosModule { + /** + * Returns the module with the specified standard parameters + * @param defaultParams The default standard parameters + * @returns The module with the specified standard parameters + */ + static forRoot( + defaultParams: NgxYtdApiStandardParams + ): ModuleWithProviders { + return { + ngModule: NgxYtdApiVideosModule, + providers: [ + { provide: NGX_YTD_API_DEFAULT_STANDARD_PARAMS, useValue: defaultParams } + ] + }; + } +}