Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the hierarchy of NavigationMode classes. (#166)
* Refactor the hierarchy of NavigationMode classes. * Shared code extracted to the base `abstract class NavigationMode`. * This higlights differences between provided navigation modes. * Document arguments for goToNextStep and goToPreviousStep * Allow checkReset to indicate check failure by returning false #166 (comment) * Split `abstract class NavigationMode` into `interface NavigationMode` and `abstract class BaseNavigationMode`. * Provide an ability to specify WizardComponent's navigationMode input as a function returning a navigation mode name or a created NavigationMode. Notes: - `WizardState.updateNavigationMode` method signature is left compatible with the old version. - A new set of tests is added in `navigation-mode-selection.spec.ts`. - The new ability should be documented in the 'navigationMode' section of the README. * Extract NavigationModeFactory interface and BaseNavigationModeFactory class. ArchwizardModule.forRoot() now takes an optional configuration object with an optional `navigationModeFactory` field. **BREAKING API CHANGES**: * WizardState.updateNavigationMode() no longer takes a navigation mode name. WizardComponent.updateNavigationMode() should be used instead. * Add comments for ArchwizardModuleConfig and ArchwizardModuleConfig.navigationModeFactory * Add missing doc-comment for a WizardComponent's constructor parameter * Add missing documentation for WizardComponent.updateNavigationMode * Rename `navigationMode` parameter to `navigationModeInput` for consistency and to match the doc comments * Improve doc comments for WizardComponent.navigationInput field and NavigationInput type * Removed the default value for WizardComponent.navigationMode field. It is not required. * Enable "member-access" check in tslint.json. Add missing access modifiers. * Move implementation-specific comments from NavigationMode interface to BaseNavigationMode class
- Loading branch information
Showing
32 changed files
with
576 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/lib/navigation/base-navigation-mode-factory.provider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {FreeNavigationMode} from './free-navigation-mode'; | ||
import {NavigationMode} from './navigation-mode.interface'; | ||
import {SemiStrictNavigationMode} from './semi-strict-navigation-mode'; | ||
import {StrictNavigationMode} from './strict-navigation-mode'; | ||
import {WizardComponent} from '../components/wizard.component'; | ||
import {NavigationModeInput} from './navigation-mode-input.interface'; | ||
import {NavigationModeFactory} from './navigation-mode-factory.interface'; | ||
|
||
/** | ||
* A factory used to create [[NavigationMode]] instances | ||
*/ | ||
export class BaseNavigationModeFactory implements NavigationModeFactory { | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public create(wizard: WizardComponent, navigationModeInput: NavigationModeInput): NavigationMode { | ||
let navigationModeName: string; | ||
if (typeof navigationModeInput === 'function') { | ||
// input is a function | ||
return navigationModeInput(wizard); | ||
} else { | ||
// input is a name | ||
navigationModeName = navigationModeInput; | ||
} | ||
// create NavigationMode by name | ||
return this.createByName(wizard, navigationModeName); | ||
} | ||
|
||
/** | ||
* Create a [[NavigationMode]] for the given wizard instance by a navigation mode name | ||
* | ||
* @param wizard The wizard componenent where the created [[NavigationMode]] will be used | ||
* @param navigationModeInput The name of a built-in navigation mode or a custom navigation mode | ||
* @returns The created [[NavigationMode]] | ||
*/ | ||
protected createByName(wizard: WizardComponent, navigationModeInput: string): NavigationMode { | ||
switch (navigationModeInput) { | ||
case 'free': | ||
return new FreeNavigationMode(wizard.model); | ||
case 'semi-strict': | ||
return new SemiStrictNavigationMode(wizard.model); | ||
case 'strict': | ||
return new StrictNavigationMode(wizard.model); | ||
default: | ||
return !navigationModeInput ? this.createDefault(wizard) : this.createUnknown(wizard, navigationModeInput); | ||
} | ||
} | ||
|
||
/** | ||
* Create a [[NavigationMode]] for the given wizard instance which does not have a configured navigation mode | ||
* | ||
* @param wizard The wizard componenent where the created [[NavigationMode]] will be used | ||
* @returns The created [[NavigationMode]] | ||
*/ | ||
protected createDefault(wizard: WizardComponent): NavigationMode { | ||
return new StrictNavigationMode(wizard.model); | ||
} | ||
|
||
/** | ||
* Create a [[NavigationMode]] for the given wizard instance by a not recognized navigation mode name | ||
* | ||
* The base implementation always throws an Error. | ||
* | ||
* @param wizard The wizard componenent where the created [[NavigationMode]] will be used | ||
* @param navigationModeInput The name of a custom navigation mode | ||
* @returns The created [[NavigationMode]] | ||
*/ | ||
protected createUnknown(wizard: WizardComponent, navigationModeInput: string): NavigationMode { | ||
throw new Error(`Unknown navigation mode name: ${navigationModeInput}`); | ||
} | ||
} |
Oops, something went wrong.