jsgui3-server 0.0.116 → 0.0.118

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.
@@ -152,26 +152,44 @@ class Demo_UI extends Active_HTML_Document {
152
152
  // Automatically avoiding feedback somehow???
153
153
  // If it gets changed to its current value it does not push the change...?
154
154
 
155
+ // on the data model change instead....
155
156
 
156
- ti1.on('change', e => {
157
+
158
+ // Code has got more complex supporting things by data model changes for the moment.
159
+ // May help a lot when making it more explicit.
160
+
161
+
162
+
163
+ // But could make 'on' (normally?) refer to the .data.model???
164
+ // For the moment, keep the more explicit notations, as well as backwards compatibility.
165
+
166
+ // ctrl.dom.on may help, be a nicer and more concise syntax, just as explicit (considering the 'on' abbreviatrion)
167
+
168
+
169
+ // does seem convenient having .on refer to dom events if it's an appropriate event name for that.
170
+
171
+
172
+
173
+
174
+ ti1.data.model.on('change', e => {
157
175
  //console.log('ti1 change e', e);
158
176
 
159
177
  if (e.value !== e.old) {
160
- ti2.value = e.value;
178
+ ti2.data.model.value = e.value;
161
179
  }
162
180
 
163
181
 
164
182
 
165
- })
166
- ti2.on('change', e => {
183
+ });
184
+ ti2.data.model.on('change', e => {
167
185
  //console.log('ti2 change e', e);
168
186
 
169
187
  if (e.value !== e.old) {
170
- ti1.value = e.value;
188
+ ti1.data.model.value = e.value;
171
189
  }
172
190
 
173
191
 
174
- })
192
+ });
175
193
 
176
194
  // listen for change events.
177
195
  // would be nice to know which change events originated from the user interacting with that specific HTML element (or ctrl???)
@@ -12,6 +12,105 @@ const Active_HTML_Document = require('../../../controls/Active_HTML_Document');
12
12
  // May want code that checks for .el being changed.
13
13
 
14
14
 
15
+ /*
16
+ Though this works through simple principles, it may be much better to do data binding with a shared ctrl.data.model.
17
+ Want the top-level code to be really simple and intuitive when specifying data flows, and when not specifying them
18
+ using sensible defaults.
19
+
20
+ The granularity between data.model and view.model should help a lot.
21
+
22
+ // Also data.model.value being a possible default.
23
+ // Data models will become more advanced and capable of holding multiple values.
24
+ // For the moment, although the Control_Data and Control_View classes exist, will continue with a POJO.
25
+ // Then could later work on getter / setters for when a data.model or a view.model gets changed.
26
+
27
+
28
+
29
+ Also should work on functional constraints or / and class based constraints for fields / text fields.
30
+ // Both for data in the system, as well as in the UI.
31
+ // Could integrate a bit more with data types / class data types.
32
+
33
+ // Typed_Data_Value perhaps.
34
+
35
+ // Anyway, want to set things up better with the .view.model and .data.model system.
36
+
37
+ // Then later support more complex (and / or app-defined) data and view models.
38
+
39
+ // Defining what the underlying data of the app is could help (a lot).
40
+ // Some data may be for editing, some not.
41
+
42
+ // A data model could have a bunch of news articles, and be set up so that they can be viewed nicely.
43
+ // Would not be so important to edit the articles themselves, though maybe the user may want to tag them
44
+ // and comment on them.
45
+
46
+ // Mid-level complexity handling a fair bit of what needs to happen with multiple models, how updates get sequenced
47
+ // but then at a high level code must be really simple.
48
+ // Could distinguish between view and data models at high level - may help a lot in some cases.
49
+ // However, will generally assume a shared data model between controls, not a shared view model, and the data model
50
+ // will be updated with at least some small / sensible hesitation.
51
+ // Maybe even define the update hesitations / update hesitation mode.
52
+ // Data Model Update Hesitation Mode???
53
+
54
+ // View Model To Data Model Syncing Update Hesitation Mode???
55
+ // really explicit names on the more complex mid level will help the code and system to make sense.
56
+
57
+ // syncing.view_to_data.hesitation = 'leave-control' ????
58
+ // And could have that one as the default.
59
+ // Or could hesitate / debounce 250ms for example.
60
+ // Very very explicit on the more complex mid / lower level, so that it's really simple on the higher level,
61
+ // and can (quickly?) get into more explicit details when needed.
62
+
63
+ // Data model syncing seems best in general.
64
+ // Then sync data model changes immediately to view models.
65
+ // Then only sync view model changes to data model after necessary hesitation / event / confirmation.
66
+ // Also be able to cancel view model changes (load values back from data model possibly, some contexts makes a lot more sense)
67
+
68
+
69
+ // The view model is essentially internal to the control - though maybe it would integrate with a whole Page_Context view
70
+ // model that's for all the controls...?
71
+
72
+ // Internal and separate view models for the controls seems best for the moment.
73
+ // Could always use refs to some place else.
74
+
75
+ // Have the controls automatically create their view model.
76
+
77
+ // Some controls should not determine the data model at application (or larger control) start.
78
+ // Maybe some should?
79
+
80
+ // Or better to change it so that the Data_Model gets set first, then all the controls given access to it at start (on server)
81
+ // and get rendered on the server with the correct data, then on the client it only sets the view_model at the start.
82
+ // Or does it???
83
+ // Want different sensible options for getting that Data_Model to the client. Maybe getting the View_Model to the client????
84
+
85
+ // Make it simple and easy to code on the top level API.
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
+
15
114
 
16
115
 
17
116
 
@@ -65,6 +164,20 @@ class Demo_UI extends Active_HTML_Document {
65
164
 
66
165
  window.size = [480, 160];
67
166
 
167
+ // Without specifying the data model.
168
+ // Should be able to use and refer to data and view models even when not specified.
169
+ // Want this complexity on the lower level to enable simple (but not overly simple/simplstic) higher level programming.
170
+
171
+
172
+
173
+ // Should set up its data model automatically if not specified here.
174
+ // An independent data model, specifically for that text field.
175
+
176
+ // Or in the data.model.label_text perhaps?
177
+
178
+ // Want to make it easy to make and use somewhat more complex and expressive structures.
179
+
180
+ // The text label makes more sense being in the view.data.model???
68
181
 
69
182
  const ti1 = new Text_Field({
70
183
  context,
@@ -92,20 +205,86 @@ class Demo_UI extends Active_HTML_Document {
92
205
 
93
206
 
94
207
  this._ctrl_fields = this._ctrl_fields || {};
95
- this._ctrl_fields.ti1 = ti1;
96
- this._ctrl_fields.ti2 = ti2;
208
+ this._ctrl_fields.ti1 = this.ti1 = ti1;
209
+ this._ctrl_fields.ti2 = this.ti2 = ti2;
97
210
 
98
211
 
99
212
  }
100
213
  if (!spec.el) {
101
214
  compose();
215
+ this.add_change_listeners();
102
216
  }
217
+
218
+
219
+ // Can respond to / deal with changes to the data models here, not only when activated.
220
+ // The data.model and view.model system seems to offer some higher level improved programming by putting
221
+ // more in the constructor. Maybe the activated code ('.activate') would not be needed on higher level controls,
222
+ // because the lower level ones will connect it all up the the dom <> view <> data models / system.
223
+
224
+ // It even has a 'dom model' too, of sorts ????
225
+ // Though currently it's not named that or considered that throughout the code there.
226
+ // Could be worth moding to dom.model
227
+ // then view.model
228
+ // then data.model
229
+
230
+ // Could be a structure that better supports non-dom models.
231
+ // Though in this case, it would no yet have the refs to all the child things????
232
+
233
+ // Getting that back in the 'compose' or 'recompose' stage could help.
234
+ // Though it's currently auto-recompose pre activate.
235
+
236
+ // Maybe want code to run either when activated, or post-compose.
237
+ // add_change_listeners.
238
+
239
+ // Would be run server-side after compose (or when composing it like that on the client)
240
+ // but when it gets recomosed on the client-side would need to run then instead.
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
103
251
  }
252
+
253
+ add_change_listeners() {
254
+ const {ti1, ti2} = this;
255
+
256
+ // Need to fix the text_field data model and view model system.
257
+
258
+ //console.log('add_change_listeners');
259
+ ti1.data.model.on('change', e => {
260
+ //console.log('ti1 e', e);
261
+ if (e.name === 'value') {
262
+ if (e.value !== e.old) {
263
+ ti2.data.model.value = e.value;
264
+ }
265
+ }
266
+ });
267
+
268
+ ti2.data.model.on('change', e => {
269
+ //console.log('ti2 e', e);
270
+ if (e.name === 'value') {
271
+ if (e.value !== e.old) {
272
+ ti1.data.model.value = e.value;
273
+ }
274
+ }
275
+ });
276
+
277
+ }
278
+
279
+
104
280
  activate() {
105
281
  if (!this.__active) {
106
282
  super.activate();
107
283
  const {context, ti1, ti2} = this;
108
284
 
285
+ this.add_change_listeners();
286
+
287
+
109
288
  console.log('activate Demo_UI');
110
289
  // and events dealing with changes to those tis.
111
290
 
@@ -144,13 +323,21 @@ class Demo_UI extends Active_HTML_Document {
144
323
 
145
324
  // Need to work on having it update the dom with value changes....
146
325
 
147
- ti1.model.on('change', e => {
148
- //console.log('ti1 change e', e);
326
+ // .data.model change instead.
327
+ // referring to a .data.model does seem like a more explicit way to do it.
328
+ // definitely looks like a good way to avoid confusion, at a small cost of more code to write.
329
+
330
+ /*
331
+
332
+ ti1.data.model.on('change', e => {
333
+ console.log('ti1.data.model change e', e);
334
+
335
+
149
336
 
150
337
 
151
- if (e.property_name === 'value') {
338
+ if (e.name === 'value') {
152
339
  if (e.value !== e.old) {
153
- ti2.value = e.value;
340
+ ti2.data.model.value = e.value;
154
341
  }
155
342
  }
156
343
 
@@ -160,17 +347,22 @@ class Demo_UI extends Active_HTML_Document {
160
347
 
161
348
 
162
349
  })
163
- ti2.model.on('change', e => {
164
- //console.log('ti2 change e', e);
350
+ ti2.data.model.on('change', e => {
351
+ console.log('ti2.data.model change e', e);
165
352
 
166
353
  //
167
354
 
168
- if (e.value !== e.old) {
169
- ti1.value = e.value;
355
+ if (e.name === 'value') {
356
+ if (e.value !== e.old) {
357
+ ti1.data.model.value = e.value;
358
+ }
170
359
  }
171
360
 
172
361
 
362
+
363
+
173
364
  })
365
+ */
174
366
 
175
367
  // listen for change events.
176
368
  // would be nice to know which change events originated from the user interacting with that specific HTML element (or ctrl???)