aboutsummaryrefslogtreecommitdiff
path: root/src/fields
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields')
-rw-r--r--src/fields/BasicField.ts2
-rw-r--r--src/fields/Document.ts13
-rw-r--r--src/fields/DocumentReference.ts5
-rw-r--r--src/fields/Field.ts43
-rw-r--r--src/fields/ImageField.ts5
-rw-r--r--src/fields/Key.ts5
-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, 33 insertions, 60 deletions
diff --git a/src/fields/BasicField.ts b/src/fields/BasicField.ts
index 40ead0953..9476f5d21 100644
--- a/src/fields/BasicField.ts
+++ b/src/fields/BasicField.ts
@@ -1,5 +1,6 @@
import { Field, FIELD_ID } from "./Field"
import { observable, computed, action } from "mobx";
+import { Server } from "../client/Server";
export abstract class BasicField<T> extends Field {
constructor(data: T, id: FIELD_ID = undefined) {
@@ -21,6 +22,7 @@ export abstract class BasicField<T> extends Field {
return;
}
this.data = value;
+ Server.UpdateField(this);
}
@action
diff --git a/src/fields/Document.ts b/src/fields/Document.ts
index 99cd03813..56ac3c471 100644
--- a/src/fields/Document.ts
+++ b/src/fields/Document.ts
@@ -7,6 +7,8 @@ import { ListField } from "./ListField";
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();
@@ -87,11 +89,12 @@ export class Document extends Field {
Set(key: Key, field: Field | undefined): void {
if (field) {
this.fields.set(key, field);
- Server.AddDocumentField(this, key, field);
+ // Server.AddDocumentField(this, key, field);
} else {
this.fields.delete(key);
- Server.DeleteDocumentField(this, key);
+ // Server.DeleteDocumentField(this, key);
}
+ Server.UpdateField(this);
}
@action
@@ -101,7 +104,7 @@ export class Document extends Field {
//if (field != WAITING) { // do we want to wait for the field to come back from the server to set it, or do we overwrite?
if (field instanceof ctor) {
field.Data = value;
- Server.SetFieldValue(field, value);
+ // Server.SetFieldValue(field, value);
} else if (!field || replaceWrongType) {
let newField = new ctor();
newField.Data = value;
@@ -156,7 +159,7 @@ export class Document extends Field {
throw new Error("Method not implemented.");
}
- ToJson(): { type: Types, data: [string, string][], id: string } {
+ ToJson(): { type: Types, data: [string, string][], _id: ObjectID } {
let fields: [string, string][] = []
this._proxies.forEach((field, key) => {
if (field) {
@@ -167,7 +170,7 @@ export class Document extends Field {
return {
type: Types.Document,
data: fields,
- id: this.Id as string
+ _id: this.Id
}
}
diff --git a/src/fields/DocumentReference.ts b/src/fields/DocumentReference.ts
index ab4c4644e..b3d8e059d 100644
--- a/src/fields/DocumentReference.ts
+++ b/src/fields/DocumentReference.ts
@@ -2,6 +2,7 @@ import { Field, Opt, FieldValue, FIELD_ID } from "./Field";
import { Document } from "./Document";
import { Key } from "./Key";
import { Types } from "../server/Message";
+import { ObjectID } from "bson";
export class DocumentReference extends Field {
get Key(): Key {
@@ -42,11 +43,11 @@ export class DocumentReference extends Field {
return "";
}
- ToJson(): { type: Types, data: FIELD_ID, id: string } {
+ ToJson(): { type: Types, data: FIELD_ID, _id: ObjectID } {
return {
type: Types.DocumentReference,
data: this.document.Id,
- id: this.Id as string
+ _id: new ObjectID(this.Id)
}
}
} \ No newline at end of file
diff --git a/src/fields/Field.ts b/src/fields/Field.ts
index 1a5cfb29c..4b9d996ac 100644
--- a/src/fields/Field.ts
+++ b/src/fields/Field.ts
@@ -9,6 +9,7 @@ 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) {
@@ -64,45 +65,5 @@ export abstract class Field {
abstract Copy(): Field;
- abstract ToJson(): { id: string, type: Types, data: any }
-
- public static FromJson(obj: { id: string, type: number, data: any }): Field {
- let data: any = obj.data
- let id: string = obj.id
-
- switch (obj.type) {
- case Types.Number:
- return new NumberField(data, id)
- case Types.Text:
- return new TextField(data, id)
- case Types.RichText:
- return new RichTextField(data, id)
- case Types.Key:
- return new Key(data, id)
- case Types.Image:
- return new ImageField(data, id)
- case Types.List:
- return new ListField(data, id)
- case Types.Document:
- let doc: Document = new Document(id)
- let fields: [string, string][] = data as [string, string][]
- fields.forEach(element => {
- doc._proxies.set(element[0], element[1]);
- let keyId: string = element[0]
- let valueId: string = element[1]
- Server.GetField(keyId, (key: Field) => {
- if (key instanceof Key) {
- Server.GetField(valueId, (field: Field) => {
- doc.Set(key as Key, field)
- })
- }
- else {
- console.log("how did you get a key that isnt a key wtf")
- }
- })
- });
- return doc
- }
- return new TextField(data, id)
- }
+ abstract ToJson(): { _id: ObjectID, type: Types, data: any }
} \ No newline at end of file
diff --git a/src/fields/ImageField.ts b/src/fields/ImageField.ts
index 8ffc6d680..30fe0970b 100644
--- a/src/fields/ImageField.ts
+++ b/src/fields/ImageField.ts
@@ -1,6 +1,7 @@
import { BasicField } from "./BasicField";
import { Field, FIELD_ID } from "./Field";
import { Types } from "../server/Message";
+import { ObjectID } from "bson";
export class ImageField extends BasicField<URL> {
constructor(data: URL | undefined = undefined, id: FIELD_ID = undefined) {
@@ -19,11 +20,11 @@ export class ImageField extends BasicField<URL> {
return new ImageField(this.Data);
}
- ToJson(): { type: Types, data: URL, id: string } {
+ ToJson(): { type: Types, data: URL, _id: ObjectID } {
return {
type: Types.Image,
data: this.Data,
- id: this.Id as string
+ _id: new ObjectID(this.Id)
}
}
} \ No newline at end of file
diff --git a/src/fields/Key.ts b/src/fields/Key.ts
index 084b444a6..ffcbfc8b4 100644
--- a/src/fields/Key.ts
+++ b/src/fields/Key.ts
@@ -2,6 +2,7 @@ import { Field, FIELD_ID } from "./Field"
import { Utils } from "../Utils";
import { observable } from "mobx";
import { Types } from "../server/Message";
+import { ObjectID } from "bson";
export class Key extends Field {
private name: string;
@@ -32,11 +33,11 @@ export class Key extends Field {
return name;
}
- ToJson(): { type: Types, data: string, id: string } {
+ ToJson(): { type: Types, data: string, _id: ObjectID } {
return {
type: Types.Key,
data: this.name,
- id: this.Id as string
+ _id: new ObjectID(this.Id)
}
}
}
diff --git a/src/fields/ListField.ts b/src/fields/ListField.ts
index 925f8c7f4..e98ced902 100644
--- a/src/fields/ListField.ts
+++ b/src/fields/ListField.ts
@@ -1,6 +1,7 @@
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) {
@@ -15,11 +16,11 @@ export class ListField<T extends Field> extends BasicField<T[]> {
return new ListField<T>(this.Data);
}
- ToJson(): { type: Types, data: T[], id: string } {
+ ToJson(): { type: Types, data: T[], _id: ObjectId } {
return {
type: Types.List,
data: this.Data,
- id: this.Id as string
+ _id: new ObjectId(this.Id)
}
}
} \ No newline at end of file
diff --git a/src/fields/NumberField.ts b/src/fields/NumberField.ts
index 22abb23e9..ce07a18b8 100644
--- a/src/fields/NumberField.ts
+++ b/src/fields/NumberField.ts
@@ -1,6 +1,7 @@
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) {
@@ -15,9 +16,9 @@ export class NumberField extends BasicField<number> {
return new NumberField(this.Data);
}
- ToJson(): { id: string, type: Types, data: number } {
+ ToJson(): { _id: ObjectID, type: Types, data: number } {
return {
- id: this.Id as string,
+ _id: new ObjectID(this.Id),
type: Types.Number,
data: this.Data
}
diff --git a/src/fields/RichTextField.ts b/src/fields/RichTextField.ts
index f7c3f2430..a7ea1f2ce 100644
--- a/src/fields/RichTextField.ts
+++ b/src/fields/RichTextField.ts
@@ -1,6 +1,7 @@
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) {
@@ -15,11 +16,11 @@ export class RichTextField extends BasicField<string> {
return new RichTextField(this.Data);
}
- ToJson(): { type: Types, data: string, id: string } {
+ ToJson(): { type: Types, data: string, _id: ObjectID } {
return {
type: Types.RichText,
data: this.Data,
- id: this.Id as string
+ _id: new ObjectID(this.Id)
}
}
diff --git a/src/fields/TextField.ts b/src/fields/TextField.ts
index 5f2cd1db8..692b746d1 100644
--- a/src/fields/TextField.ts
+++ b/src/fields/TextField.ts
@@ -1,6 +1,7 @@
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) {
@@ -15,11 +16,11 @@ export class TextField extends BasicField<string> {
return new TextField(this.Data);
}
- ToJson(): { type: Types, data: string, id: string } {
+ ToJson(): { type: Types, data: string, _id: ObjectID } {
return {
type: Types.Text,
data: this.Data,
- id: this.Id as string
+ _id: new ObjectID(this.Id)
}
}
}