GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — asta4js/src/value-monitor.js at master · astamuse/asta4js

Expand file tree

/

value-monitor.js

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
246 lines (217 loc) · 6.22 KB
/

value-monitor.js

Copy path

File metadata and controls

246 lines (217 loc) · 6.22 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
"use strict";
var _ = require("../lib/observe");
var util = require("./util");
var config = require("./config");
var ResourceMap = require("./resource-map");
var safePathReplaces = [
[".", "_dot_"],
["[", "_lb_"],
["]", "_rb_"],
["\"", "_dq_"],
["\'", "_sg_"],
];
safePathReplaces.forEach(function(rep){
rep[1] = rep[1] + "_" + util.createUID();
});
var transferToSafePropertyPath = function(path){
var p = path;
var rep;
for(var i=0;i<safePathReplaces.length;i++){
rep = safePathReplaces[i];
p = p.replace(rep[0], rep[1]);
}
return p;
}
var VirtualScopeMonitorWrapper=function(){
this._scope = {};
this.monitorMap = new ResourceMap();
}
VirtualScopeMonitorWrapper.prototype.discard=function(){
this.monitorMap.discard();
}
VirtualScopeMonitorWrapper.prototype.getMonitro=function(virtualRootPath){
var k = virtualRootPath ? virtualRootPath : "";
k = transferToSafePropertyPath(k);
k = k ? "__vr__." + k : "__vr__";
var monitor = this.monitorMap.get("vm", k);
if(!monitor){
monitor = new ValueMonitor(this._scope, k);
this.monitorMap.add("vm", k, monitor);
}
return monitor;
}
VirtualScopeMonitorWrapper.prototype.reset=function(otherWrapper){
if(otherWrapper){
this._scope.__vr__ = util.clone(otherWrapper._scope.__vr__);
}else{
this._scope.__vr__ = {};
}
}
//===============================================================================
var ValueMonitor=function(scope, varRefRoot){
this.scope = scope;
this.varRefRoot = varRefRoot;
this.observerMap = new ResourceMap();
this.virtualScopeMonitorWrapper = new VirtualScopeMonitorWrapper();
}
var concatPath = function(p1, p2){
var path;
if(p1){
path = p2 ? p1 + "." + p2 : p1;
}else{
path = p2;
}
//fix the n-dimensions array path
path = path.replace(".[", "[");
return path;
}
var convertObservePath=function(rootPath, subPath){
var observePath = concatPath(rootPath, subPath);
if(!observePath){
throw "The scope root cannot be observed";
}
//fix the n-dimensions array path
observePath = observePath.replace(".[", "[");
var parts = observePath.split(".");
var safePath = "";
var arrayReg = /(\[[0-9]+\])+/
var match;
var p;
for(var i=0;i<parts.length;i++){
p = parts[i];
match = arrayReg.exec(p);
if(match){
p = p.substring(0, match.index)
if(p){
safePath += "['" + p + "']";
}
safePath += match[0];
}else{
if(p){
safePath += "['" + p + "']";
}
}
}
return safePath;
}
ValueMonitor.prototype.getVirtualMonitor=function(virtualRootPath){
return this.virtualScopeMonitorWrapper.getMonitro(virtualRootPath);
}
ValueMonitor.prototype.createSubMonitor=function(subPath){
var observePath = concatPath(this.varRefRoot, subPath);
return new ValueMonitor(this.scope, observePath);
};
ValueMonitor.prototype.pathObserve=function(identifier, subPath, changeFn, transform){
var observePath = convertObservePath(this.varRefRoot, subPath);
var observer = new _.PathObserver(this.scope, observePath);
if(transform){
observer.open(function(newValue, oldValue){
changeFn(
transform._get_value(newValue),
transform._get_value(oldValue)
);
});
}else{
observer.open(changeFn);
}
this.observerMap.add(observePath, identifier, observer);
}
function setValueWithSpawn(ref, path, value, pathPartIndex){
var index;
if(pathPartIndex === undefined){
index = 0;
}else{
index = pathPartIndex;
}
if(index == path.length -1){
ref[path[index]] = value;
}else{
if(!ref[path[index]]){
ref[path[index]] = {};
}
setValueWithSpawn(ref[path[index]], path, value, index+1);
}
}
ValueMonitor.prototype.getValueRef=function(subPath, transform){
var observePath = convertObservePath(this.varRefRoot, subPath);
var path = _.Path.get(observePath);
var scope = this.scope;
return {
setValue : function(v, spawnUnreachablePath){
var tv = transform ? transform._set_value(v) : v;
var success = path.setValueFrom(scope, tv);
if(!success){//unreachable path
var spawn = spawnUnreachablePath;
if(spawn === undefined){
spawn = true; //default to generate all necessary sub path
}
if(spawn){
setValueWithSpawn(scope, path, tv);
}
}
},
getValue : function(){
var v = path.getValueFrom(scope);
return transform ? transform._get_value(v) : v;
},
};
}
ValueMonitor.prototype.arrayObserve=function(identifier, targetArray, changeFn){
var observer = new _.ArrayObserver(targetArray);
observer.open(changeFn);
this.observerMap.add(identifier, identifier, observer);
}
ValueMonitor.prototype.removeArrayObserve=function(identifier){
this.observerMap.remove(identifier, identifier);
}
ValueMonitor.prototype.compoundObserve=function(identifier, pathes, changeFn){
var observer = new _.CompoundObserver();
var p;
for(var i=0;i<pathes.length;i++){
p = pathes[i];
if(p.indexOf("@:") == 0){//absolute path from scope root
p = p.substr(2);
}else{//relative path from current monitor ref path
p = convertObservePath(this.varRefRoot, p);
}
observer.addPath(this.scope, p);
}
observer.open(changeFn);
this.observerMap.add(identifier, identifier, observer);
}
ValueMonitor.prototype.getCompoundValueRef=function(pathes){
var ps = [];
var p;
for(var i=0;i<pathes.length;i++){
p = pathes[i];
if(p.indexOf("@:") == 0){//absolute path from scope root
p = p.substr(2);
}else{//relative path from current monitor ref path
p = convertObservePath(this.varRefRoot, p);
}
ps[i] = _.Path.get(p);
}
var scope = this.scope;
return {
setValues : function(values){
if(values.length != ps.length){
throw "length not equal for compound value set";
}
for(var i=0;i<values.length;i++){
ps[i].setValueFrom(scope, values[i]);
}
},
getValues : function(){
var values = [];
for(var i=0;i<ps.length;i++){
values[i] = ps[i].getValueFrom(scope);
}
return values;
},
};
}
ValueMonitor.prototype.discard=function(){
this.observerMap.discard();
this.virtualScopeMonitorWrapper.discard();
}
module.exports=ValueMonitor;
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.