aboutsummaryrefslogtreecommitdiff
path: root/src/fields
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields')
-rw-r--r--src/fields/Document.ts14
-rw-r--r--src/fields/DocumentReference.ts11
-rw-r--r--src/fields/Field.ts13
-rw-r--r--src/fields/ImageField.ts4
-rw-r--r--src/fields/Key.ts3
-rw-r--r--src/fields/ListField.ts4
-rw-r--r--src/fields/RichTextField.ts4
-rw-r--r--src/fields/TextField.ts4
8 files changed, 40 insertions, 17 deletions
diff --git a/src/fields/Document.ts b/src/fields/Document.ts
index 53138eda9..e482df622 100644
--- a/src/fields/Document.ts
+++ b/src/fields/Document.ts
@@ -1,4 +1,4 @@
-import { Field, Cast, Opt, FieldWaiting, FIELD_ID, DOC_ID } from "./Field"
+import { Field, Cast, Opt, FieldWaiting, FIELD_ID, DOC_ID, FieldValue } from "./Field"
import { Key, KeyStore } from "./Key"
import { NumberField } from "./NumberField";
import { ObservableMap, computed, action, observable } from "mobx";
@@ -16,8 +16,8 @@ export class Document extends Field {
return this.GetText(KeyStore.Title, "<untitled>");
}
- Get(key: Key, ignoreProto: boolean = false): Opt<Field> {
- let field: Opt<Field>;
+ Get(key: Key, ignoreProto: boolean = false): FieldValue<Field> {
+ let field: FieldValue<Field>;
if (ignoreProto) {
if (this.fields.has(key)) {
field = this.fields.get(key);
@@ -25,7 +25,7 @@ export class Document extends Field {
field = Server.GetDocumentField(this, key);
}
} else {
- let doc: Opt<Document> = this;
+ let doc: FieldValue<Document> = this;
while (doc && doc != FieldWaiting && field != FieldWaiting) {
if (!doc.fields.has(key)) {
if (doc._proxies.has(key)) {
@@ -46,7 +46,7 @@ export class Document extends Field {
return field;
}
- GetT<T extends Field = Field>(key: Key, ctor: { new(...args: any[]): T }, ignoreProto: boolean = false): Opt<T> {
+ GetT<T extends Field = Field>(key: Key, ctor: { new(...args: any[]): T }, ignoreProto: boolean = false): FieldValue<T> {
var getfield = this.Get(key, ignoreProto);
if (getfield != FieldWaiting) {
return Cast(getfield, ctor);
@@ -119,13 +119,13 @@ export class Document extends Field {
this.SetData(key, value, NumberField, replaceWrongType);
}
- GetPrototype(): Opt<Document> {
+ GetPrototype(): FieldValue<Document> {
return this.GetT(KeyStore.Prototype, Document, true);
}
GetAllPrototypes(): Document[] {
let protos: Document[] = [];
- let doc: Opt<Document> = this;
+ let doc: FieldValue<Document> = this;
while (doc && doc != FieldWaiting) {
protos.push(doc);
doc = doc.GetPrototype();
diff --git a/src/fields/DocumentReference.ts b/src/fields/DocumentReference.ts
index 10dac9f92..983b162a3 100644
--- a/src/fields/DocumentReference.ts
+++ b/src/fields/DocumentReference.ts
@@ -1,4 +1,4 @@
-import { Field, Opt } from "./Field";
+import { Field, Opt, FieldValue } from "./Field";
import { Document } from "./Document";
import { Key } from "./Key";
@@ -15,12 +15,12 @@ export class DocumentReference extends Field {
super();
}
- Dereference(): Opt<Field> {
+ Dereference(): FieldValue<Field> {
return this.document.Get(this.key);
}
- DereferenceToRoot(): Opt<Field> {
- let field: Opt<Field> = this;
+ DereferenceToRoot(): FieldValue<Field> {
+ let field: FieldValue<Field> = this;
while (field instanceof DocumentReference) {
field = field.Dereference();
}
@@ -37,5 +37,8 @@ export class DocumentReference extends Field {
throw new Error("Method not implemented.");
}
+ ToScriptString(): string {
+ return "";
+ }
} \ No newline at end of file
diff --git a/src/fields/Field.ts b/src/fields/Field.ts
index 20d8bf5ed..2bfc9d1da 100644
--- a/src/fields/Field.ts
+++ b/src/fields/Field.ts
@@ -1,7 +1,7 @@
import { Utils } from "../Utils";
-export function Cast<T extends Field>(field: Opt<Field>, ctor: { new(): T }): Opt<T> {
+export function Cast<T extends Field>(field: FieldValue<Field>, ctor: { new(): T }): Opt<T> {
if (field) {
if (ctor && field instanceof ctor) {
return field;
@@ -14,7 +14,8 @@ export let FieldWaiting: FIELD_WAITING = "<Waiting>";
export type FIELD_WAITING = "<Waiting>";
export type FIELD_ID = string | undefined;
export type DOC_ID = FIELD_ID;
-export type Opt<T> = T | undefined | FIELD_WAITING;
+export type Opt<T> = T | undefined;
+export type FieldValue<T> = Opt<T> | FIELD_WAITING;
export abstract class Field {
//FieldUpdated: TypedEvent<Opt<FieldUpdatedArgs>> = new TypedEvent<Opt<FieldUpdatedArgs>>();
@@ -28,18 +29,18 @@ export abstract class Field {
this.id = id || Utils.GenerateGuid();
}
- Dereference(): Opt<Field> {
+ Dereference(): FieldValue<Field> {
return this;
}
- DereferenceToRoot(): Opt<Field> {
+ DereferenceToRoot(): FieldValue<Field> {
return this;
}
- DereferenceT<T extends Field = Field>(ctor: { new(): T }): Opt<T> {
+ DereferenceT<T extends Field = Field>(ctor: { new(): T }): FieldValue<T> {
return Cast(this.Dereference(), ctor);
}
- DereferenceToRootT<T extends Field = Field>(ctor: { new(): T }): Opt<T> {
+ DereferenceToRootT<T extends Field = Field>(ctor: { new(): T }): FieldValue<T> {
return Cast(this.DereferenceToRoot(), ctor);
}
diff --git a/src/fields/ImageField.ts b/src/fields/ImageField.ts
index bc2e7cdf4..63baf815b 100644
--- a/src/fields/ImageField.ts
+++ b/src/fields/ImageField.ts
@@ -10,6 +10,10 @@ export class ImageField extends BasicField<URL> {
return this.Data.href;
}
+ ToScriptString(): string {
+ return `new ImageField(${this.Data})`;
+ }
+
Copy(): Field {
return new ImageField(this.Data);
}
diff --git a/src/fields/Key.ts b/src/fields/Key.ts
index 5cd43f55e..993102613 100644
--- a/src/fields/Key.ts
+++ b/src/fields/Key.ts
@@ -27,6 +27,9 @@ export class Key extends Field {
return this;
}
+ ToScriptString(): string {
+ return name;
+ }
}
diff --git a/src/fields/ListField.ts b/src/fields/ListField.ts
index 8607ebe43..8843338c1 100644
--- a/src/fields/ListField.ts
+++ b/src/fields/ListField.ts
@@ -6,6 +6,10 @@ export class ListField<T extends Field> extends BasicField<T[]> {
super(data.slice());
}
+ ToScriptString(): string {
+ return "new ListField([" + this.Data.map(field => field.ToScriptString()).join(", ") + "])";
+ }
+
Copy(): Field {
return new ListField<T>(this.Data);
}
diff --git a/src/fields/RichTextField.ts b/src/fields/RichTextField.ts
index 24c7472d8..4a77c669c 100644
--- a/src/fields/RichTextField.ts
+++ b/src/fields/RichTextField.ts
@@ -5,6 +5,10 @@ export class RichTextField extends BasicField<string> {
super(data);
}
+ ToScriptString(): string {
+ return `new RichTextField(${this.Data})`;
+ }
+
Copy() {
return new RichTextField(this.Data);
}
diff --git a/src/fields/TextField.ts b/src/fields/TextField.ts
index 95825d2ae..11d2ed7cd 100644
--- a/src/fields/TextField.ts
+++ b/src/fields/TextField.ts
@@ -5,6 +5,10 @@ export class TextField extends BasicField<string> {
super(data);
}
+ ToScriptString(): string {
+ return `new TextField("${this.Data}")`;
+ }
+
Copy() {
return new TextField(this.Data);
}