@lango-project/lango-client 0.4.0 → 0.4.1

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.
@@ -0,0 +1,119 @@
1
+ import js global Object
2
+ import js global Reflect
3
+ import js global Promise
4
+
5
+ export class TableScope(parent)
6
+ properties
7
+ parent
8
+ requestForm
9
+ app
10
+ token
11
+ controls
12
+ owned
13
+ resources
14
+ disposed
15
+ methods
16
+ register(name, control)
17
+ unregister(control)
18
+ find(name)
19
+ getValue()
20
+ setValue(values)
21
+ prepareValue()
22
+ clearValidation()
23
+ clearResources()
24
+ send(url)
25
+ dispose()
26
+
27
+ TableScope(parent)
28
+ @parent = parent
29
+ @app = parent.app
30
+ @requestForm = parent
31
+ if parent.requestForm != null
32
+ @requestForm = parent.requestForm
33
+ token = ()
34
+ return @requestForm.token
35
+ Object/defineProperty(@this, "token", {
36
+ get: token
37
+ })
38
+ @controls = Object/create(null)
39
+ @owned = []
40
+ @resources = []
41
+ @disposed = false
42
+
43
+ TableScope:register(name, control)
44
+ if name != null
45
+ if !is_string(name) or name == "" or name.includes("/") or name in @controls
46
+ control.dispose()
47
+ throw "Invalid or duplicate control name: ${name}"
48
+ @controls[name] = control
49
+ @owned.add(control)
50
+ return control
51
+
52
+ TableScope:unregister(control)
53
+ for Object/keys(@controls) as name
54
+ if @controls[name] == control
55
+ Reflect/deleteProperty(@controls, name)
56
+ index = @owned.indexOf(control)
57
+ if index >= 0
58
+ @owned.splice(index, 1)
59
+ return null
60
+
61
+ TableScope:find(name)
62
+ parts = name.split("/")
63
+ child = @controls[parts.shift()]
64
+ if child == null
65
+ throw "Unknown control: ${name}"
66
+ if parts.length > 0
67
+ if child.find == null
68
+ throw "Control has no named children: ${name}"
69
+ return child.find(parts.join("/"))
70
+ return child
71
+
72
+ TableScope:getValue()
73
+ result = Object/create(null)
74
+ for @controls as name: control
75
+ result[name] = control.getValue()
76
+ return result
77
+
78
+ TableScope:setValue(values)
79
+ if !is_object(values) or is_array(values)
80
+ throw "Multiple cell controls require a value map"
81
+ for values as name: value
82
+ find(name).setValue(value)
83
+ return @this
84
+
85
+ TableScope:prepareValue()
86
+ pending = []
87
+ for @owned as control
88
+ if control.prepareValue != null
89
+ ready = control.prepareValue()
90
+ if ready != null
91
+ pending.add(ready)
92
+ if pending.length == 0
93
+ return null
94
+ return Promise/all(pending)
95
+
96
+ TableScope:clearValidation()
97
+ for @owned as control
98
+ if control.clearValidation != null
99
+ control.clearValidation()
100
+ return null
101
+
102
+ TableScope:clearResources()
103
+ return @parent.clearResources()
104
+
105
+ TableScope:send(url)
106
+ return @parent.send(url)
107
+
108
+ TableScope:dispose()
109
+ if @disposed
110
+ return null
111
+ @disposed = true
112
+ for @owned.slice() as control
113
+ control.dispose()
114
+ for @resources as release
115
+ release()
116
+ @owned = []
117
+ @controls = Object/create(null)
118
+ @resources = []
119
+ return null