Skip to content

Commit

Permalink
feat(piece): add options field to read raw options (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Oct 17, 2021
1 parent a3f81e1 commit e994d8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/lib/structures/AliasPiece.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface AliasPieceOptions extends PieceOptions {
/**
* The piece to be stored in {@link AliasStore} instances.
*/
export class AliasPiece extends Piece {
export class AliasPiece<O extends AliasPieceOptions = AliasPieceOptions> extends Piece<O> {
/**
* The aliases for the piece.
*/
Expand All @@ -38,4 +38,5 @@ export class AliasPiece extends Piece {
*/
export interface AliasPieceJSON extends PieceJSON {
aliases: string[];
options: AliasPieceOptions;
}
12 changes: 10 additions & 2 deletions src/lib/structures/Piece.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface PieceOptions {
/**
* The piece to be stored in {@link Store} instances.
*/
export class Piece {
export class Piece<O extends PieceOptions = PieceOptions> {
/**
* The store that contains the piece.
*/
Expand All @@ -70,11 +70,17 @@ export class Piece {
*/
public enabled: boolean;

/**
* The raw options passed to this {@link Piece}
*/
public readonly options: O;

public constructor(context: PieceContext, options: PieceOptions = {}) {
this.store = context.store;
this.location = new PieceLocation(context.path, context.root);
this.name = options.name ?? context.name;
this.enabled = options.enabled ?? true;
this.options = options as O;
}

/**
Expand Down Expand Up @@ -123,7 +129,8 @@ export class Piece {
return {
location: this.location.toJSON(),
name: this.name,
enabled: this.enabled
enabled: this.enabled,
options: this.options
};
}
}
Expand All @@ -135,4 +142,5 @@ export interface PieceJSON {
location: PieceLocationJSON;
name: string;
enabled: boolean;
options: PieceOptions;
}

0 comments on commit e994d8c

Please sign in to comment.