aboutsummaryrefslogtreecommitdiff
path: root/src/fields
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields')
-rw-r--r--src/fields/BasicField.ts4
-rw-r--r--src/fields/Document.ts30
-rw-r--r--src/fields/DocumentReference.ts4
-rw-r--r--src/fields/Field.ts10
-rw-r--r--src/fields/ImageField.ts4
-rw-r--r--src/fields/Key.ts2
-rw-r--r--src/fields/KeyStore.ts8
-rw-r--r--src/fields/ListField.ts4
-rw-r--r--src/fields/NumberField.ts4
-rw-r--r--src/fields/RichTextField.ts4
-rw-r--r--src/fields/TextField.ts4
11 files changed, 49 insertions, 29 deletions
diff --git a/src/fields/BasicField.ts b/src/fields/BasicField.ts
index 15eb067a0..8728b7145 100644
--- a/src/fields/BasicField.ts
+++ b/src/fields/BasicField.ts
@@ -1,9 +1,9 @@
-import { Field, FIELD_ID } from "./Field"
+import { Field, FieldId } from "./Field"
import { observable, computed, action } from "mobx";
import { Server } from "../client/Server";
export abstract class BasicField<T> extends Field {
- constructor(data: T, save: boolean, id: FIELD_ID = undefined) {
+ constructor(data: T, save: boolean, id?: FieldId) {
super(id);
this.data = data;
diff --git a/src/fields/Document.ts b/src/fields/Document.ts
index 3067621be..fcc8adbcf 100644
--- a/src/fields/Document.ts
+++ b/src/fields/Document.ts
@@ -1,8 +1,8 @@
-import { Field, Cast, Opt, FieldWaiting, FIELD_ID, FieldValue } from "./Field"
import { Key } from "./Key"
import { KeyStore } from "./KeyStore";
+import { Field, Cast, FieldWaiting, FieldValue, FieldId } from "./Field"
import { NumberField } from "./NumberField";
-import { ObservableMap, computed, action, observable } from "mobx";
+import { ObservableMap, computed, action } from "mobx";
import { TextField } from "./TextField";
import { ListField } from "./ListField";
import { Server } from "../client/Server";
@@ -10,7 +10,7 @@ import { Types } from "../server/Message";
export class Document extends Field {
public fields: ObservableMap<string, { key: Key, field: Field }> = new ObservableMap();
- public _proxies: ObservableMap<string, FIELD_ID> = new ObservableMap();
+ public _proxies: ObservableMap<string, FieldId> = new ObservableMap();
constructor(id?: string, save: boolean = true) {
super(id)
@@ -40,7 +40,17 @@ export class Document extends Field {
if (this.fields.has(key.Id)) {
field = this.fields.get(key.Id)!.field;
} else if (this._proxies.has(key.Id)) {
- field = Server.GetDocumentField(this, key);
+ Server.GetDocumentField(this, key);
+ /*
+ The field might have been instantly filled from the cache
+ Maybe we want to just switch back to returning the value
+ from Server.GetDocumentField if it's in the cache
+ */
+ if (this.fields.has(key.Id)) {
+ field = this.fields.get(key.Id)!.field;
+ } else {
+ field = "<Waiting>";
+ }
}
} else {
let doc: FieldValue<Document> = this;
@@ -49,7 +59,17 @@ export class Document extends Field {
let curProxy = doc._proxies.get(key.Id);
if (!curField || (curProxy && curField.field.Id !== curProxy)) {
if (curProxy) {
- field = Server.GetDocumentField(doc, key);
+ Server.GetDocumentField(doc, key);
+ /*
+ The field might have been instantly filled from the cache
+ Maybe we want to just switch back to returning the value
+ from Server.GetDocumentField if it's in the cache
+ */
+ if (this.fields.has(key.Id)) {
+ field = this.fields.get(key.Id)!.field;
+ } else {
+ field = "<Waiting>";
+ }
break;
}
if ((doc.fields.has(KeyStore.Prototype.Id) || doc._proxies.has(KeyStore.Prototype.Id))) {
diff --git a/src/fields/DocumentReference.ts b/src/fields/DocumentReference.ts
index 4096cbb92..9d3c209b4 100644
--- a/src/fields/DocumentReference.ts
+++ b/src/fields/DocumentReference.ts
@@ -1,4 +1,4 @@
-import { Field, Opt, FieldValue, FIELD_ID } from "./Field";
+import { Field, Opt, FieldValue, FieldId } from "./Field";
import { Document } from "./Document";
import { Key } from "./Key";
import { Types } from "../server/Message";
@@ -47,7 +47,7 @@ export class DocumentReference extends Field {
return "";
}
- ToJson(): { type: Types, data: FIELD_ID, _id: string } {
+ ToJson(): { type: Types, data: FieldId, _id: string } {
return {
type: Types.DocumentReference,
data: this.document.Id,
diff --git a/src/fields/Field.ts b/src/fields/Field.ts
index 853fb9327..c7e0232af 100644
--- a/src/fields/Field.ts
+++ b/src/fields/Field.ts
@@ -11,9 +11,9 @@ export function Cast<T extends Field>(field: FieldValue<Field>, ctor: { new(): T
return undefined;
}
-export let FieldWaiting: FIELD_WAITING = "<Waiting>";
+export const FieldWaiting: FIELD_WAITING = "<Waiting>";
export type FIELD_WAITING = "<Waiting>";
-export type FIELD_ID = string | undefined;
+export type FieldId = string;
export type Opt<T> = T | undefined;
export type FieldValue<T> = Opt<T> | FIELD_WAITING;
@@ -24,12 +24,12 @@ export abstract class Field {
callback(this);
}
- private id: string;
- get Id(): string {
+ private id: FieldId;
+ get Id(): FieldId {
return this.id;
}
- constructor(id: FIELD_ID = undefined) {
+ constructor(id: Opt<FieldId> = undefined) {
this.id = id || Utils.GenerateGuid();
}
diff --git a/src/fields/ImageField.ts b/src/fields/ImageField.ts
index aba011199..b2226d55a 100644
--- a/src/fields/ImageField.ts
+++ b/src/fields/ImageField.ts
@@ -1,10 +1,10 @@
import { BasicField } from "./BasicField";
-import { Field, FIELD_ID } from "./Field";
+import { Field, FieldId } 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, save: boolean = true) {
+ constructor(data: URL | undefined = undefined, id?: FieldId, save: boolean = true) {
super(data == undefined ? new URL("http://cs.brown.edu/~bcz/bob_fettucine.jpg") : data, save, id);
}
diff --git a/src/fields/Key.ts b/src/fields/Key.ts
index d3958df2d..c16a00878 100644
--- a/src/fields/Key.ts
+++ b/src/fields/Key.ts
@@ -1,4 +1,4 @@
-import { Field, FIELD_ID } from "./Field"
+import { Field, FieldId } from "./Field"
import { Utils } from "../Utils";
import { observable } from "mobx";
import { Types } from "../server/Message";
diff --git a/src/fields/KeyStore.ts b/src/fields/KeyStore.ts
index 1e0b12729..c7c52f0b0 100644
--- a/src/fields/KeyStore.ts
+++ b/src/fields/KeyStore.ts
@@ -9,16 +9,16 @@ export namespace KeyStore {
export const PanX = new Key("PanX");
export const PanY = new Key("PanY");
export const Scale = new Key("Scale");
+ export const NativeWidth = new Key("NativeWidth");
+ export const NativeHeight = new Key("NativeHeight");
export const Width = new Key("Width");
export const Height = new Key("Height");
export const ZIndex = new Key("ZIndex");
export const Data = new Key("Data");
+ export const Annotations = new Key("Annotations");
export const Layout = new Key("Layout");
+ export const BackgroundLayout = new Key("BackgroundLayout");
export const LayoutKeys = new Key("LayoutKeys");
export const LayoutFields = new Key("LayoutFields");
export const ColumnsKey = new Key("SchemaColumns");
-
- export function Get(name: string): Key {
- return new Key(name)
- }
}
diff --git a/src/fields/ListField.ts b/src/fields/ListField.ts
index 1357dc445..2e192bf90 100644
--- a/src/fields/ListField.ts
+++ b/src/fields/ListField.ts
@@ -1,4 +1,4 @@
-import { Field, FIELD_ID, FieldValue, Opt } from "./Field";
+import { Field, FieldId, FieldValue, Opt } from "./Field";
import { BasicField } from "./BasicField";
import { Types } from "../server/Message";
import { observe, action } from "mobx";
@@ -7,7 +7,7 @@ import { ServerUtils } from "../server/ServerUtil";
export class ListField<T extends Field> extends BasicField<T[]> {
private _proxies: string[] = []
- constructor(data: T[] = [], id: FIELD_ID = undefined, save: boolean = true) {
+ constructor(data: T[] = [], id?: FieldId, save: boolean = true) {
super(data, save, id);
this.updateProxies();
if (save) {
diff --git a/src/fields/NumberField.ts b/src/fields/NumberField.ts
index 29e285201..47dfc74cb 100644
--- a/src/fields/NumberField.ts
+++ b/src/fields/NumberField.ts
@@ -1,9 +1,9 @@
import { BasicField } from "./BasicField"
import { Types } from "../server/Message";
-import { FIELD_ID } from "./Field";
+import { FieldId } from "./Field";
export class NumberField extends BasicField<number> {
- constructor(data: number = 0, id: FIELD_ID = undefined, save: boolean = true) {
+ constructor(data: number = 0, id?: FieldId, save: boolean = true) {
super(data, save, id);
}
diff --git a/src/fields/RichTextField.ts b/src/fields/RichTextField.ts
index 9783107e3..5efb43314 100644
--- a/src/fields/RichTextField.ts
+++ b/src/fields/RichTextField.ts
@@ -1,9 +1,9 @@
import { BasicField } from "./BasicField";
import { Types } from "../server/Message";
-import { FIELD_ID } from "./Field";
+import { FieldId } from "./Field";
export class RichTextField extends BasicField<string> {
- constructor(data: string = "", id: FIELD_ID = undefined, save: boolean = true) {
+ constructor(data: string = "", id?: FieldId, save: boolean = true) {
super(data, save, id);
}
diff --git a/src/fields/TextField.ts b/src/fields/TextField.ts
index efb3c035f..ad96ab6d9 100644
--- a/src/fields/TextField.ts
+++ b/src/fields/TextField.ts
@@ -1,9 +1,9 @@
import { BasicField } from "./BasicField"
-import { FIELD_ID } from "./Field";
+import { FieldId } from "./Field";
import { Types } from "../server/Message";
export class TextField extends BasicField<string> {
- constructor(data: string = "", id: FIELD_ID = undefined, save: boolean = true) {
+ constructor(data: string = "", id?: FieldId, save: boolean = true) {
super(data, save, id);
}