lightview 1.4.10-b → 1.6.3-b
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.
- package/README.md +35 -1
- package/components/chart.html +76 -0
- package/components/gauge.html +57 -0
- package/examples/chart.html +64 -0
- package/examples/counter.html +3 -10
- package/examples/counter.test.mjs +47 -0
- package/examples/directives.html +2 -2
- package/examples/foreign.html +1 -1
- package/examples/forgeinform.html +3 -3
- package/examples/form.html +9 -15
- package/examples/gauge.html +16 -0
- package/examples/invalid-template-literals.html +45 -0
- package/examples/message.html +1 -1
- package/examples/remote.html +3 -1
- package/examples/remote.json +1 -1
- package/examples/sensors/index.html +30 -0
- package/examples/sensors/sensor-server.js +30 -0
- package/examples/template.html +1 -1
- package/examples/types.html +25 -5
- package/examples/xor.html +3 -3
- package/lightview.js +179 -327
- package/package.json +36 -36
- package/test/basic.html +26 -19
- package/test/basic.test.mjs +98 -21
- package/types.js +445 -0
package/types.js
ADDED
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
function ValidityState(options) {
|
|
2
|
+
if(!this || !(this instanceof ValidityState)) return new ValidityState(options);
|
|
3
|
+
Object.assign(this,{
|
|
4
|
+
valid:false,
|
|
5
|
+
badInput:undefined,
|
|
6
|
+
customError:undefined,
|
|
7
|
+
patternMismatch:undefined,
|
|
8
|
+
rangeUnderflow:undefined,
|
|
9
|
+
rangeOverflow:undefined,
|
|
10
|
+
typeMismatch:undefined,
|
|
11
|
+
valueMissing:undefined,
|
|
12
|
+
stepMistmatch:undefined,
|
|
13
|
+
tooLong:undefined,
|
|
14
|
+
tooShort:undefined
|
|
15
|
+
},options);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const tryParse = (value) => {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(value+"")
|
|
21
|
+
} catch(e) {
|
|
22
|
+
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const ifInvalid = (variable) => {
|
|
27
|
+
variable.validityState.type = typeof(variable.type)==="string" ? variable.type : variable.type.type;
|
|
28
|
+
throw new TypeError(JSON.stringify(variable));
|
|
29
|
+
// or could return existing value variable.value
|
|
30
|
+
// or could return nothing
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const validateAny = function(value,variable) {
|
|
34
|
+
if(value===undefined && variable.value===undefined) {
|
|
35
|
+
return this.default;
|
|
36
|
+
}
|
|
37
|
+
if(this.required && value==null) {
|
|
38
|
+
variable.validityState = ValidityState({valueMissing: true});
|
|
39
|
+
} else {
|
|
40
|
+
variable.validityState = ValidityState({valid:true});
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
return this.whenInvalid(variable,value);
|
|
44
|
+
}
|
|
45
|
+
const any = ({required=false,whenInvalid = ifInvalid,...rest}) => { // ...rest allows use of property "default", which is otherwise reserved
|
|
46
|
+
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
47
|
+
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
48
|
+
return {
|
|
49
|
+
type: "any",
|
|
50
|
+
required,
|
|
51
|
+
whenInvalid,
|
|
52
|
+
...rest,
|
|
53
|
+
validate: validateAny
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
any.validate = validateAny;
|
|
57
|
+
any.required = false;
|
|
58
|
+
|
|
59
|
+
const validateArray = function(value,variable) {
|
|
60
|
+
if(value===undefined && variable.value===undefined) {
|
|
61
|
+
return this.default;
|
|
62
|
+
}
|
|
63
|
+
if(this.required && value==null) {
|
|
64
|
+
variable.validityState = ValidityState({valueMissing: true});
|
|
65
|
+
} else {
|
|
66
|
+
let result = this.coerce && typeof(value)==="string" ? tryParse(value.startsWith("[") ? value : `[${value}]`) : value;
|
|
67
|
+
if (!Array.isArray(result)) {
|
|
68
|
+
if (value.includes(",")) result = value.split(",");
|
|
69
|
+
}
|
|
70
|
+
if(typeof(result)!=="object" || !(result instanceof Array || Array.isArray(result))) {
|
|
71
|
+
variable.validityState = ValidityState({typeMismatch:true,value});
|
|
72
|
+
} else if(result.length<this.minlength) {
|
|
73
|
+
variable.validityState = ValidityState({tooShort:true,value});
|
|
74
|
+
} else if(result.length>this.maxlength) {
|
|
75
|
+
variable.validityState = ValidityState({tooLong:true,value});
|
|
76
|
+
} else {
|
|
77
|
+
variable.validityState = ValidityState({valid:true});
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return this.whenInvalid(variable,value);
|
|
82
|
+
}
|
|
83
|
+
const array = ({coerce=false, required = false,whenInvalid = ifInvalid,maxlength=Infinity,minlength=0,...rest}) => {
|
|
84
|
+
if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
|
|
85
|
+
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
86
|
+
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
87
|
+
if(typeof(maxlength)!=="number") throw new TypeError(`maxlength, ${JSON.stringify(maxlength)}, must be a number`);
|
|
88
|
+
if(typeof(minlength)!=="number") throw new TypeError(`minlength, ${JSON.stringify(minlength)}, must be a number`);
|
|
89
|
+
if(rest.default!==undefined && (typeof(rest.default)!=="object" || !(rest.default instanceof Array || Array.isArray(rest.default)))) throw new TypeError(`default, ${rest.default}, must be an Array`);
|
|
90
|
+
return {
|
|
91
|
+
type: "array",
|
|
92
|
+
coerce,
|
|
93
|
+
required,
|
|
94
|
+
whenInvalid,
|
|
95
|
+
maxlength,
|
|
96
|
+
minlength,
|
|
97
|
+
...rest,
|
|
98
|
+
validate: validateArray
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
array.validate = validateArray;
|
|
102
|
+
array.coerce = false;
|
|
103
|
+
array.required = false;
|
|
104
|
+
|
|
105
|
+
const validateBoolean = function(value,variable) {
|
|
106
|
+
if(value===undefined && variable.value===undefined) {
|
|
107
|
+
return this.default;
|
|
108
|
+
}
|
|
109
|
+
if(variable.value===undefined) value = this.default;
|
|
110
|
+
if(this.required && value==null) {
|
|
111
|
+
variable.validityState = ValidityState({valueMissing: true});
|
|
112
|
+
} else {
|
|
113
|
+
const result = !!(this.coerce ? tryParse(value) : value);
|
|
114
|
+
if(typeof(result)!=="boolean") {
|
|
115
|
+
variable.validityState = ValidityState({typeMismatch: true, value});
|
|
116
|
+
} else {
|
|
117
|
+
variable.validityState = ValidityState({valid:true});
|
|
118
|
+
return result;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return this.whenInvalid(variable,value);
|
|
122
|
+
}
|
|
123
|
+
const boolean = ({coerce=false,required=false, whenInvalid = ifInvalid,...rest}) =>{
|
|
124
|
+
if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
|
|
125
|
+
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
126
|
+
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
127
|
+
if(rest.default!==undefined && typeof(rest.default)!=="boolean") throw new TypeError(`default, ${rest.default}, must be a boolean`);
|
|
128
|
+
return {
|
|
129
|
+
type: "boolean",
|
|
130
|
+
coerce,
|
|
131
|
+
required,
|
|
132
|
+
whenInvalid,
|
|
133
|
+
...rest,
|
|
134
|
+
validate: validateBoolean
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
boolean.validate = validateBoolean;
|
|
138
|
+
boolean.coerce = false;
|
|
139
|
+
boolean.required = false;
|
|
140
|
+
|
|
141
|
+
const validateNumber = function(value,variable) {
|
|
142
|
+
if(value===undefined && variable.value===undefined) {
|
|
143
|
+
return this.default;
|
|
144
|
+
}
|
|
145
|
+
if(this.required && value==null) {
|
|
146
|
+
variable.validityState = ValidityState({valueMissing: true});
|
|
147
|
+
} else {
|
|
148
|
+
const result = this.coerce ? tryParse(value) : value;
|
|
149
|
+
if(typeof(result)!=="number") {
|
|
150
|
+
variable.validityState = ValidityState({typeMismatch:true,value});
|
|
151
|
+
} else if(isNaN(result) && !allowNaN) {
|
|
152
|
+
variable.validityState = ValidityState({badInput:true,value});
|
|
153
|
+
} else if(result<this.min) {
|
|
154
|
+
variable.validityState = ValidityState({rangeUnderflow:true,value});
|
|
155
|
+
} else if(result>this.max) {
|
|
156
|
+
variable.validityState = ValidityState({rangeOverflow:true,value});
|
|
157
|
+
} else if((result % this.step)!==0) {
|
|
158
|
+
variable.validityState = ValidityState({rangeUnderflow:true,value});
|
|
159
|
+
} else {
|
|
160
|
+
variable.validityState = ValidityState({valid:true});
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return this.whenInvalid(variable,value);
|
|
165
|
+
}
|
|
166
|
+
const number = ({coerce=false,required = false,whenInvalid = ifInvalid,min=-Infinity,max=Infinity,step = 1,allowNaN = true,...rest}) => {
|
|
167
|
+
if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
|
|
168
|
+
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
169
|
+
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
170
|
+
if(typeof(min)!=="number") throw new TypeError(`min, ${JSON.stringify(min)}, must be a number`);
|
|
171
|
+
if(typeof(max)!=="number") throw new TypeError(`max, ${JSON.stringify(max)}, must be a number`);
|
|
172
|
+
if(typeof(step)!=="number") throw new TypeError(`step, ${JSON.stringify(step)}, must be a number`);
|
|
173
|
+
if(typeof(allowNaN)!=="boolean") throw new TypeError(`step, ${JSON.stringify(allowNaN)}, must be a boolean`);
|
|
174
|
+
if(rest.default!==undefined && typeof(rest.default)!=="number") throw new TypeError(`default, ${rest.default}, must be a number`);
|
|
175
|
+
return {
|
|
176
|
+
type: "number",
|
|
177
|
+
coerce,
|
|
178
|
+
required,
|
|
179
|
+
whenInvalid,
|
|
180
|
+
min,
|
|
181
|
+
max,
|
|
182
|
+
step,
|
|
183
|
+
allowNaN,
|
|
184
|
+
...rest,
|
|
185
|
+
validate: validateNumber
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
number.validate = validateNumber;
|
|
189
|
+
number.min = -Infinity;
|
|
190
|
+
number.max = Infinity;
|
|
191
|
+
number.coerce = false;
|
|
192
|
+
number.required = false;
|
|
193
|
+
number.allwNaN = true;
|
|
194
|
+
number.step = 1;
|
|
195
|
+
|
|
196
|
+
const validateObject = function(value,variable) {
|
|
197
|
+
if(value===undefined && variable.value===undefined) {
|
|
198
|
+
return this.default;
|
|
199
|
+
}
|
|
200
|
+
if(this.required && value==null) {
|
|
201
|
+
variable.validityState = ValidityState({valueMissing: true});
|
|
202
|
+
} else {
|
|
203
|
+
const result = this.coerce ? tryParse(value) : value;
|
|
204
|
+
if(typeof(result)!=="object") {
|
|
205
|
+
variable.validityState = ValidityState({typeMismatch:true,value});
|
|
206
|
+
} else {
|
|
207
|
+
variable.validityState = ValidityState({valid:true});
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return this.whenInvalid(variable,value);
|
|
212
|
+
}
|
|
213
|
+
const object = ({coerce=false, required = false,whenInvalid = ifInvalid,...rest}) => {
|
|
214
|
+
if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
|
|
215
|
+
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
216
|
+
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
217
|
+
if(rest.default!==undefined && typeof(rest.default)!=="object") throw new TypeError(`default, ${rest.default}, must be of type object`);
|
|
218
|
+
return {
|
|
219
|
+
type: "object",
|
|
220
|
+
coerce,
|
|
221
|
+
required,
|
|
222
|
+
whenInvalid,
|
|
223
|
+
...rest,
|
|
224
|
+
validate: validateObject
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
object.validate = validateObject;
|
|
228
|
+
object.coerce = false;
|
|
229
|
+
object.required = false;
|
|
230
|
+
|
|
231
|
+
const validateString = function(value,variable) {
|
|
232
|
+
if(value===undefined && variable.value===undefined) {
|
|
233
|
+
return this.default;
|
|
234
|
+
}
|
|
235
|
+
if(this.required && value==null) {
|
|
236
|
+
variable.validityState = ValidityState({valueMissing: true});
|
|
237
|
+
} else {
|
|
238
|
+
const result = this.coerce ? value+"" : value;
|
|
239
|
+
if(typeof(result)!=="string") {
|
|
240
|
+
variable.validityState = ValidityState({typeMismatch:true,value});
|
|
241
|
+
} else if(result.length<this.minlength) {
|
|
242
|
+
variable.validityState = ValidityState({tooShort:true,value});
|
|
243
|
+
} else if(result.length>this.maxlength) {
|
|
244
|
+
variable.validityState = ValidityState({tooLong:true,value});
|
|
245
|
+
} else {
|
|
246
|
+
variable.validityState = ValidityState({valid:true});
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return this.whenInvalid(variable,value);
|
|
251
|
+
}
|
|
252
|
+
const string = ({coerce=false, required = false,whenInvalid = ifInvalid, maxlength = Infinity, minlength = 0, pattern, ...rest}) => {
|
|
253
|
+
if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
|
|
254
|
+
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
255
|
+
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
256
|
+
if(typeof(maxlength)!=="number") throw new TypeError(`maxlength, ${JSON.stringify(maxlength)}, must be a number`);
|
|
257
|
+
if(typeof(minlength)!=="number") throw new TypeError(`minlength, ${JSON.stringify(minlength)}, must be a number`);
|
|
258
|
+
if(pattern && (typeof(pattern)!=="object" || !(pattern instanceof RegExp))) throw new TypeError(`pattern, ${pattern}, must be a RegExp`);
|
|
259
|
+
if(rest.default!==undefined && typeof(rest.default)!=="string") throw new TypeError(`default, ${rest.default}, must be a string`);
|
|
260
|
+
return {
|
|
261
|
+
type: "string",
|
|
262
|
+
coerce,
|
|
263
|
+
required,
|
|
264
|
+
whenInvalid,
|
|
265
|
+
maxlength,
|
|
266
|
+
minlength,
|
|
267
|
+
...rest,
|
|
268
|
+
validate: validateString
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
string.validate = validateString;
|
|
272
|
+
string.coerce = false;
|
|
273
|
+
string.required = false;
|
|
274
|
+
string.maxlength = Infinity;
|
|
275
|
+
string.minlength = 0;
|
|
276
|
+
|
|
277
|
+
const validateSymbol = function(value,variable) {
|
|
278
|
+
if(value===undefined && variable.value===undefined) {
|
|
279
|
+
return this.default;
|
|
280
|
+
}
|
|
281
|
+
if(this.required && value==null) {
|
|
282
|
+
variable.validityState = ValidityState({valueMissing: true});
|
|
283
|
+
} else {
|
|
284
|
+
const result = !!(this.coerce && typeof(value)!=="symbol" ? Symbol(value+"") : value);
|
|
285
|
+
if(typeof(result)!=="symbol") {
|
|
286
|
+
variable.validityState = ValidityState({typeMismatch: true, value});
|
|
287
|
+
} else {
|
|
288
|
+
variable.validityState = ValidityState({valid:true});
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return this.whenInvalid(variable,value);
|
|
293
|
+
}
|
|
294
|
+
const symbol = ({coerce=false,required=false, whenInvalid = ifInvalid,...rest}) =>{
|
|
295
|
+
if(typeof(coerce)!=="boolean") throw new TypeError(`coerce, ${JSON.stringify(coerce)}, must be a boolean`);
|
|
296
|
+
if(typeof(required)!=="boolean") throw new TypeError(`required, ${JSON.stringify(required)}, must be a boolean`);
|
|
297
|
+
if(typeof(whenInvalid)!=="function") throw new TypeError(`whenInvalid, ${whenInvalid}, must be a function`);
|
|
298
|
+
if(rest.default!==undefined && typeof(rest.default)!=="symbol") throw new TypeError(`default, ${rest.default}, must be a symbol`);
|
|
299
|
+
return {
|
|
300
|
+
type: "symbol",
|
|
301
|
+
coerce,
|
|
302
|
+
required,
|
|
303
|
+
whenInvalid,
|
|
304
|
+
...rest,
|
|
305
|
+
validate: validateSymbol
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
symbol.validate = validateSymbol;
|
|
309
|
+
symbol.coerce = false;
|
|
310
|
+
symbol.required = false;
|
|
311
|
+
|
|
312
|
+
const remoteProxy = ({json, variable,config, reactive, component}) => {
|
|
313
|
+
const type = typeof (config);
|
|
314
|
+
return new Proxy(json, {
|
|
315
|
+
get(target,property) {
|
|
316
|
+
if(property==="__remoteProxytarget__") return json;
|
|
317
|
+
return target[property];
|
|
318
|
+
},
|
|
319
|
+
async set(target, property, value) {
|
|
320
|
+
if(value && typeof(value)==="object" && value instanceof Promise) value = await value;
|
|
321
|
+
const oldValue = target[property];
|
|
322
|
+
if (oldValue !== value) {
|
|
323
|
+
let remotevalue;
|
|
324
|
+
if (type === "string") {
|
|
325
|
+
const href = new URL(config,window.location.href).href;
|
|
326
|
+
remotevalue = patch({target,property,value,oldValue},href,variable);
|
|
327
|
+
} else if(config && type==="object") {
|
|
328
|
+
let href;
|
|
329
|
+
if(config.path) href = new URL(config.path,window.location.href).href;
|
|
330
|
+
if(!config.patch) {
|
|
331
|
+
if(!href) throw new Error(`A remote path is required is no put function is provided for remote data`)
|
|
332
|
+
config.patch = patch;
|
|
333
|
+
}
|
|
334
|
+
remotevalue = config.patch({target,property,value,oldValue},href,variable);
|
|
335
|
+
}
|
|
336
|
+
if(remotevalue) {
|
|
337
|
+
await remotevalue.then((newjson) => {
|
|
338
|
+
if (newjson && typeof (newjson) === "object" && reactive) {
|
|
339
|
+
const target = variable.value?.__reactorProxyTarget__ ? json : variable.value;
|
|
340
|
+
Object.entries(newjson).forEach(([key,newValue]) => {
|
|
341
|
+
if(target[key]!==newValue) target[key] = newValue;
|
|
342
|
+
})
|
|
343
|
+
Object.keys(target).forEach((key) => {
|
|
344
|
+
if(!(key in newjson)) delete target[key];
|
|
345
|
+
});
|
|
346
|
+
if(variable.value?.__reactorProxyTarget__) {
|
|
347
|
+
const dependents = variable.value.__dependents__,
|
|
348
|
+
observers = dependents[property] || [];
|
|
349
|
+
[...observers].forEach((f) => {
|
|
350
|
+
if (f.cancelled) dependents[property].delete(f);
|
|
351
|
+
else f();
|
|
352
|
+
})
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
component.setVariableValue(variable.name,newjson)
|
|
356
|
+
//variable.value = json;
|
|
357
|
+
}
|
|
358
|
+
})
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
})
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const patch = ({target,property,value,oldValue},href,variable) => {
|
|
367
|
+
return fetch(href, {
|
|
368
|
+
method: "PATCH",
|
|
369
|
+
body: JSON.stringify({property,value,oldValue}),
|
|
370
|
+
headers: {
|
|
371
|
+
"Content-Type": "application/json"
|
|
372
|
+
}
|
|
373
|
+
}).then((response) => {
|
|
374
|
+
if (response.status < 400) return response.json();
|
|
375
|
+
})
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const get = (href,variable) => {
|
|
379
|
+
return fetch(href)
|
|
380
|
+
.then((response) => {
|
|
381
|
+
if (response.status < 400) return response.json();
|
|
382
|
+
})
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
const put = (href,variable) => {
|
|
386
|
+
return fetch(href, {
|
|
387
|
+
method: "PUT",
|
|
388
|
+
body: JSON.stringify(variable.value),
|
|
389
|
+
headers: {
|
|
390
|
+
"Content-Type": "application/json"
|
|
391
|
+
}
|
|
392
|
+
}).then((response) => {
|
|
393
|
+
if (response.status === 200) return response.json();
|
|
394
|
+
})
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const handleRemote = async ({variable, config, reactive, component},doput) => {
|
|
398
|
+
const type = typeof (config);
|
|
399
|
+
let value;
|
|
400
|
+
if (type === "string") {
|
|
401
|
+
const href = new URL(config,window.location.href).href;
|
|
402
|
+
value = (doput
|
|
403
|
+
? put(href,variable)
|
|
404
|
+
: get(href,variable));
|
|
405
|
+
if(variable.value===undefined) variable.value = value; // do not await here
|
|
406
|
+
} else if (remote && type === "object") {
|
|
407
|
+
let href;
|
|
408
|
+
if(!config.path) config.path = `./${variable.name}`;
|
|
409
|
+
if(config.path) href = new URL(config.path,window.location.href).href;
|
|
410
|
+
if(!config.get || !config.put) {
|
|
411
|
+
if(!href) throw new Error(`A remote path is required if no put function is provided for remote data`)
|
|
412
|
+
if(!config.get) config.get = get;
|
|
413
|
+
if(!config.put && reactive) config.put = put;
|
|
414
|
+
}
|
|
415
|
+
value = (doput
|
|
416
|
+
? config.put(href,variable)
|
|
417
|
+
: config.get(href,variable));
|
|
418
|
+
if(config.ttl && !doput && !config.intervalId) {
|
|
419
|
+
config.intervalId = setInterval(async () => {
|
|
420
|
+
await handleRemote({variable, config, reactive, component});
|
|
421
|
+
//schedule();
|
|
422
|
+
},config.ttl);
|
|
423
|
+
}
|
|
424
|
+
if(variable.value===undefined) variable.value = value;
|
|
425
|
+
}
|
|
426
|
+
if(value) {
|
|
427
|
+
const json = await value;
|
|
428
|
+
//value.then((json) => {
|
|
429
|
+
if (json && typeof (json) === "object" && reactive) {
|
|
430
|
+
variable.value = remoteProxy({json, variable,config, reactive, component});
|
|
431
|
+
} else {
|
|
432
|
+
component.setVariableValue(variable.name,json);
|
|
433
|
+
}
|
|
434
|
+
//})
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const remote = (config) => {
|
|
439
|
+
return {
|
|
440
|
+
config,
|
|
441
|
+
handleRemote
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export {ValidityState,any,array,boolean,number,string,symbol,remote}
|