dbm 1.0.4 → 1.0.6

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.
@@ -11,11 +11,27 @@ export default class CallFunction extends CommandBaseObject {
11
11
  }
12
12
 
13
13
  perform(aFromObject, aData) {
14
-
15
- //METODO: resolve input
14
+
16
15
  let callFunction = this.item.callFunction;
16
+
17
+ let currentArray = this.item.callArguments;
18
+ let currentArrayLength = currentArray.length;
19
+ let resolvedArguments = new Array(currentArrayLength);
20
+
21
+ for(let i = 0; i < currentArrayLength; i++){
22
+ let currentArgument = currentArray[i];
23
+
24
+ if(currentArgument && currentArgument.isFlowProperty) {
25
+ currentArgument = currentArgument.value;
26
+ }
27
+ else if(currentArgument && currentArgument.isSource) {
28
+ currentArgument = currentArgument.getSource(aFromObject, aData);
29
+ }
30
+
31
+ resolvedArguments[i] = currentArgument;
32
+ }
17
33
 
18
34
  //METODO: try catch
19
- callFunction.apply(this.item.scopeObject, this.item.callArguments);
35
+ return callFunction.apply(this.item.scopeObject, resolvedArguments);
20
36
  }
21
37
  }
package/core/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  export {default as LifeCycleObject} from "./LifeCycleObject.js";
2
2
  export {default as BaseObject} from "./BaseObject.js";
3
- export {default as GlobalObject} from "./GlobalObject.js";
3
+ export {default as GlobalObject} from "./GlobalObject.js";
4
+
5
+ export * as source from "./source/index.js";
@@ -0,0 +1,8 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class EventSource extends Dbm.core.source.SourceBaseObject {
4
+
5
+ getBaseObject(aFromObject, aEventData) {
6
+ return aEventData;
7
+ }
8
+ }
@@ -0,0 +1,29 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class SourceBaseObject extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ this.item.setValue("path", null);
8
+ }
9
+
10
+ get isSource() {
11
+ return true;
12
+ }
13
+
14
+ getBaseObject(aFromObject, aEventData) {
15
+ return null;
16
+ }
17
+
18
+ getSource(aFromObject, aEventData = null) {
19
+ //console.log("getSource");
20
+
21
+ let path = this.item.path;
22
+ let baseObject = this.getBaseObject(aFromObject, aEventData);
23
+ if(!path) {
24
+ return baseObject;
25
+ }
26
+
27
+ return Dbm.objectPath(baseObject, path);
28
+ }
29
+ }
@@ -0,0 +1,14 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export default class StaticSoruce extends Dbm.core.source.SourceBaseObject {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.item.setValue("object", null);
9
+ }
10
+
11
+ getBaseObject(aFromObject, aEventData) {
12
+ return this.item.object;
13
+ }
14
+ }
@@ -0,0 +1,22 @@
1
+ import Dbm from "../../index.js";
2
+
3
+ export {default as SourceBaseObject} from "./SourceBaseObject.js";
4
+ export {default as EventSource} from "./EventSource.js";
5
+ export {default as StaticSource} from "./StaticSource.js";
6
+
7
+ export const event = function(aPath = null) {
8
+ let newSource = new Dbm.core.source.EventSource();
9
+
10
+ newSource.item.properties.path.setOrConnect(aPath);
11
+
12
+ return newSource;
13
+ }
14
+
15
+ export const staticObject = function(aObject, aPath = null) {
16
+ let newSource = new Dbm.core.source.StaticSource();
17
+
18
+ newSource.item.object = aObject;
19
+ newSource.item.properties.path.setOrConnect(aPath);
20
+
21
+ return newSource;
22
+ }
@@ -17,7 +17,7 @@ export default class FlowProperty extends Dbm.flow.FlowBaseObject {
17
17
 
18
18
  setValue(aValue) {
19
19
  if(this._upstreamConnection) {
20
- //METODO: add warning
20
+ console.warn("Property has upstream connection, can't set value", this, aValue);
21
21
  //METODO: check if upstream can be changed
22
22
  }
23
23
  else {
@@ -0,0 +1,18 @@
1
+ import Dbm from "../index.js";
2
+
3
+ export default class FlowPropertyWithExternalInput extends Dbm.flow.FlowProperty {
4
+
5
+ setValue(aValue) {
6
+ if(aValue !== this._value) {
7
+ this._value = aValue;
8
+ this.isDirty = false;
9
+ this.setDownstreamAsDirty();
10
+ }
11
+
12
+ return this;
13
+ }
14
+
15
+ _internal_setValueInFlow(aValue) {
16
+ //MENOTE: do nothing
17
+ }
18
+ }
package/flow/index.js CHANGED
@@ -6,6 +6,7 @@ export {default as FlowUpdateFunction} from "./FlowUpdateFunction.js";
6
6
  export {default as UpdateFunctionInputs} from "./UpdateFunctionInputs.js";
7
7
  export {default as UpdateFunctionOutputs} from "./UpdateFunctionOutputs.js";
8
8
  export {default as DirtyCommands} from "./DirtyCommands.js";
9
+ export {default as FlowPropertyWithExternalInput} from "./FlowPropertyWithExternalInput.js";
9
10
 
10
11
  export * as updatefunctions from "./updatefunctions/index.js";
11
12
 
@@ -15,7 +16,7 @@ export let addUpdateCommand = function(aProperty, aCommand) {
15
16
  updateFunction.input.command = aCommand;
16
17
  updateFunction.noFirstTriggger();
17
18
 
18
- let updatePropertyCommand = Dbm.commands.callFunction(Dbm.getInstance().repository.getItem("propertyUpdater").controller.addSinglePropertyUpdateBound, [updateFunction.output.properties.value]);
19
+ let updatePropertyCommand = Dbm.commands.callFunction(Dbm.getInstance().repository.getItem("propertyUpdater").controller.addSinglePropertyUpdateBound, [Dbm.core.source.staticObject(updateFunction.output.properties.value)]);
19
20
 
20
21
  let dirtyCommands = new Dbm.flow.DirtyCommands();
21
22
  updateFunction.output.properties.value.connectOutput(dirtyCommands);
@@ -37,4 +38,40 @@ export let addDirectUpdateCommand = function(aProperty, aCommand) {
37
38
  dirtyCommands.commands.push(updatePropertyCommand);
38
39
 
39
40
  return {"updateFunction": updateFunction, "dirtyCommands": dirtyCommands};
41
+ }
42
+
43
+ export let addUpdateCommandWhenMatched = function(aProperty, aMatchValue, aCommand) {
44
+ let whenMatched = Dbm.flow.updatefunctions.logic.whenMatched(aProperty, aMatchValue);
45
+
46
+ let updateData = Dbm.flow.addUpdateCommand(whenMatched.output.properties.value, aCommand);
47
+
48
+ updateData["whenMatched"] = whenMatched;
49
+
50
+ return whenMatched;
51
+ }
52
+
53
+ export const animateValue = function(aValue, aTime = 0.5, aEasing = null) {
54
+
55
+ let returnObject = new Dbm.repository.Item();
56
+
57
+ returnObject.setValue("time", aTime);
58
+ returnObject.setValue("easing", aEasing);
59
+
60
+ let inputProperty = returnObject.requireProperty("input");
61
+ inputProperty.setOrConnect(aValue);
62
+
63
+ let outputProperty = new Dbm.flow.FlowPropertyWithExternalInput();
64
+ outputProperty.value = inputProperty.value;
65
+
66
+ returnObject._internal_addProperty("output", outputProperty);
67
+
68
+ let updateCommand = Dbm.flow.addUpdateCommand(inputProperty, Dbm.commands.callFunction(function(aItem) {
69
+ console.log("animate value");
70
+
71
+ aItem.properties.output.animateValue(aItem.input, aItem.time, aItem.easing);
72
+ }, [returnObject]));
73
+
74
+ returnObject.setValue("updateCommand", updateCommand);
75
+
76
+ return returnObject;
40
77
  }
@@ -18,10 +18,9 @@ export default class RunCommand extends Dbm.flow.FlowUpdateFunction {
18
18
  let value = this.input.value;
19
19
 
20
20
  let command = this.input.command;
21
- command.perform(this.input.baseObject, value);
22
-
21
+ let outputValue = command.perform(this.input.baseObject, value);
23
22
 
24
- this.output.value = value;
23
+ this.output.value = outputValue;
25
24
  }
26
25
 
27
26
  noFirstTriggger() {
@@ -1,2 +1,18 @@
1
+ import Dbm from "../../../index.js";
2
+
1
3
  export {default as RunCommand} from "./RunCommand.js";
2
- export {default as CombineString} from "./CombineString.js";
4
+ export {default as CombineString} from "./CombineString.js";
5
+
6
+ export const runCommand = function(aValue, aCommand) {
7
+ let updateFunction = new Dbm.flow.updatefunctions.basic.RunCommand();
8
+ updateFunction.input.properties.value.setOrConnect(aValue);
9
+ updateFunction.input.properties.command.setOrConnect(aCommand);
10
+
11
+ return updateFunction;
12
+ }
13
+
14
+ export const transformValue = function(aValue, aFunction) {
15
+ let command = Dbm.commands.callFunction(aFunction, [Dbm.core.source.event()]);
16
+
17
+ return Dbm.flow.updatefunctions.basic.runCommand(aValue, command);
18
+ }
@@ -37,10 +37,14 @@ export default class ElementPosition extends Dbm.flow.FlowUpdateFunction {
37
37
  console.log(element);
38
38
  //this.output.width = element.clientWidth;
39
39
  //this.output.height = element.clientHeight;
40
+
41
+ //METODO
40
42
  }
41
43
  else {
42
44
  //this.output.width = 0;
43
45
  //this.output.height = 0;
46
+
47
+ //METODO
44
48
  }
45
49
  }
46
50
 
@@ -31,13 +31,13 @@ export default class Switch extends Dbm.flow.FlowUpdateFunction {
31
31
 
32
32
  let value = this.input.value;
33
33
 
34
- let currentArray = this.input.ranges;
34
+ let currentArray = this.input.cases;
35
35
  let currentArrayLength = currentArray.length;
36
36
  for(let i = 0; i < currentArrayLength; i++) {
37
37
  let currentCase = currentArray[i];
38
38
 
39
39
  if(value === currentCase["key"]) {
40
- this.output.value = currentRange["value"];
40
+ this.output.value = currentCase["value"];
41
41
  return;
42
42
  }
43
43
  }
@@ -0,0 +1,24 @@
1
+ import Dbm from "../../../index.js";
2
+
3
+ export default class WhenMatched extends Dbm.flow.FlowUpdateFunction {
4
+
5
+ _construct() {
6
+ super._construct();
7
+
8
+ this.input.register("value", null);
9
+ this.input.register("matchValue", true);
10
+
11
+ this.output.register("value", false);
12
+ }
13
+
14
+ _update() {
15
+ //console.log("_update");
16
+
17
+ if(this.input.value === this.input.matchValue) {
18
+ this.output.value = true;
19
+ }
20
+ else {
21
+ this.output.properties.value.isDirty = false;
22
+ }
23
+ }
24
+ }
@@ -9,6 +9,7 @@ export {default as Condition} from "./Condition.js";
9
9
  export {default as All} from "./All.js";
10
10
  export {default as Any} from "./Any.js";
11
11
  export {default as AllAtValue} from "./AllAtValue.js";
12
+ export {default as WhenMatched} from "./WhenMatched.js";
12
13
 
13
14
  export let subtract = function(aInput1 = 0, aInput2 = 0) {
14
15
  let updateFunction = new Dbm.flow.updatefunctions.logic.Subtraction();
@@ -87,4 +88,19 @@ export let allAtValue = function(aMatchValue, ...aValues) {
87
88
  }
88
89
 
89
90
  return updateFunction;
91
+ }
92
+
93
+ export let whenMatched = function(aValue, aMatchValue = true) {
94
+ let updateFunction = new Dbm.flow.updatefunctions.logic.WhenMatched();
95
+ updateFunction.input.properties.value.setOrConnect(aValue);
96
+ updateFunction.input.properties.matchValue.setOrConnect(aMatchValue);
97
+
98
+ return updateFunction;
99
+ }
100
+
101
+ export let switchValue = function(aValue = null) {
102
+ let updateFunction = new Dbm.flow.updatefunctions.logic.Switch();
103
+ updateFunction.input.properties.value.setOrConnect(aValue);
104
+
105
+ return updateFunction;
90
106
  }
package/loading/index.js CHANGED
@@ -3,6 +3,8 @@ export {default as ScriptLoader} from "./ScriptLoader.js";
3
3
  export {default as JsonLoader} from "./JsonLoader.js";
4
4
  export * as LoadingStatus from "./LoadingStatus.js";
5
5
 
6
+ export * as node from "./node/index.js";
7
+
6
8
  export let loadScript = function(aUrl) {
7
9
 
8
10
  let loaderName = "loader-" + aUrl;
@@ -0,0 +1,161 @@
1
+ import https from "node:https";
2
+ import http from "node:http";
3
+
4
+ import Dbm from "../../index.js";
5
+
6
+ export default class JsonLoader extends Dbm.core.BaseObject {
7
+
8
+ _construct() {
9
+
10
+ super._construct();
11
+
12
+ this.item.setValue("url", null);
13
+ this.item.setValue("method", "GET");
14
+ this.item.setValue("headers", {});
15
+
16
+ this.item.setValue("status", Dbm.loading.LoadingStatus.NOT_STARTED);
17
+ this.item.setValue("data", null);
18
+ this.item.setValue("body", null);
19
+ this.item.setValue("rawData", "");
20
+
21
+ this._callback_requestBound = this._callback_request.bind(this);
22
+ this._callback_dataBound = this._callback_data.bind(this);
23
+ this._callback_errorBound = this._callback_error.bind(this);
24
+ this._callback_endBound = this._callback_end.bind(this);
25
+ }
26
+
27
+ get completed() {
28
+ let status = this.item.status;
29
+ return (status === Dbm.loading.LoadingStatus.LOADED || status === Dbm.loading.LoadingStatus.ERROR);
30
+ }
31
+
32
+ setMethod(aMethod) {
33
+ this.item.method = aMethod;
34
+
35
+ return this;
36
+ }
37
+
38
+ setUrl(aUrl) {
39
+ this.item.url = aUrl;
40
+
41
+ return this;
42
+ }
43
+
44
+ setupPost(aUrl, aBody) {
45
+ this.item.url = aUrl;
46
+ this.item.method = "POST";
47
+ this.setBody(aBody);
48
+
49
+ return this;
50
+ }
51
+
52
+ setupJsonPost(aUrl, aBody) {
53
+ this.item.url = aUrl;
54
+
55
+ return this.setJsonPostBody(aBody);
56
+ }
57
+
58
+ setJsonPostBody(aBody) {
59
+ this.item.method = "POST";
60
+ this.item.body = JSON.stringify(aBody);
61
+
62
+ this.addHeader("Content-Type", "application/json");
63
+
64
+ return this;
65
+ }
66
+
67
+ addHeader(aName, aValue) {
68
+ this.item.headers[aName] = aValue;
69
+
70
+ return this;
71
+ }
72
+
73
+ setBody(aBody) {
74
+ this.item.body = (aBody instanceof String) ? aBody : JSON.stringify(aBody);
75
+
76
+ return this;
77
+ }
78
+
79
+ setData(aData) {
80
+ //console.log("wprr/utils/loading/JsonLoader::setData");
81
+ //console.log(aData);
82
+
83
+ this._loadedAt = (new Date()).valueOf();
84
+ this.item.data = aData;
85
+ }
86
+
87
+ setStatus(aStatus) {
88
+ //console.log("wprr/utils/loading/JsonLoader::setStatus");
89
+ //console.log(aStatus);
90
+
91
+ this.item.status = aStatus;
92
+
93
+ return this;
94
+ }
95
+
96
+ _callback_request(aResponse) {
97
+ //console.log("_callback_request");
98
+ aResponse.on("data", this._callback_dataBound);
99
+ aResponse.on("end", this._callback_endBound);
100
+ }
101
+
102
+ _callback_data(aData) {
103
+ //console.log("_callback_data");
104
+ this.item.rawData += aData;
105
+ }
106
+
107
+ _callback_error(aError) {
108
+ console.log("_callback_error");
109
+ console.error(aError.message);
110
+
111
+ this.item.status = Dbm.loading.LoadingStatus.ERROR;
112
+ }
113
+
114
+ _callback_end() {
115
+ //console.log("_callback_end");
116
+ //console.log(this.item.rawData);
117
+ this._setData(this.item.rawData);
118
+ this.item.status = Dbm.loading.LoadingStatus.LOADED;
119
+ }
120
+
121
+ _setData(aData) {
122
+ this.item.data = aData;
123
+ }
124
+
125
+ load() {
126
+ //console.log("load");
127
+
128
+ if(this.item.status !== Dbm.loading.LoadingStatus.NOT_STARTED) {
129
+ return this;
130
+ }
131
+
132
+ let body = this.item.body;
133
+
134
+ this.item.status = Dbm.loading.LoadingStatus.LOADING;
135
+ let sendParameters = {
136
+ "method": this.item.method,
137
+ "headers": {...this.item.headers}
138
+ };
139
+
140
+ if(body) {
141
+ sendParameters.headers['Content-Length'] = body.length;
142
+ }
143
+
144
+ let url = this.item.url;
145
+
146
+ let request;
147
+ if(url.indexOf("https://") === 0) {
148
+ request = https.request(url, sendParameters, this._callback_requestBound).on("error", this._callback_errorBound);
149
+ }
150
+ else {
151
+ request = http.request(url, sendParameters, this._callback_requestBound).on("error", this._callback_errorBound);
152
+ }
153
+
154
+ if(body) {
155
+ request.write(body);
156
+ }
157
+ request.end();
158
+
159
+ return this;
160
+ }
161
+ }
@@ -0,0 +1 @@
1
+ export {default as TextLoader} from "./TextLoader.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbm",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "main": "index.js",
5
5
  "type": "module",
6
6
  "scripts": {},
@@ -27,11 +27,14 @@ export default class BaseObject extends Component {
27
27
  let currentDynamicProperty = this.getDynamicProp(objectName);
28
28
  currentDynamicProperty.setValue(currentProp);
29
29
  }
30
-
31
- if(currentProp && currentProp.isFlowProperty) {
30
+ else if(currentProp && currentProp.isFlowProperty) {
32
31
  let currentDynamicProperty = this.getDynamicProp(objectName);
33
32
  currentDynamicProperty.connectInput(currentProp);
34
33
  }
34
+ else if(this._dynamicProps[objectName]) {
35
+ let currentDynamicProperty = this.getDynamicProp(objectName);
36
+ currentDynamicProperty.value = currentProp;
37
+ }
35
38
  }
36
39
 
37
40
  //METODO: remove unused connections
@@ -0,0 +1,45 @@
1
+ import React from "react";
2
+ import Dbm from "../../index.js";
3
+
4
+ export default class OpenCloseExpandableArea extends Dbm.react.BaseObject {
5
+ _construct() {
6
+ super._construct();
7
+
8
+ let startValue = this.getPropValue("startState") === "open";
9
+ let openProperty = this.getDynamicProp("open", startValue);
10
+
11
+ let switchValue = Dbm.flow.updatefunctions.logic.switchValue(openProperty).addCase(false, 0).addCase(true, 1);
12
+ let animateValueObject = Dbm.flow.animateValue(switchValue.output.properties.value);
13
+ let transformToStyle = Dbm.flow.updatefunctions.basic.transformValue(animateValueObject.properties.output, this._transformToStyle.bind(this));
14
+
15
+ this.item.requireProperty("animationStyle", {}).connectInput(transformToStyle.output.properties.value);
16
+ }
17
+
18
+ _transformToStyle(aEnvelope) {
19
+ console.log("_transformToStyle");
20
+ console.log(aEnvelope, this, this.item.element);
21
+
22
+ if(aEnvelope === 0) {
23
+ return {"height": "0px", "overflow": "hidden"};
24
+ }
25
+ else if(aEnvelope === 1 || !this.item.element) {
26
+ return {};
27
+ }
28
+
29
+ return {"height": (this.item.element.clientHeight*aEnvelope) + "px", "overflow": "hidden"};
30
+ }
31
+
32
+ _renderMainElement() {
33
+ //console.log("OpenCloseExpandableArea::_renderMainElement");
34
+ //console.log(this);
35
+
36
+ return this._createMainElement(Dbm.react.BaseObject, {"className": "animation-element", "style": this.item.properties.animationStyle},
37
+ React.createElement("div", {"ref": this.createRef("element")},
38
+ this.getPropValue("children")
39
+ )
40
+ );
41
+
42
+ return null;
43
+ }
44
+ }
45
+
@@ -6,7 +6,7 @@ export default class ScrollActivatedArea extends Dbm.react.BaseObject {
6
6
  super._construct();
7
7
 
8
8
  let elementProperty = this.item.requireProperty("element", null);
9
- this.item.requireProperty("activated", false);
9
+ let activatedProperty = this.item.requireProperty("activated", false);
10
10
 
11
11
  let position = new Dbm.flow.updatefunctions.dom.ElementPosition();
12
12
  this.item.setValue("position", position);
@@ -15,17 +15,11 @@ export default class ScrollActivatedArea extends Dbm.react.BaseObject {
15
15
  let prepareProperty = this.item.requireProperty("prepare", 100);
16
16
  position.input.properties.prepareY.connectInput(prepareProperty);
17
17
 
18
- position.start();
18
+ let whenMatched = Dbm.flow.updatefunctions.logic.whenMatched(position.output.properties.prepare, true);
19
+ activatedProperty.connectInput(whenMatched.output.properties.value);
19
20
 
20
- Dbm.flow.addUpdateCommand(position.output.properties.prepare, Dbm.commands.callFunction(this._prepareChanged.bind(this)));
21
- }
22
-
23
- _prepareChanged() {
24
- //console.log("_prepareChanged");
21
+ position.start();
25
22
 
26
- if(this.item.position.output.prepare) {
27
- this.item.setValue("activated", true);
28
- }
29
23
  }
30
24
 
31
25
  _renderMainElement() {
@@ -1,3 +1,4 @@
1
1
  export {default as InsertElement} from "./InsertElement.js";
2
2
  export {default as HasData} from "./HasData.js";
3
- export {default as ScrollActivatedArea} from "./ScrollActivatedArea.js";
3
+ export {default as ScrollActivatedArea} from "./ScrollActivatedArea.js";
4
+ export {default as OpenCloseExpandableArea} from "./OpenCloseExpandableArea.js";
@@ -149,13 +149,10 @@ export default class CookieBar extends Dbm.react.BaseObject {
149
149
 
150
150
  _renderMainElement() {
151
151
 
152
- let isOpen = this.getDynamicProp("open").value;
153
- if(!isOpen) {
154
- return null;
155
- }
156
-
157
- return this._createMainElement("div", {className: "cookie-bar-position", ref: this.createRef("widthElement")},
158
- React.createElement(Dbm.react.area.InsertElement, {element: this.item.properties.element})
152
+ return this._createMainElement("div", {className: "cookie-bar-position", ref: this.createRef("widthElement")},
153
+ React.createElement(Dbm.react.area.OpenCloseExpandableArea, {open: this.getDynamicProp("open")},
154
+ React.createElement(Dbm.react.area.InsertElement, {element: this.item.properties.element})
155
+ )
159
156
  );
160
157
  }
161
158
  }
@@ -1,19 +1,8 @@
1
1
  import Dbm from "../../index.js";
2
2
 
3
- export default class ContextVariableSource extends Dbm.core.BaseObject {
4
- _construct() {
5
- super._construct();
6
-
7
- this.item.setValue("path", null);
8
- }
9
-
10
- get isSource() {
11
- return true;
12
- }
13
-
14
- getSource(aFromObject) {
15
- //console.log("getSource");
16
-
17
- return Dbm.objectPath(aFromObject.context, this.item.path);
18
- }
3
+ export default class SourceBaseObject extends Dbm.core.source.SourceBaseObject {
4
+
5
+ getBaseObject(aFromObject, aEventData) {
6
+ return aFromObject.context;
7
+ }
19
8
  }
@@ -43,19 +43,23 @@ export default class Item extends Dbm.core.LifeCycleObject {
43
43
 
44
44
  return this;
45
45
  }
46
+
47
+ _internal_addProperty(aName, aProperty) {
48
+ Object.defineProperty(this, aName, {
49
+ get() {
50
+ return aProperty.value;
51
+ },
52
+ set(aValue) {
53
+ aProperty.value = aValue;
54
+ }
55
+ });
56
+ this.properties[aName] = aProperty;
57
+ }
46
58
 
47
59
  getProperty(aName) {
48
60
  if(!this.properties.hasOwnProperty(aName)) {
49
61
  let property = new Dbm.flow.FlowProperty();
50
- Object.defineProperty(this, aName, {
51
- get() {
52
- return property.value;
53
- },
54
- set(aValue) {
55
- property.value = aValue;
56
- }
57
- });
58
- this.properties[aName] = property;
62
+ this._internal_addProperty(aName, property);
59
63
  }
60
64
 
61
65
  return this.properties[aName];
@@ -0,0 +1,40 @@
1
+ import Dbm from "../index.js";
2
+
3
+ export default class IntervalTimer extends Dbm.core.BaseObject {
4
+ _construct() {
5
+ super._construct();
6
+
7
+ this.item.setValue("running", false);
8
+ this._requestId = -1;
9
+ this.item.setValue("update", function() {});
10
+
11
+ this._updateBound = this._update.bind(this);
12
+ }
13
+
14
+ _update(aTime) {
15
+
16
+ this.item.update(aTime);
17
+
18
+ }
19
+
20
+ start() {
21
+ if(!this.item.running) {
22
+ this.item.running = true;
23
+ this._requestId = setInterval(this._updateBound, 10);
24
+ }
25
+
26
+ return this;
27
+ }
28
+
29
+ stop() {
30
+ if(this.item.running) {
31
+ this.item.running = false;
32
+ if(this._requestId) {
33
+ clearInterval(this._requestId);
34
+ this._requestId = -1;
35
+ }
36
+ }
37
+
38
+ return this;
39
+ }
40
+ }
package/updater/index.js CHANGED
@@ -2,6 +2,7 @@ import Dbm from "../index.js";
2
2
 
3
3
  export {default as PropertyUpdater} from "./PropertyUpdater.js";
4
4
  export {default as RequestAnimationFrameTimer} from "./RequestAnimationFrameTimer.js";
5
+ export {default as IntervalTimer} from "./IntervalTimer.js";
5
6
 
6
7
  let webSetup = function() {
7
8
  let updater = new Dbm.updater.PropertyUpdater();
@@ -13,4 +14,16 @@ let webSetup = function() {
13
14
  updater.start();
14
15
  }
15
16
 
16
- export {webSetup};
17
+ export {webSetup};
18
+
19
+ let nodeSetup = function() {
20
+ let updater = new Dbm.updater.PropertyUpdater();
21
+ updater.item.register("propertyUpdater");
22
+
23
+ let timer = new Dbm.updater.IntervalTimer();
24
+ updater.setTimer(timer.item);
25
+
26
+ updater.start();
27
+ }
28
+
29
+ export {nodeSetup};