Skip to content
This repository has been archived by the owner on Dec 10, 2022. It is now read-only.

Commit

Permalink
fix(preset): Fix types of preset input in modules
Browse files Browse the repository at this point in the history
And add structural difference to the abstrac preset type so only those who extend from it will  be
allowed
  • Loading branch information
gund committed Jan 23, 2018
1 parent 26380c7 commit 7bf2782
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/preset/preset-default.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PRESET_COMPS_TOKEN } from './preset-token';
import { CommonModule } from '@angular/common';
import { ModuleWithProviders, NgModule, Type } from '@angular/core';

import { providePresetFor } from './provide/preset-for';
import { PRESET_COMPS_TOKEN, PresetType } from './preset-token';
import { PresetService } from './preset.service';
import { providePresetFor } from './provide/preset-for';

@NgModule({
imports: [CommonModule],
Expand All @@ -14,14 +14,14 @@ import { PresetService } from './preset.service';
export class PresetDefaultModule {
static forComponent(
component: Type<any>,
presetType: Type<any>,
presetType: Type<PresetType>,
): ModuleWithProviders {
return PresetDefaultModule.forComponents([component], presetType);
}

static forComponents(
components: Type<any>[],
presetType: Type<any>,
presetType: Type<PresetType>,
): ModuleWithProviders {
return providePresetFor(PresetDefaultModule, presetType, [
{ provide: PRESET_COMPS_TOKEN, useValue: components, multi: true },
Expand Down
4 changes: 3 additions & 1 deletion src/preset/preset-token.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { InjectionToken, Type } from '@angular/core';

export abstract class PresetType {}
export abstract class PresetType {
private __isPreset__ = true;
}

export const PRESET_TYPES_TOKEN = new InjectionToken<PresetType[]>(
'PresetTypes',
Expand Down
2 changes: 1 addition & 1 deletion src/preset/provide/preset-for.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { providePreset } from './preset';

export function providePresetFor(
moduleClass: Type<any>,
presetType: PresetType,
presetType: Type<PresetType>,
additionalProviders: Provider[] = [],
): ModuleWithProviders {
return {
Expand Down
4 changes: 2 additions & 2 deletions src/preset/provide/preset.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ANALYZE_FOR_ENTRY_COMPONENTS, Provider } from '@angular/core';
import { ANALYZE_FOR_ENTRY_COMPONENTS, Provider, Type } from '@angular/core';

import { PRESET_TYPES_TOKEN, PresetType } from '../preset-token';

export function providePreset(presetType: PresetType): Provider[] {
export function providePreset(presetType: Type<PresetType>): Provider[] {
return [
{ provide: PRESET_TYPES_TOKEN, useValue: presetType, multi: true },
{
Expand Down

0 comments on commit 7bf2782

Please sign in to comment.