diff options
author | bob <bcz@cs.brown.edu> | 2019-06-11 10:53:36 -0400 |
---|---|---|
committer | bob <bcz@cs.brown.edu> | 2019-06-11 10:53:36 -0400 |
commit | 95674ee7f68782d1ce85858120efea956825bcb9 (patch) | |
tree | 0d2ddc9838b45278d6533099f7030a9713d6413f /src/new_fields/URLField.ts | |
parent | 4dacd1220e6a0ef73167f187f52f3b4c222c2586 (diff) | |
parent | 06d5bb5c65da6f4a115ebf8118989115420bccef (diff) |
merged embedded linking with master
Diffstat (limited to 'src/new_fields/URLField.ts')
-rw-r--r-- | src/new_fields/URLField.ts | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/new_fields/URLField.ts b/src/new_fields/URLField.ts index d00a95a16..4a2841fb6 100644 --- a/src/new_fields/URLField.ts +++ b/src/new_fields/URLField.ts @@ -1,6 +1,7 @@ import { Deserializable } from "../client/util/SerializationHelper"; import { serializable, custom } from "serializr"; -import { ObjectField, Copy } from "./ObjectField"; +import { ObjectField } from "./ObjectField"; +import { ToScriptString, Copy } from "./FieldSymbols"; function url() { return custom( @@ -13,15 +14,24 @@ function url() { ); } -export class URLField extends ObjectField { +export abstract class URLField extends ObjectField { @serializable(url()) readonly url: URL; - constructor(url: URL) { + constructor(url: string); + constructor(url: URL); + constructor(url: URL | string) { super(); + if (typeof url === "string") { + url = new URL(url); + } this.url = url; } + [ToScriptString]() { + return `new ${this.constructor.name}("${this.url.href}")`; + } + [Copy](): this { return new (this.constructor as any)(this.url); } |