Commit f2a60acb authored by Amirjanyan's avatar Amirjanyan
Browse files

MemriDictionary

parent 29a4e197
Showing with 195 additions and 163 deletions
+195 -163
......@@ -33,6 +33,7 @@ import {Renderers} from "../cvu/views/Renderers";
import {CacheMemri} from "../model/Cache";
import {Realm} from "../model/RealmLocal";
import {ViewArguments} from "../cvu/views/CascadableDict";
import {MemriDictionary} from "../model/MemriDictionary";
export var globalCache
......@@ -149,7 +150,7 @@ export class MemriContext {
//this.uiUpdateSubject.send() TODO
}
scheduleCascadableViewUpdate(immediate = false) {
scheduleCascadableViewUpdate(immediate = true) {
if (immediate) {
// Do this straight away, usually for the sake of correct animation
try { this.currentSession?.setCurrentView() }
......@@ -474,7 +475,7 @@ export class MemriContext {
.merge(viewArguments)
.resolve(item)
var args = {}
var args = new MemriDictionary()
for (let [argName, inputValue] of Object.entries(action.values)) {
if (action.argumentTypes[argName] == undefined) { continue }
......@@ -491,7 +492,7 @@ export class MemriContext {
let dataItem = argValue;
if (dataItem?.constructor?.name == "Item") {
finalValue = dataItem
} else if (typeof argValue.isCVUObject === "function") {
} else if (argValue?.constructor?.name === "MemriDictionary") {
let dict = argValue;
if (action.argumentTypes[argName] == "ViewArguments") {
finalValue = new ViewArguments(dict).resolve(item, viewArgs)
......
This diff is collapsed.
......@@ -6,21 +6,22 @@ import {ActionMultiAction} from "./Action";
import {debugHistory} from "./ViewDebugger";
import {CVUParsedDefinition} from "../../parsers/cvu-parser/CVUParsedDefinition";
import {CVUSerializer} from "../../parsers/cvu-parser/CVUToString";
import {MemriDictionary} from "../../model/MemriDictionary";
export class Cascadable/* extends CustomStringConvertible*/{
host?: Cascadable
cascadeStack: CVUParsedDefinition[]
tail: CVUParsedDefinition[]
head: CVUParsedDefinition
localCache = {}
localCache = new MemriDictionary()
get viewArguments() { return this.host?.viewArguments }
set viewArguments(value) { this.host?.viewArguments = value }
get toString() {
var merged = {}
var merged = new MemriDictionary()
function recur(dict: {}) {
function recur(dict: MemriDictionary) {
if (!dict) { return }
for (let [key, value] of Object.entries(dict)) {
......@@ -200,7 +201,7 @@ export class Cascadable/* extends CustomStringConvertible*/{
if (forceArray) {
for (var def of this.cascadeStack) {
let x = def[name]
if (typeof x.isCVUObject === "function") {
if (x.constructor.name === "MemriDictionary") {
for (let [key, value] of Object.entries(x)) {
if (value) {
result[key] = value
......
......@@ -7,6 +7,7 @@ import {Cascadable} from "./Cascadable";
import {ItemReference} from "../../model/DatabaseController";
import {CVUParsedDefinition, CVUParsedObjectDefinition} from "../../parsers/cvu-parser/CVUParsedDefinition";
import {Item} from "../../model/items/Item";
import {MemriDictionary} from "../../model/MemriDictionary";
export class CascadableDict extends Cascadable/*extends Cascadable, Subscriptable*/ {
subscript() {
......@@ -49,9 +50,6 @@ export class CascadableDict extends Cascadable/*extends Cascadable, Subscriptabl
}
}
getSubscript(name) { return this.get(name) }//TODO get with param
setSubscript(name, value) { this.set(name, value) }
constructor(head?, tail?: CVUParsedDefinition[]|Item, host?:Cascadable) {//TODO
if (head instanceof CascadableDict || tail instanceof Item) {
super(new CVUParsedObjectDefinition(), head?.cascadeStack)
......@@ -59,9 +57,9 @@ export class CascadableDict extends Cascadable/*extends Cascadable, Subscriptabl
} else if (head instanceof CVUParsedDefinition) {
super(head, tail, host)
} else {
var result = {}
var result = new MemriDictionary()
if (head) {
if (head && head.constructor.name === "MemriDictionary") {
for (let [key, value] of Object.entries(head)) {
if (value instanceof Item) {
result[key] = new ItemReference(value)
......@@ -103,7 +101,7 @@ export class CascadableDict extends Cascadable/*extends Cascadable, Subscriptabl
deepMerge(other?: CascadableDict) {
if (!other) { return this }
let merge = (parsed?) => {
let merge = (parsed?: MemriDictionary) => {
if (!parsed) { return }
for (let [key, value] of Object.entries(parsed)) {
this.head.set(key, value)
......
......@@ -20,6 +20,9 @@ import {registerThumbGridRenderer} from "../../gui/renderers/GridRenderers/Thumb
import {registerMessageRenderer} from "../../gui/renderers/MessageRenderer";
import {registerPhotoViewerRenderer} from "../../gui/renderers/PhotoViewerRenderer/PhotoViewerRenderer";
import {GeneralEditorLayoutItem, registerGeneralEditorRenderer} from "../../gui/renderers/GeneralEditorView";
//import {registerThumbHorizontalGridRenderer} from "../../gui/renderers/GridRenderers/ThumbHorizontalGridRendererView";
//import {registerThumbWaterfallRenderer} from "../../gui/renderers/GridRenderers/ThumbWaterfallRendererView";
import {MemriDictionary} from "../../model/MemriDictionary";
export class Renderers {
all = {}
......@@ -68,10 +71,10 @@ export var allRenderers = new Renderers();
//FilterPanelRendererButton moved to Action.ts
class RenderGroup {
options = {}
options = new MemriDictionary()
body: UIElement = null
constructor(dict) {
constructor(dict: MemriDictionary) {
if (Array.isArray(dict["children"]) && dict["children"][0]?.constructor?.name == "UIElement") this.body = dict["children"][0]
delete dict["children"]
this.options = dict
......@@ -117,7 +120,7 @@ export class CascadingRenderConfig extends Cascadable {
if (renderGroup) {
return renderGroup.options
}
return {}
return new MemriDictionary()
}
getRenderGroup(group) {
......@@ -128,14 +131,14 @@ export class CascadingRenderConfig extends Cascadable {
else if (group == "*" && this.cascadeProperty("*") == null) {
let list = this.cascadeProperty("children")
if (list) {
var dict = {"children": list}
var dict = new MemriDictionary({"children": list})
let renderGroup = new RenderGroup(dict)
this.localCache[group] = renderGroup
return renderGroup
}
}
else {
var dict = this.cascadeProperty(group)
var dict: MemriDictionary = this.cascadeProperty(group)
if (dict) {
let renderGroup = new RenderGroup(dict)
this.localCache[group] = renderGroup
......
......@@ -8,6 +8,8 @@
import {realmWriteIfAvailable} from "../../gui/util";
import {Datasource} from "../../api/Datasource";
import {CVUStoredDefinition} from "../../model/items/Item";
import {MemriDictionary} from "../../model/MemriDictionary";
export class SessionView /*extends DataItem */{
......@@ -76,16 +78,16 @@ export class SessionView /*extends DataItem */{
args = parsed["viewArguments"].clone();
}
var values = {//TODO
var values = new MemriDictionary({//TODO
selector: parsed?.selector ?? stored?.selector ?? "[view]",
name: typeof parsed["name"] === 'string' ? parsed["name"] : stored?.name || "",
viewDefinition: stored ?? new CVUStoredDefinition({ //TODO
viewDefinition: stored ?? new CVUStoredDefinition(new MemriDictionary({ //TODO
type: "view",
selector: parsed?.selector,
domain: parsed?.domain,
definition: parsed?.toCVUString(0, " ")
})
}
}))
})
if (args) { values["viewArguments"] = args }
if (us) { values["userState"] = us }
......
......@@ -16,18 +16,19 @@ import {
import {debugHistory} from "./ViewDebugger";
import {dataItemListToArray, UUID} from "../../model/items/Item";
import {ViewArguments} from "./CascadableDict";
import {MemriDictionary} from "../../model/MemriDictionary";
export class UIElement /*extends CVUToString */{
id = UUID()
type: UIElementFamily
children = []
properties = {} // TODO: ViewParserDefinitionContext
properties: MemriDictionary // TODO: ViewParserDefinitionContext
constructor(type, children?, properties = {}) {
constructor(type, children?, properties?) {
//super()
this.type = type
this.children = children ?? this.children
this.properties = properties
this.properties = properties ?? new MemriDictionary()
}
has(propName) {
......@@ -290,8 +291,8 @@ export var validateUIElementProperties = function (key, value) {
case UIElementProperties.image: return value?.constructor?.name == "File" || typeof value == "string";
case UIElementProperties.press: return value?.constructor?.name == "Action" || Array.isArray(value) && value[0]?.constructor?.name == "Action"
case UIElementProperties.list: return Array.isArray(value) && value[0]?.constructor?.name == "Item"
case UIElementProperties.view: return value?.constructor?.name == "CVUParsedDefinition" || typeof value.isCVUObject === "function"
case UIElementProperties.arguments: return typeof value.isCVUObject === "function"
case UIElementProperties.view: return value?.constructor?.name == "CVUParsedDefinition" || value.constructor.name === "MemriDictionary"
case UIElementProperties.arguments: return value.constructor.name === "MemriDictionary"
case UIElementProperties.location: return value?.constructor?.name == "Location"
case UIElementProperties.address: return value?.constructor?.name == "Address"
case UIElementProperties.value: return true
......
......@@ -17,6 +17,7 @@ import {CacheMemri} from "../../model/Cache";
import {CVUStateDefinition, dataItemListToArray, Item} from "../../model/items/Item";
import {ViewArguments} from "./CascadableDict";
import {CascadingRenderConfig} from "./Renderers";
import {MemriDictionary} from "../../model/MemriDictionary";
export class Views {
///
......@@ -103,10 +104,10 @@ export class Views {
DatabaseController.tryWriteSync(() => { // Start write transaction outside loop for performance reasons
// Loop over lookup table with named views
for (let def of parsedDefinitions) {
var values = {
var values = new MemriDictionary({
"domain": "defaults",
"definition": def.toString(),//TODO
}
})
if (def.selector != undefined) { values["selector"] = def.selector }
if (def.name != undefined) { values["name"] = def.name }
......
......@@ -35,6 +35,7 @@ import {RichTextEditor} from "../MemriTextEditor/RichTextEditor";
import {MessageBubbleView} from "../renderers/MessageRenderer";
import {SubView} from "./SubView";
import {MemriDictionary} from "../../model/MemriDictionary";
export class UIElementView extends MainUI {
context: MemriContext
......@@ -110,10 +111,10 @@ export class UIElementView extends MainUI {
this.context = this.props.context;
this.init(this.props.gui, this.props.dataItem, this.props.viewArguments);
let editorLabelAction = () => {
let args = {
let args = new MemriDictionary({
"subject": this.context.item, // self.item,
"edgeType": this.viewArguments.get("name")
}
})
let action = new ActionUnlink(this.context, args)
this.context.executeAction(action, this.item, this.viewArguments
)
......
......@@ -43,7 +43,7 @@ export var registerGeneralEditorRenderer = function () {
export class GeneralEditorLayoutItem {
id = UUID()
dict //future Dictionary
dict: MemriDictionary
viewArguments
constructor(dict, viewArguments?) {
......
......@@ -14,6 +14,7 @@ import {ResultSet} from "./ResultSet";
import {DatabaseController} from "./DatabaseController";
import {Realm} from "./RealmLocal";
import {Sync} from "./Sync";
import {MemriDictionary} from "./MemriDictionary";
export var cacheUIDCounter: number = -1
export class CacheMemri {
......@@ -61,7 +62,7 @@ export class CacheMemri {
var lut = {}
function recur(dict) {
var values = {}
var values = new MemriDictionary()
let type = dict["_type"];
let itemType = getItemType(type);
if (typeof type != "string" || !itemType) {
......@@ -411,7 +412,7 @@ export class CacheMemri {
let itemType = item.getType()
if (itemType) {
var dict= {};
var dict= new MemriDictionary();
for (var prop in item) {
if (item.hasOwnProperty(prop)) {
......@@ -490,7 +491,7 @@ export class CacheMemri {
}
//#warning("This doesnt trigger syncToPod()")
static createItem(type, values = {}, unique?: string) {
static createItem(type, values = new MemriDictionary(), unique?: string) {
var item
DatabaseController.tryWriteSync((realm: Realm) => {
var dict = values
......@@ -594,7 +595,7 @@ export class CacheMemri {
// TODO: find item in DB & merge
// Uniqueness based on also not primary key
let values = {
let values = new MemriDictionary({
"targetItemType": target[0],
"targetItemID": target[1],
"sourceItemType": source.genericType,
......@@ -604,7 +605,7 @@ export class CacheMemri {
"sequence": sequence,
"dateCreated": new Date(),
"_action": "create"
}
})
edge = realm.create("Edge", values)
});
......
export class MemriDictionary {
constructor(properties = {}) {
for (let key in properties) {
this[key] = properties[key];
}
}
}
\ No newline at end of file
......@@ -84,9 +84,17 @@ export class RealmObjects extends Array {
sorted(descriptor: string, reverse?: boolean) {
//TODO:
return this;/*.sort((a, b) => {
}) */
return this.sort((a, b) => {
let res
if (a[descriptor] > b[descriptor]) {
res = 1
} else if (a[descriptor] < b[descriptor]) {
res = -1
} else {
res = 0
}
return reverse ? res : -res
})
}
}
......
import {CVUSerializer} from "./CVUToString";
import {MemriDictionary} from "../../model/MemriDictionary";
export enum CompileScope {
all="all",
......@@ -37,7 +38,7 @@ export class CVUParsedDefinition {
}
parsed: {};
parsed = new MemriDictionary();
get description(): string {
return this.toCVUString(0, " ")
......@@ -85,7 +86,7 @@ export class CVUParsedDefinition {
return scope == CompileScope.all
? notnil.execute(viewArguments)
: notnil.compile(viewArguments)
} else if (typeof notnil.isCVUObject == "function") {
} else if (notnil.constructor.name == "MemriDictionary") {
for (let [key, value] of Object.entries(notnil)) {
notnil[key] = recur(value)
}
......@@ -200,7 +201,7 @@ export class CVUParsedViewDefinition extends CVUParsedDefinition {
query?: ExprNode
get definitionType() {return "view" }
constructor(selector, name, type?, query?, domain: string = "user", parsed?) {//TODO
constructor(selector, name, type?, query?, domain: string = "user", parsed?: MemriDictionary) {//TODO
super(selector, name, domain, parsed)
this.type = type
......
......@@ -21,6 +21,7 @@ import {
} from "./CVUParsedDefinition"
import {ActionFamily, getActionType} from "../../cvu/views/Action";
import {UIElement, UIElementFamily} from "../../cvu/views/UIElement";
import {MemriDictionary} from "../../model/MemriDictionary";
export class Color {
value;
......@@ -315,7 +316,7 @@ export class CVUParser {
}
parseDict(uiElementName?) {
var dict = {};
var dict = new MemriDictionary();
var stack = [];
let forUIElement = this.knownUIElements[uiElementName?.toLowerCase() ?? ""] != undefined;//TODO:
......@@ -343,7 +344,7 @@ export class CVUParser {
}
}
function addUIElement(type, properties) {//TODO:
function addUIElement(type, properties: MemriDictionary) {//TODO:
var children = dict["children"] || [];
let subChildren = Object.assign([], properties.children);
delete properties.children;
......@@ -447,7 +448,7 @@ export class CVUParser {
let lvalue = v.toLowerCase();
let type = this.knownUIElements[lvalue];
if (lastKey == null && type) {
var properties = {};
var properties = new MemriDictionary();
if (CVUToken.CurlyBracketOpen == this.peekCurrentToken().constructor) {
this.popCurrentToken();
properties = this.parseDict(v);
......@@ -456,7 +457,7 @@ export class CVUParser {
addUIElement(type, properties);//TODO
continue;
} else if (lvalue == "userstate" || lvalue == "viewarguments" || lvalue == "contextpane") {
var properties = {};
var properties = new MemriDictionary();
if (CVUToken.CurlyBracketOpen == this.peekCurrentToken().constructor) {
this.popCurrentToken();
properties = this.parseDict();
......@@ -472,7 +473,7 @@ export class CVUParser {
} else {
let name = this.knownActions[v.toLowerCase()];
if (name) {
var options = {};
var options = new MemriDictionary();
outerLoop: while (true) {
switch (this.peekCurrentToken().constructor) {
case CVUToken.Comma:
......@@ -702,7 +703,7 @@ export class CVUParser {
}
};
processCompoundProperties(dict) {
processCompoundProperties(dict: MemriDictionary) {
for (let name in this.frameProperties) {
if (dict[name]) {
......
......@@ -4,6 +4,7 @@
// Copyright © 2020 memri. All rights reserved.
//
import {HorizontalAlignment, Alignment, Color, VerticalAlignment, TextAlignment, Font, CGFloat} from "./CVUParser";
import {MemriDictionary} from "../../model/MemriDictionary";
//function UIElement() {}
......@@ -46,7 +47,7 @@ export class CVUSerializer {
return `"${p.replace("\"", "\\\"")}"`;
} else if (Array.isArray(p)) {
return this.arrayToString(p, depth + 1, tab)
} else if (typeof p.isCVUObject === "function") {//TODO:
} else if (p.constructor.name === "MemriDictionary") {//TODO:
return this.dictToString(p, depth + 1, tab)
} else if (typeof p.toCVUString === "function") {//TODO:
return p.toCVUString(depth, tab)
......@@ -97,7 +98,7 @@ export class CVUSerializer {
: str.join((extraNewLine ? "\n" : "") + `\n${tabs}`)
}
static dictToString(dict, depth: number = 0, tab: string = " ",
static dictToString(dict: MemriDictionary, depth: number = 0, tab: string = " ",
withDef: boolean = true, extraNewLine: boolean = false,
sortFunc?): string {
var keys: string[];
......@@ -140,7 +141,7 @@ export class CVUSerializer {
if (!isDef || dict1 != undefined && Object.entries(dict1)?.length > 0) {
let p = value;
if (p && typeof p.isCVUObject === "function") {
if (p && p.constructor.name === "MemriDictionary") {
str.push((extraNewLine ? "\n" + (withDef ? tabs : tabsEnd) : "")
+ `${key}: ${this.valueToString(p, depth, tab)}`);
} else if (value !== undefined) {
......
......@@ -10,6 +10,7 @@ const {ExprLexer} = require("./ExprLexer");
const {ExprParser} = require("./ExprParser");
import {ExprInterpreter} from "./ExprInterpreter";
import {DatabaseController, ItemReference} from "../../model/DatabaseController";
import {MemriDictionary} from "../../model/MemriDictionary";
export class Expression {
code: string;
......@@ -170,7 +171,7 @@ export class Expression {
static resolve(object?, viewArguments?: ViewArguments, dontResolveItems: boolean = false) { //TODO:
var dict = object;
if (typeof dict?.isCVUObject == "function") {
if (dict?.constructor.name === "MemriDictionary") {
for (let [key, value] of Object.entries(dict)) {
dict[key] = this.resolve(value, viewArguments, dontResolveItems)
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment