aboutsummaryrefslogtreecommitdiff
path: root/src/fields
diff options
context:
space:
mode:
authorusodhi <61431818+usodhi@users.noreply.github.com>2021-05-13 01:40:40 -0400
committerusodhi <61431818+usodhi@users.noreply.github.com>2021-05-13 01:40:40 -0400
commitfdd5ab800536a8f1dd8acff284bd3a956a4a17ff (patch)
tree62ad87dc41cd8fec6e5d7005e616e6f1f44d242a /src/fields
parenta97cd98786ff5572547430fff6c9a46117423bb1 (diff)
parent66f120531a7e86a7a6bfac30e9c966c3baaed99d (diff)
merging
Diffstat (limited to 'src/fields')
-rw-r--r--src/fields/Doc.ts4
-rw-r--r--src/fields/Schema.ts32
2 files changed, 11 insertions, 25 deletions
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index aa9e57a96..de4c1e5f9 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -914,8 +914,8 @@ export namespace Doc {
}
export function NativeWidth(doc?: Doc, dataDoc?: Doc, useWidth?: boolean) { return !doc ? 0 : NumCast(doc._nativeWidth, NumCast((dataDoc || doc)[Doc.LayoutFieldKey(doc) + "-nativeWidth"], useWidth ? doc[WidthSym]() : 0)); }
export function NativeHeight(doc?: Doc, dataDoc?: Doc, useHeight?: boolean) { return !doc ? 0 : NumCast(doc._nativeHeight, NumCast((dataDoc || doc)[Doc.LayoutFieldKey(doc) + "-nativeHeight"], useHeight ? doc[HeightSym]() : 0)); }
- export function SetNativeWidth(doc: Doc, width: number | undefined) { doc[Doc.LayoutFieldKey(doc) + "-nativeWidth"] = width; }
- export function SetNativeHeight(doc: Doc, height: number | undefined) { doc[Doc.LayoutFieldKey(doc) + "-nativeHeight"] = height; }
+ export function SetNativeWidth(doc: Doc, width: number | undefined, fieldKey?: string) { doc[(fieldKey ?? Doc.LayoutFieldKey(doc)) + "-nativeWidth"] = width; }
+ export function SetNativeHeight(doc: Doc, height: number | undefined, fieldKey?: string) { doc[(fieldKey ?? Doc.LayoutFieldKey(doc)) + "-nativeHeight"] = height; }
const manager = new DocData();
diff --git a/src/fields/Schema.ts b/src/fields/Schema.ts
index 78f8a6bfb..7ad376a28 100644
--- a/src/fields/Schema.ts
+++ b/src/fields/Schema.ts
@@ -21,8 +21,6 @@ export interface InterfaceFunc<T extends Interface[]> {
}
export type makeInterface<T extends Interface[]> = AllToInterface<T> & Doc & { proto: Doc | undefined };
-// export function makeInterface<T extends Interface[], U extends Doc>(schemas: T): (doc: U) => All<T, U>;
-// export function makeInterface<T extends Interface, U extends Doc>(schema: T): (doc: U) => makeInterface<T, U>;
export function makeInterface<T extends Interface[]>(...schemas: T): InterfaceFunc<T> {
const schema: Interface = {};
for (const s of schemas) {
@@ -37,18 +35,18 @@ export function makeInterface<T extends Interface[]>(...schemas: T): InterfaceFu
const desc = prop === "proto" ? Doc : (schema as any)[prop]; // bcz: proto doesn't appear in schemas ... maybe it should?
if (typeof desc === "object" && "defaultVal" in desc && "type" in desc) {//defaultSpec
return Cast(field, desc.type, desc.defaultVal);
- } else if (typeof desc === "function" && !ObjectField.isPrototypeOf(desc) && !RefField.isPrototypeOf(desc)) {
+ }
+ if (typeof desc === "function" && !ObjectField.isPrototypeOf(desc) && !RefField.isPrototypeOf(desc)) {
const doc = Cast(field, Doc);
if (doc === undefined) {
return undefined;
- } else if (doc instanceof Doc) {
+ }
+ if (doc instanceof Doc) {
return desc(doc);
- } else {
- return doc.then(doc => doc && desc(doc));
}
- } else {
- return Cast(field, desc);
+ return doc.then(doc => doc && desc(doc));
}
+ return Cast(field, desc);
}
return field;
},
@@ -57,21 +55,9 @@ export function makeInterface<T extends Interface[]>(...schemas: T): InterfaceFu
return true;
}
});
- const fn = (doc: Doc) => {
- doc = doc[SelfProxy];
- // if (!(doc instanceof Doc)) {
- // throw new Error("Currently wrapping a schema in another schema isn't supported");
- // }
- const obj = Object.create(proto, { doc: { value: doc, writable: false } });
- return obj;
- };
- return function (doc?: Doc | Doc[]) {
- if (doc instanceof Doc || doc === undefined) {
- return fn(doc || new Doc);
- } else if (doc instanceof List) {
- return doc.map(fn);
- } else return {};
- };
+ // !(doc instanceof Doc) && (throw new Error("Currently wrapping a schema in another schema isn't supported"));
+ const fn = (doc: Doc) => Object.create(proto, { doc: { value: doc[SelfProxy], writable: false } });
+ return ((doc?: Doc | Doc[]) => (doc instanceof List ? doc : undefined)?.map?.(fn) ?? fn((doc as Doc) ?? new Doc)) as InterfaceFunc<T>;
}
export type makeStrictInterface<T extends Interface> = Partial<ToInterface<T>>;