This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(store): property type system, setter, and coercing
- Loading branch information
1 parent
d1a61a7
commit af2a581
Showing
18 changed files
with
326 additions
and
41 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
5 changes: 3 additions & 2 deletions
5
src/store/page/element_value.ts → src/store/page/property_value.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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
import { PageElement } from './page_element'; | ||
|
||
export type ElementValue = | ||
export type PropertyValue = | ||
// tslint:disable-next-line:no-any | ||
| { [id: string]: any } | ||
| string | ||
| string[] | ||
| number | ||
| number[] | ||
| boolean | ||
| object | ||
| PageElement | ||
| undefined | ||
| null; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Property } from '.'; | ||
|
||
export class BooleanProperty extends Property { | ||
public constructor(id: string, name: string, required: boolean) { | ||
super(id, name, required); | ||
} | ||
|
||
// tslint:disable-next-line:no-any | ||
public coerceValue(value: any): any { | ||
return value && (value === true || value === 'true' || value === 1); | ||
} | ||
|
||
public getType(): string { | ||
return 'boolean'; | ||
} | ||
|
||
public toString(): string { | ||
return `BooleanProperty(id="${this.getId()}", required="${this.isRequired()}")`; | ||
} | ||
} |
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,32 @@ | ||
import { Option } from './option'; | ||
import { Property } from '.'; | ||
|
||
export class EnumProperty extends Property { | ||
private options: Option[]; | ||
|
||
public constructor(id: string, name: string, required: boolean, options: Option[]) { | ||
super(id, name, required); | ||
this.options = options; | ||
} | ||
|
||
// tslint:disable-next-line:no-any | ||
public coerceValue(value: any): any { | ||
if (value === null || value === undefined || value === '') { | ||
return undefined; | ||
} | ||
|
||
return String(value); | ||
} | ||
|
||
public getOptions(): Option[] { | ||
return this.options; | ||
} | ||
|
||
public getType(): string { | ||
return 'enum'; | ||
} | ||
|
||
public toString(): string { | ||
return `EnumProperty(id="${this.getId()}", required="${this.isRequired()}")`; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Property } from '.'; | ||
|
||
export class NumberArrayProperty extends Property { | ||
public constructor(id: string, name: string, required: boolean) { | ||
super(id, name, required); | ||
} | ||
|
||
// tslint:disable-next-line:no-any | ||
public coerceValue(value: any): any { | ||
// tslint:disable-next-line:no-any | ||
return this.coerceArrayValue(value, (element: any) => parseFloat(value)); | ||
} | ||
|
||
public getType(): string { | ||
return 'number[]'; | ||
} | ||
|
||
public toString(): string { | ||
return `NumberArrayProperty(id="${this.getId()}", required="${this.isRequired()}")`; | ||
} | ||
} |
Oops, something went wrong.