aboutsummaryrefslogtreecommitdiff
path: root/src/new_fields/URLField.ts
diff options
context:
space:
mode:
authoryipstanley <stanley_yip@brown.edu>2019-06-04 14:01:08 -0400
committeryipstanley <stanley_yip@brown.edu>2019-06-04 14:01:08 -0400
commitb33ee6461b4aad420d52600946bee03dcf480e06 (patch)
tree275e6eaa3beb791a6110522efab79b4fa7a6454a /src/new_fields/URLField.ts
parent1fb7a7bc185c1ba9bbe0f21ad5e16cf19235b2da (diff)
parent7d3ef1c914cc1cc0b6c05b14773a8b83e1b95c96 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into pdf_impl
Diffstat (limited to 'src/new_fields/URLField.ts')
-rw-r--r--src/new_fields/URLField.ts16
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);
}