Skip to content

Commit

Permalink
Split the State type into ScenariosStateRoot and ScenariosStateDerived
Browse files Browse the repository at this point in the history
  • Loading branch information
lolmaus committed Sep 4, 2023
1 parent 690329a commit 1781d48
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,31 @@ export type CallbackMutateProject = (project: Project) => void | Promise<void>;

export { Project };

type State =
| {
type: 'root';
callbackCreateProject: CallbackCreateProject;
}
| {
type: 'derived';
parent: Scenarios;
variants: Record<string, CallbackMutateProject[]>;
};
/**
* One of possible arguments used to instantiate {@link Scenarios}.
*
* Normally you don't need this as {@link Scenarios} is not supposed to be instantiated by hand.
* Instead, you use its static methods.
*/
export interface ScenariosStateRoot {
type: 'root';
callbackCreateProject: CallbackCreateProject;
}

/**
* One of possible arguments used to instantiate {@link Scenarios}.
*
* Normally you don't need this as {@link Scenarios} is not supposed to be instantiated by hand.
* Instead, you use its static methods.
*/
export interface ScenariosStateDerived {
type: 'derived';
parent: Scenarios;
variants: Record<string, CallbackMutateProject[]>;
}

export class Scenarios {
private constructor(private state: State) {}
private constructor(private state: ScenariosStateRoot | ScenariosStateDerived) {}

static fromDir(appPath: string, as: 'app' | 'lib' = 'app'): Scenarios {
return new this({
Expand Down

0 comments on commit 1781d48

Please sign in to comment.