dbm 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/commands/CallFunction.js +21 -0
  2. package/commands/CommandBaseObject.js +11 -0
  3. package/commands/ResolvePromise.js +20 -0
  4. package/commands/index.js +36 -0
  5. package/core/BaseObject.js +23 -0
  6. package/core/GlobalObject.js +18 -0
  7. package/core/LifeCycleObject.js +25 -0
  8. package/core/index.js +3 -0
  9. package/dbm.js +71 -0
  10. package/flow/DirtyCommands.js +45 -0
  11. package/flow/FlowBaseObject.js +78 -0
  12. package/flow/FlowProperty.js +146 -0
  13. package/flow/FlowUpdateFunction.js +39 -0
  14. package/flow/UpdateFunctionInputs.js +58 -0
  15. package/flow/UpdateFunctionOutputs.js +51 -0
  16. package/flow/index.js +40 -0
  17. package/flow/updatefunctions/basic/CombineString.js +45 -0
  18. package/flow/updatefunctions/basic/RunCommand.js +34 -0
  19. package/flow/updatefunctions/basic/index.js +2 -0
  20. package/flow/updatefunctions/debug/Log.js +30 -0
  21. package/flow/updatefunctions/debug/index.js +1 -0
  22. package/flow/updatefunctions/dom/ElementSize.js +47 -0
  23. package/flow/updatefunctions/dom/StyleObject.js +43 -0
  24. package/flow/updatefunctions/dom/index.js +2 -0
  25. package/flow/updatefunctions/index.js +5 -0
  26. package/flow/updatefunctions/logic/Addition.js +19 -0
  27. package/flow/updatefunctions/logic/Multiplication.js +19 -0
  28. package/flow/updatefunctions/logic/RangeSwitch.js +46 -0
  29. package/flow/updatefunctions/logic/Subtraction.js +19 -0
  30. package/flow/updatefunctions/logic/index.js +38 -0
  31. package/flow/updatefunctions/react/UpdateState.js +22 -0
  32. package/flow/updatefunctions/react/index.js +1 -0
  33. package/graphapi/index.js +1 -0
  34. package/graphapi/webclient/WebSocketConnection.js +236 -0
  35. package/graphapi/webclient/WebSocketRequest.js +30 -0
  36. package/graphapi/webclient/decode/DecodeBaseObject.js +48 -0
  37. package/graphapi/webclient/decode/index.js +59 -0
  38. package/graphapi/webclient/index.js +4 -0
  39. package/index.js +1 -0
  40. package/loading/JsonLoader.js +128 -0
  41. package/loading/LoadingStatus.js +4 -0
  42. package/loading/ScriptLoader.js +40 -0
  43. package/loading/index.js +24 -0
  44. package/package.json +17 -0
  45. package/react/BaseObject.js +179 -0
  46. package/react/RefToProperty.js +20 -0
  47. package/react/admin/Editor.js +153 -0
  48. package/react/admin/EditorBlock.js +53 -0
  49. package/react/admin/EditorBlockName.js +19 -0
  50. package/react/admin/index.js +3 -0
  51. package/react/area/HasData.js +22 -0
  52. package/react/area/InsertElement.js +22 -0
  53. package/react/area/index.js +2 -0
  54. package/react/blocks/index.js +61 -0
  55. package/react/context/AddContextVariables.js +22 -0
  56. package/react/context/Context.js +4 -0
  57. package/react/context/index.js +2 -0
  58. package/react/cookies/CookieBar.js +162 -0
  59. package/react/cookies/CookieSettings.js +118 -0
  60. package/react/cookies/index.js +2 -0
  61. package/react/form/Checkbox.js +28 -0
  62. package/react/form/FormField.js +28 -0
  63. package/react/form/index.js +2 -0
  64. package/react/index.js +13 -0
  65. package/react/login/LoginForm.js +113 -0
  66. package/react/login/index.js +1 -0
  67. package/react/modules/ModuleCreator.js +30 -0
  68. package/react/modules/index.js +1 -0
  69. package/react/source/ContextVariableSource.js +19 -0
  70. package/react/source/index.js +1 -0
  71. package/react/text/HtmlText.js +14 -0
  72. package/react/text/Text.js +13 -0
  73. package/react/text/index.js +19 -0
  74. package/repository/Item.js +70 -0
  75. package/repository/Repository.js +60 -0
  76. package/repository/index.js +2 -0
  77. package/site/SiteDataLoader.js +62 -0
  78. package/site/SiteNavigation.js +242 -0
  79. package/site/index.js +2 -0
  80. package/startup/Controller.js +43 -0
  81. package/startup/Runner.js +40 -0
  82. package/startup/index.js +28 -0
  83. package/tracking/Controller.js +157 -0
  84. package/tracking/DataLayerTracker.js +80 -0
  85. package/tracking/index.js +16 -0
  86. package/updater/PropertyUpdater.js +127 -0
  87. package/updater/RequestAnimationFrameTimer.js +43 -0
  88. package/updater/index.js +16 -0
  89. package/utils/ArrayFunctions.js +20 -0
  90. package/utils/index.js +1 -0
@@ -0,0 +1,45 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class CombineString extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("parts", []);
9
+ this.input.register("delimiter", "");
10
+
11
+ this.output.register("value", "");
12
+ }
13
+
14
+ addPart(aValue) {
15
+ let part = this.input.register("part_" + this.input.parts.length, null).setOrConnect(aValue);
16
+
17
+ this.input.parts.push(part);
18
+
19
+ return this;
20
+ }
21
+
22
+ addParts(...aParts) {
23
+ let currentArray = aParts;
24
+ let currentArrayLength = currentArray.length;
25
+ for(let i = 0; i < currentArrayLength; i++) {
26
+ this.addPart(currentArray[i]);
27
+ }
28
+
29
+ return this;
30
+ }
31
+
32
+ _update() {
33
+ //console.log("_update");
34
+
35
+ let currentArray = this.input.parts;
36
+ let currentArrayLength = currentArray.length;
37
+
38
+ let returnArray = new Array(currentArrayLength);
39
+ for(let i = 0; i < currentArrayLength; i++) {
40
+ returnArray[i] = currentArray[i].value;
41
+ }
42
+
43
+ this.output.value = returnArray.join(this.input.delimiter);
44
+ }
45
+ }
@@ -0,0 +1,34 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class RunCommand extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("baseObject", this);
9
+ this.input.register("command", null);
10
+ this.input.register("value", null);
11
+
12
+ this.output.register("value", null);
13
+ }
14
+
15
+ _update() {
16
+ //console.log("_update");
17
+
18
+ let value = this.input.value;
19
+
20
+ let command = this.input.command;
21
+ command.perform(this.input.baseObject, value);
22
+
23
+
24
+ this.output.value = value;
25
+ }
26
+
27
+ noFirstTriggger() {
28
+ this.input.updateValues();
29
+ this.output.markAsClean();
30
+ this.isDirty = false;
31
+
32
+ return this;
33
+ }
34
+ }
@@ -0,0 +1,2 @@
1
+ export {default as RunCommand} from "./RunCommand.js";
2
+ export {default as CombineString} from "./CombineString.js";
@@ -0,0 +1,30 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class Log extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("annotation", null);
9
+ this.input.register("value", null);
10
+
11
+ this.output.register("value", null);
12
+ }
13
+
14
+ _update() {
15
+ //console.log("_update");
16
+
17
+ let value = this.input.value;
18
+
19
+ let annotation = this.input.annotation;
20
+ if(annotation) {
21
+ console.log(annotation, value);
22
+ }
23
+ else {
24
+ console.log(value);
25
+ }
26
+
27
+
28
+ this.output.value = value;
29
+ }
30
+ }
@@ -0,0 +1 @@
1
+ export {default as Log} from "./Log.js";
@@ -0,0 +1,47 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class ElementSize extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("element", null);
9
+
10
+ this.output.register("width", 0);
11
+ this.output.register("height", 0);
12
+
13
+ this._callback_sizeChangedBound = this._callback_sizeChanged.bind(this);
14
+ }
15
+
16
+ start() {
17
+ window.addEventListener("resize", this._callback_sizeChangedBound, false);
18
+
19
+ return this;
20
+ }
21
+
22
+ _update() {
23
+ //console.log("_update");
24
+
25
+ let element = this.input.element;
26
+
27
+ if(element) {
28
+ this.output.width = element.clientWidth;
29
+ this.output.height = element.clientHeight;
30
+ }
31
+ else {
32
+ this.output.width = 0;
33
+ this.output.height = 0;
34
+ }
35
+ }
36
+
37
+ _callback_sizeChanged(aEvent) {
38
+ //console.log("_callback_sizeChanged");
39
+
40
+ let element = this.input.element;
41
+
42
+ if(element) {
43
+ this.output.properties.width._internal_setValueInFlowOutsideOfUpdate(element.clientWidth);
44
+ this.output.properties.height._internal_setValueInFlowOutsideOfUpdate(element.clientHeight);
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,43 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class StyleObject extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("values", {});
9
+ this.input.register("units", {});
10
+
11
+ this.output.register("style", {});
12
+ }
13
+
14
+ addProperty(aName, aValue, aUnit = null) {
15
+ let property = this.input.register("property_" + aName, null).setOrConnect(aValue);
16
+ let unit = this.input.register("units_" + aName, null).setOrConnect(aUnit);
17
+
18
+ this.input.values[aName] = property;
19
+ this.input.units[aName] = unit;
20
+
21
+ return this;
22
+ }
23
+
24
+ _update() {
25
+ //console.log("_update");
26
+
27
+ let properties = this.input.values;
28
+
29
+ let styleObject = {};
30
+
31
+ for(let objectName in properties) {
32
+ let value = properties[objectName].value;
33
+ let unit = this.input.units[objectName].value;
34
+
35
+ if(unit) {
36
+ value += " " + unit;
37
+ }
38
+ styleObject[objectName] = value;
39
+ }
40
+
41
+ this.output.style = styleObject;
42
+ }
43
+ }
@@ -0,0 +1,2 @@
1
+ export {default as ElementSize} from "./ElementSize.js";
2
+ export {default as StyleObject} from "./StyleObject.js";
@@ -0,0 +1,5 @@
1
+ export * as logic from "./logic/index.js";
2
+ export * as debug from "./debug/index.js";
3
+ export * as react from "./react/index.js";
4
+ export * as basic from "./basic/index.js";
5
+ export * as dom from "./dom/index.js";
@@ -0,0 +1,19 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class Addition extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("input1", 0);
9
+ this.input.register("input2", 0);
10
+
11
+ this.output.register("result", 0);
12
+ }
13
+
14
+ _update() {
15
+ //console.log("_update");
16
+
17
+ this.output.result = this.input.input1 + this.input.input2;
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class Multiplication extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("input1", 0);
9
+ this.input.register("input2", 0);
10
+
11
+ this.output.register("result", 0);
12
+ }
13
+
14
+ _update() {
15
+ //console.log("_update");
16
+
17
+ this.output.result = this.input.input1 * this.input.input2;
18
+ }
19
+ }
@@ -0,0 +1,46 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class RangeSwitch extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("value", 0);
9
+ this.input.register("defaultValue", null);
10
+ this.input.register("ranges", []);
11
+
12
+ this.output.register("value", null);
13
+ }
14
+
15
+ addValueForRange(aOutputValue, aMinInputValue = null, aMaxInputValue = null) {
16
+
17
+ let rangeData = {value: aOutputValue, min: aMinInputValue, max: aMaxInputValue};
18
+
19
+ let newRanges = [].concat(this.input.ranges);
20
+
21
+ newRanges.push(rangeData);
22
+
23
+ this.input.ranges = newRanges;
24
+
25
+ return this;
26
+ }
27
+
28
+ _update() {
29
+ //console.log("_update");
30
+
31
+ let value = this.input.value;
32
+
33
+ let currentArray = this.input.ranges;
34
+ let currentArrayLength = currentArray.length;
35
+ for(let i = 0; i < currentArrayLength; i++) {
36
+ let currentRange = currentArray[i];
37
+
38
+ if((value >= currentRange["min"] || currentRange["min"] === null) && (value < currentRange["max"] || currentRange["max"] === null)) {
39
+ this.output.value = currentRange["value"];
40
+ return;
41
+ }
42
+ }
43
+
44
+ this.output.value = this.input.defaultValue;
45
+ }
46
+ }
@@ -0,0 +1,19 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class Subtraction extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("input1", 0);
9
+ this.input.register("input2", 0);
10
+
11
+ this.output.register("result", 0);
12
+ }
13
+
14
+ _update() {
15
+ //console.log("_update");
16
+
17
+ this.output.result = this.input.input1 - this.input.input2;
18
+ }
19
+ }
@@ -0,0 +1,38 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export {default as Addition} from "./Addition.js";
4
+ export {default as Multiplication} from "./Multiplication.js";
5
+ export {default as RangeSwitch} from "./RangeSwitch.js";
6
+ export {default as Subtraction} from "./Subtraction.js";
7
+
8
+ export let subtract = function(aInput1 = 0, aInput2 = 0) {
9
+ let updateFunction = new Dbm.flow.updatefunctions.logic.Subtraction();
10
+ updateFunction.input.properties.input1.setOrConnect(aInput1);
11
+ updateFunction.input.properties.input2.setOrConnect(aInput2);
12
+
13
+ return updateFunction;
14
+ }
15
+
16
+ export let invertP = function(aP = 0) {
17
+ let updateFunction = new Dbm.flow.updatefunctions.logic.Subtraction();
18
+ updateFunction.input.properties.input1.setValue(1);
19
+ updateFunction.input.properties.input2.setOrConnect(aP);
20
+
21
+ return updateFunction;
22
+ }
23
+
24
+ export let add = function(aInput1 = 0, aInput2 = 0) {
25
+ let updateFunction = new Dbm.flow.updatefunctions.logic.Addition();
26
+ updateFunction.input.properties.input1.setOrConnect(aInput1);
27
+ updateFunction.input.properties.input2.setOrConnect(aInput2);
28
+
29
+ return updateFunction;
30
+ }
31
+
32
+ export let multiply = function(aInput1 = 1, aInput2 = 1) {
33
+ let updateFunction = new Dbm.flow.updatefunctions.logic.Multiplication();
34
+ updateFunction.input.properties.input1.setOrConnect(aInput1);
35
+ updateFunction.input.properties.input2.setOrConnect(aInput2);
36
+
37
+ return updateFunction;
38
+ }
@@ -0,0 +1,22 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class UpdateState extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("owner", null);
9
+
10
+ this.output.register("dynamicUpdate", 0);
11
+ }
12
+
13
+ _update() {
14
+ //console.log("UpdateState::_update");
15
+
16
+ let dynamicUpdate = this.input.owner.state.dynamicUpdate;
17
+ dynamicUpdate++;
18
+ this.input.owner.setState({"dynamicUpdate": dynamicUpdate});
19
+
20
+ this.output.dynamicUpdate = dynamicUpdate;
21
+ }
22
+ }
@@ -0,0 +1 @@
1
+ export {default as UpdateState} from "./UpdateState.js";
@@ -0,0 +1 @@
1
+ export * as webclient from "./webclient/index.js";
@@ -0,0 +1,236 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class WebSocketConnection extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ this._webSocket = null;
8
+ this._callback_onOpenBound = this._callback_onOpen.bind(this);
9
+ this._callback_onMessageBound = this._callback_onMessage.bind(this);
10
+
11
+ this.item.setValue("requests", []);
12
+ this.item.setValue("status", 0);
13
+ }
14
+
15
+ setup(aUrl) {
16
+ this._webSocket = new WebSocket(aUrl);
17
+ this.item.setValue("status", 2);
18
+
19
+ this._webSocket.onopen = this._callback_onOpenBound;
20
+ this._webSocket.onmessage = this._callback_onMessageBound;
21
+ return this;
22
+ }
23
+
24
+ _getRequestItem() {
25
+ let requestId = "graphApi/webSocketRequest" + Dbm.getInstance().getNextId();
26
+
27
+ let request = new Dbm.graphapi.webclient.WebSocketRequest();
28
+ request.item.register(requestId);
29
+ request.item.setValue("status", Dbm.loading.LoadingStatus.NOT_STARTED);
30
+ request.item.setValue("connection", this.item);
31
+
32
+ return request.item;
33
+ }
34
+
35
+ _runRequest(aRequestItem) {
36
+ let newRequests = [].concat(this.item.requests);
37
+ newRequests.push(aRequestItem);
38
+ this.item.setValue("requests", newRequests);
39
+
40
+ if(this.item.status === 1) {
41
+ aRequestItem.setValue("status", Dbm.loading.LoadingStatus.LOADING);
42
+ this._webSocket.send(JSON.stringify(aRequestItem.requestData));
43
+ }
44
+ }
45
+
46
+ requestRange(aSelect, aEncode) {
47
+ let item = this._getRequestItem();
48
+ item.setValue("requestData", {"type": "range", "select": aSelect, "encode": aEncode, "requestId": item.id});
49
+ this._runRequest(item);
50
+
51
+ return item;
52
+ }
53
+
54
+ requestItem(aId, aEncode) {
55
+ let item = this._getRequestItem();
56
+ item.setValue("requestData", {"type": "item", "id": aId, "encode": aEncode, "requestId": item.id});
57
+ this._runRequest(item);
58
+
59
+ return item;
60
+ }
61
+
62
+ requestData(aFunctionName, aData) {
63
+ console.log("requestData");
64
+ let item = this._getRequestItem();
65
+ item.setValue("requestData", {"type": "data", "functionName": aFunctionName, "data": aData, "requestId": item.id});
66
+ this._runRequest(item);
67
+
68
+ return item;
69
+ }
70
+
71
+ createItem(aTypes, aVisibility = "draft", aChanges = [], aEncode = []) {
72
+ let item = this._getRequestItem();
73
+ item.setValue("requestData", {"type": "admin/createObject", "types": aTypes, "visibility": aVisibility, "changes": aChanges, "encode": aEncode, "requestId": item.id});
74
+ this._runRequest(item);
75
+
76
+ return item;
77
+ }
78
+
79
+ editItem(aId, aChanges, aEncode = []) {
80
+ let item = this._getRequestItem();
81
+ item.setValue("requestData", {"type": "admin/editObject", "id": aId, "changes": aChanges, "encode": aEncode, "requestId": item.id});
82
+ this._runRequest(item);
83
+
84
+ return item;
85
+ }
86
+
87
+ requestUrl(aUrl) {
88
+ let item = this._getRequestItem();
89
+ item.setValue("requestData", {"type": "url", "url": aUrl, "requestId": item.id});
90
+ this._runRequest(item);
91
+
92
+ return item;
93
+ }
94
+
95
+ _callback_onOpen(aEvent) {
96
+ //console.log("_callback_onOpen");
97
+
98
+ //MENOTE: do nothing
99
+ }
100
+
101
+ _connectionReady() {
102
+ this.item.setValue("status", 1);
103
+ let currentArray = this.item.requests;
104
+ let currentArrayLength = currentArray.length;
105
+ for(let i = 0; i < currentArrayLength; i++) {
106
+ let currentItem = currentArray[i];
107
+ currentItem.setValue("status", Dbm.loading.LoadingStatus.LOADING);
108
+ this._webSocket.send(JSON.stringify(currentItem.requestData));
109
+ }
110
+ }
111
+
112
+ _callback_onMessage(aEvent) {
113
+ //console.log("_callback_onMessage");
114
+ //console.log(aEvent.data);
115
+
116
+ let data = JSON.parse(aEvent.data);
117
+ let repository = Dbm.getInstance().repository;
118
+ switch(data.type) {
119
+ case "updateEncodedObject":
120
+ {
121
+ let item = repository.getItem(data["id"]);
122
+ let decoder = repository.getItemIfExists("graphApi/decode/" + data["encoding"]);
123
+ if(decoder) {
124
+ decoder.controller.updateItemWithEncoding(item, data["data"]);
125
+ }
126
+ else {
127
+ console.warn("No decoder for " + data["encoding"]);
128
+ }
129
+ }
130
+ break;
131
+ case "range/response":
132
+ {
133
+ let item = repository.getItem(data["requestId"]);
134
+ item.setValue("items", repository.getItems(data["ids"]));
135
+ item.setValue("status", Dbm.loading.LoadingStatus.LOADED);
136
+ }
137
+ break;
138
+ case "item/response":
139
+ {
140
+ let item = repository.getItem(data["requestId"]);
141
+ item.setValue("item", repository.getItem(data["id"]));
142
+ item.setValue("status", Dbm.loading.LoadingStatus.LOADED);
143
+
144
+ let currentArray = item.doneCommands;
145
+ if(currentArray) {
146
+ let currentArrayLength = currentArray.length;
147
+ for(let i = 0; i < currentArrayLength; i++) {
148
+ let currentCommand = currentArray[i];
149
+ currentCommand.perform(item, data["id"]);
150
+ }
151
+ }
152
+ }
153
+ break;
154
+ case "data/response":
155
+ {
156
+ let item = repository.getItem(data["requestId"]);
157
+ item.setValue("data", data["data"]);
158
+ item.setValue("status", Dbm.loading.LoadingStatus.LOADED);
159
+
160
+ let currentArray = item.doneCommands;
161
+ if(currentArray) {
162
+ let currentArrayLength = currentArray.length;
163
+ for(let i = 0; i < currentArrayLength; i++) {
164
+ let currentCommand = currentArray[i];
165
+ currentCommand.perform(item, data["data"]);
166
+ }
167
+ }
168
+ }
169
+ break;
170
+ case "url/response":
171
+ {
172
+ let item = repository.getItem(data["requestId"]);
173
+ if(data["id"]) {
174
+ item.setValue("item", repository.getItem(data["id"]));
175
+ }
176
+ else {
177
+ item.setValue("item", null);
178
+ }
179
+ item.setValue("status", Dbm.loading.LoadingStatus.LOADED);
180
+
181
+ let currentArray = item.doneCommands;
182
+ if(currentArray) {
183
+ let currentArrayLength = currentArray.length;
184
+ for(let i = 0; i < currentArrayLength; i++) {
185
+ let currentCommand = currentArray[i];
186
+ currentCommand.perform(item, data["id"]);
187
+ }
188
+ }
189
+ }
190
+ break;
191
+ case "currentUser/response":
192
+ {
193
+ let item = repository.getItem(data["requestId"]);
194
+ if(data["id"]) {
195
+ item.setValue("user", repository.getItem(data["id"]));
196
+ }
197
+ else {
198
+ item.setValue("user", null);
199
+ }
200
+ repository.getItem("site").currentUser = item.user;
201
+ item.setValue("status", Dbm.loading.LoadingStatus.LOADED);
202
+ }
203
+ break;
204
+ case "connectionReady":
205
+ {
206
+ if(data["user"]) {
207
+ repository.getItem("site").currentUser = repository.getItem(data["user"]);
208
+ }
209
+ else {
210
+ repository.getItem("site").currentUser = null;
211
+ }
212
+ this._connectionReady();
213
+ }
214
+ break;
215
+ default:
216
+ console.warn("Unknown message type " + data.type);
217
+ break;
218
+ }
219
+ }
220
+
221
+ signIn(aToken) {
222
+ let item = this._getRequestItem();
223
+ item.setValue("requestData", {"type": "user/signInWithToken", "token": aToken, "requestId": item.id});
224
+ this._runRequest(item);
225
+
226
+ return item;
227
+ }
228
+
229
+ signOut() {
230
+ let item = this._getRequestItem();
231
+ item.setValue("requestData", {"type": "user/signOut", "requestId": item.id});
232
+ this._runRequest(item);
233
+
234
+ return item;
235
+ }
236
+ }
@@ -0,0 +1,30 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class WebSocketRequest extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ }
8
+
9
+ get processPromise() {
10
+ if(this.item.status === Dbm.loading.LoadingStatus.LOADED) {
11
+ return Promise.resolve(this.item);
12
+ }
13
+ if(this.item.status === Dbm.loading.LoadingStatus.LOADING || this.item.status === Dbm.loading.LoadingStatus.NOT_STARTED) {
14
+ if(!this.item.processPromise) {
15
+ let resolveCommand = Dbm.commands.resolvePromise(this.item);
16
+ this.item.setValue("doneCommands", [resolveCommand]);
17
+ let rejectCommand = Dbm.commands.callFunction(resolveCommand.item.reject, []);
18
+ this.item.setValue("errorCommands", [rejectCommand]);
19
+
20
+ //METODO: change these to addToArray
21
+
22
+ this.item.setValue("processPromise", resolveCommand.item.promise);
23
+ }
24
+
25
+ return this.item.processPromise;
26
+ }
27
+
28
+ return Promise.reject();
29
+ }
30
+ }