diff options
| author | Eleanor Eng <eleanor_eng@brown.edu> | 2019-05-04 16:44:22 -0400 |
|---|---|---|
| committer | Eleanor Eng <eleanor_eng@brown.edu> | 2019-05-04 16:44:40 -0400 |
| commit | cecd09917f23fc83c87cffc4fddf5fe1f8331bac (patch) | |
| tree | ab7144d36046aaada287c2ce14d2fe7722585dce /src/new_fields/URLField.ts | |
| parent | 0bf0b028b1af8b9481e369c754277af5fb8b3fcd (diff) | |
| parent | 1ccabe155cb4f23c0aa7e37f91cd4a303008b8c7 (diff) | |
merge with master
Diffstat (limited to 'src/new_fields/URLField.ts')
| -rw-r--r-- | src/new_fields/URLField.ts | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/new_fields/URLField.ts b/src/new_fields/URLField.ts new file mode 100644 index 000000000..d00a95a16 --- /dev/null +++ b/src/new_fields/URLField.ts @@ -0,0 +1,34 @@ +import { Deserializable } from "../client/util/SerializationHelper"; +import { serializable, custom } from "serializr"; +import { ObjectField, Copy } from "./ObjectField"; + +function url() { + return custom( + function (value: URL) { + return value.href; + }, + function (jsonValue: string) { + return new URL(jsonValue); + } + ); +} + +export class URLField extends ObjectField { + @serializable(url()) + readonly url: URL; + + constructor(url: URL) { + super(); + this.url = url; + } + + [Copy](): this { + return new (this.constructor as any)(this.url); + } +} + +@Deserializable("audio") export class AudioField extends URLField { } +@Deserializable("image") export class ImageField extends URLField { } +@Deserializable("video") export class VideoField extends URLField { } +@Deserializable("pdf") export class PdfField extends URLField { } +@Deserializable("web") export class WebField extends URLField { }
\ No newline at end of file |
