aboutsummaryrefslogtreecommitdiff
path: root/src/fields
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields')
-rw-r--r--src/fields/BasicField.ts1
-rw-r--r--src/fields/Document.ts14
-rw-r--r--src/fields/DocumentReference.ts4
-rw-r--r--src/fields/Field.ts3
-rw-r--r--src/fields/ImageField.ts4
-rw-r--r--src/fields/Key.ts6
-rw-r--r--src/fields/ListField.ts5
-rw-r--r--src/fields/NumberField.ts5
-rw-r--r--src/fields/RichTextField.ts5
-rw-r--r--src/fields/TextField.ts5
10 files changed, 29 insertions, 23 deletions
diff --git a/src/fields/BasicField.ts b/src/fields/BasicField.ts
index 9476f5d21..4b68ba01f 100644
--- a/src/fields/BasicField.ts
+++ b/src/fields/BasicField.ts
@@ -7,6 +7,7 @@ export abstract class BasicField<T> extends Field {
super(id);
this.data = data;
+ Server.UpdateField(this)
}
@observable
diff --git a/src/fields/Document.ts b/src/fields/Document.ts
index 56ac3c471..cb4f6f25c 100644
--- a/src/fields/Document.ts
+++ b/src/fields/Document.ts
@@ -8,12 +8,17 @@ import { findDOMNode } from "react-dom";
import { Server } from "../client/Server";
import { Types } from "../server/Message";
import { ObjectID } from "bson";
-import { Utils } from "../Utils";
export class Document extends Field {
public fields: ObservableMap<Key, Opt<Field>> = new ObservableMap();
public _proxies: ObservableMap<string, FIELD_ID> = new ObservableMap();
+ constructor(id?: string) {
+ super(id)
+
+ Server.UpdateField(this)
+ }
+
@computed
public get Title() {
return this.GetText(KeyStore.Title, "<untitled>");
@@ -89,9 +94,11 @@ export class Document extends Field {
Set(key: Key, field: Field | undefined): void {
if (field) {
this.fields.set(key, field);
+ this._proxies.set(key.Id, field.Id)
// Server.AddDocumentField(this, key, field);
} else {
this.fields.delete(key);
+ this._proxies.delete(key.Id)
// Server.DeleteDocumentField(this, key);
}
Server.UpdateField(this);
@@ -159,13 +166,15 @@ export class Document extends Field {
throw new Error("Method not implemented.");
}
- ToJson(): { type: Types, data: [string, string][], _id: ObjectID } {
+ ToJson(): { type: Types, data: [string, string][], _id: string } {
+ console.log(this.fields)
let fields: [string, string][] = []
this._proxies.forEach((field, key) => {
if (field) {
fields.push([key, field as string])
}
});
+ console.log(fields)
return {
type: Types.Document,
@@ -173,5 +182,4 @@ export class Document extends Field {
_id: this.Id
}
}
-
} \ No newline at end of file
diff --git a/src/fields/DocumentReference.ts b/src/fields/DocumentReference.ts
index b3d8e059d..b1edd1dff 100644
--- a/src/fields/DocumentReference.ts
+++ b/src/fields/DocumentReference.ts
@@ -43,11 +43,11 @@ export class DocumentReference extends Field {
return "";
}
- ToJson(): { type: Types, data: FIELD_ID, _id: ObjectID } {
+ ToJson(): { type: Types, data: FIELD_ID, _id: string } {
return {
type: Types.DocumentReference,
data: this.document.Id,
- _id: new ObjectID(this.Id)
+ _id: this.Id
}
}
} \ No newline at end of file
diff --git a/src/fields/Field.ts b/src/fields/Field.ts
index 4b9d996ac..5a65e35b9 100644
--- a/src/fields/Field.ts
+++ b/src/fields/Field.ts
@@ -9,7 +9,6 @@ import { ImageField } from "./ImageField";
import { ListField } from "./ListField";
import { Document } from "./Document";
import { Server } from "../client/Server";
-import { ObjectID } from "bson";
export function Cast<T extends Field>(field: FieldValue<Field>, ctor: { new(): T }): Opt<T> {
if (field) {
@@ -65,5 +64,5 @@ export abstract class Field {
abstract Copy(): Field;
- abstract ToJson(): { _id: ObjectID, type: Types, data: any }
+ abstract ToJson(): { _id: string, type: Types, data: any }
} \ No newline at end of file
diff --git a/src/fields/ImageField.ts b/src/fields/ImageField.ts
index 30fe0970b..12503b2ec 100644
--- a/src/fields/ImageField.ts
+++ b/src/fields/ImageField.ts
@@ -20,11 +20,11 @@ export class ImageField extends BasicField<URL> {
return new ImageField(this.Data);
}
- ToJson(): { type: Types, data: URL, _id: ObjectID } {
+ ToJson(): { type: Types, data: URL, _id: string } {
return {
type: Types.Image,
data: this.Data,
- _id: new ObjectID(this.Id)
+ _id: this.Id
}
}
} \ No newline at end of file
diff --git a/src/fields/Key.ts b/src/fields/Key.ts
index ffcbfc8b4..1e878a361 100644
--- a/src/fields/Key.ts
+++ b/src/fields/Key.ts
@@ -3,6 +3,7 @@ import { Utils } from "../Utils";
import { observable } from "mobx";
import { Types } from "../server/Message";
import { ObjectID } from "bson";
+import { Server } from "../client/Server";
export class Key extends Field {
private name: string;
@@ -15,6 +16,7 @@ export class Key extends Field {
super(id || Utils.GenerateDeterministicGuid(name));
this.name = name;
+ Server.UpdateField(this)
}
TrySetValue(value: any): boolean {
@@ -33,11 +35,11 @@ export class Key extends Field {
return name;
}
- ToJson(): { type: Types, data: string, _id: ObjectID } {
+ ToJson(): { type: Types, data: string, _id: string } {
return {
type: Types.Key,
data: this.name,
- _id: new ObjectID(this.Id)
+ _id: this.Id
}
}
}
diff --git a/src/fields/ListField.ts b/src/fields/ListField.ts
index e98ced902..cf8a1ba8b 100644
--- a/src/fields/ListField.ts
+++ b/src/fields/ListField.ts
@@ -1,7 +1,6 @@
import { Field, FIELD_ID } from "./Field";
import { BasicField } from "./BasicField";
import { Types } from "../server/Message";
-import { ObjectId } from "bson";
export class ListField<T extends Field> extends BasicField<T[]> {
constructor(data: T[] = [], id: FIELD_ID = undefined) {
@@ -16,11 +15,11 @@ export class ListField<T extends Field> extends BasicField<T[]> {
return new ListField<T>(this.Data);
}
- ToJson(): { type: Types, data: T[], _id: ObjectId } {
+ ToJson(): { type: Types, data: T[], _id: string } {
return {
type: Types.List,
data: this.Data,
- _id: new ObjectId(this.Id)
+ _id: this.Id
}
}
} \ No newline at end of file
diff --git a/src/fields/NumberField.ts b/src/fields/NumberField.ts
index ce07a18b8..7fa9ec2e4 100644
--- a/src/fields/NumberField.ts
+++ b/src/fields/NumberField.ts
@@ -1,7 +1,6 @@
import { BasicField } from "./BasicField"
import { Types } from "../server/Message";
import { FIELD_ID } from "./Field";
-import { ObjectID } from "bson";
export class NumberField extends BasicField<number> {
constructor(data: number = 0, id: FIELD_ID = undefined) {
@@ -16,9 +15,9 @@ export class NumberField extends BasicField<number> {
return new NumberField(this.Data);
}
- ToJson(): { _id: ObjectID, type: Types, data: number } {
+ ToJson(): { _id: string, type: Types, data: number } {
return {
- _id: new ObjectID(this.Id),
+ _id: this.Id,
type: Types.Number,
data: this.Data
}
diff --git a/src/fields/RichTextField.ts b/src/fields/RichTextField.ts
index a7ea1f2ce..3c6151009 100644
--- a/src/fields/RichTextField.ts
+++ b/src/fields/RichTextField.ts
@@ -1,7 +1,6 @@
import { BasicField } from "./BasicField";
import { Types } from "../server/Message";
import { FIELD_ID } from "./Field";
-import { ObjectID } from "bson";
export class RichTextField extends BasicField<string> {
constructor(data: string = "", id: FIELD_ID = undefined) {
@@ -16,11 +15,11 @@ export class RichTextField extends BasicField<string> {
return new RichTextField(this.Data);
}
- ToJson(): { type: Types, data: string, _id: ObjectID } {
+ ToJson(): { type: Types, data: string, _id: string } {
return {
type: Types.RichText,
data: this.Data,
- _id: new ObjectID(this.Id)
+ _id: this.Id
}
}
diff --git a/src/fields/TextField.ts b/src/fields/TextField.ts
index 692b746d1..f2b277298 100644
--- a/src/fields/TextField.ts
+++ b/src/fields/TextField.ts
@@ -1,7 +1,6 @@
import { BasicField } from "./BasicField"
import { FIELD_ID } from "./Field";
import { Types } from "../server/Message";
-import { ObjectID } from "bson";
export class TextField extends BasicField<string> {
constructor(data: string = "", id: FIELD_ID = undefined) {
@@ -16,11 +15,11 @@ export class TextField extends BasicField<string> {
return new TextField(this.Data);
}
- ToJson(): { type: Types, data: string, _id: ObjectID } {
+ ToJson(): { type: Types, data: string, _id: string } {
return {
type: Types.Text,
data: this.Data,
- _id: new ObjectID(this.Id)
+ _id: this.Id
}
}
}