x4js 2.2.65 → 2.2.66
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/package.json +1 -1
- package/src/core/core_data.ts +46 -41
package/package.json
CHANGED
package/src/core/core_data.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @file core_data.ts
|
|
9
9
|
* @author Etienne Cochard
|
|
10
10
|
*
|
|
11
|
-
* @copyright (c)
|
|
11
|
+
* @copyright (c) 2024 R-libre ingenierie
|
|
12
12
|
*
|
|
13
13
|
* Use of this source code is governed by an MIT-style license
|
|
14
14
|
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
@@ -78,7 +78,18 @@ const metaFields = Symbol( 'metaField' );
|
|
|
78
78
|
function _getMetas( obj: object, create = true ) : MetaInfos {
|
|
79
79
|
|
|
80
80
|
let ctor = obj.constructor as any;
|
|
81
|
-
let mfld =
|
|
81
|
+
let mfld = null;
|
|
82
|
+
let direct = false;
|
|
83
|
+
|
|
84
|
+
// comming from new DataModel(...)
|
|
85
|
+
if( ctor.name=="DataModel" ) {
|
|
86
|
+
direct = true;
|
|
87
|
+
mfld = (obj as any)[metaFields];
|
|
88
|
+
}
|
|
89
|
+
// standard @data....
|
|
90
|
+
else {
|
|
91
|
+
mfld = Object.prototype.hasOwnProperty.call(ctor,metaFields) ? ctor[metaFields] : undefined;
|
|
92
|
+
}
|
|
82
93
|
|
|
83
94
|
if( mfld===undefined ) {
|
|
84
95
|
if( !create && ctor!=DataModel ) {
|
|
@@ -102,7 +113,12 @@ function _getMetas( obj: object, create = true ) : MetaInfos {
|
|
|
102
113
|
}
|
|
103
114
|
}
|
|
104
115
|
|
|
105
|
-
(
|
|
116
|
+
if( !direct ) {
|
|
117
|
+
(obj.constructor as any)[metaFields] = mfld;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
(obj as any)[metaFields] = mfld;
|
|
121
|
+
}
|
|
106
122
|
}
|
|
107
123
|
|
|
108
124
|
return mfld;
|
|
@@ -119,17 +135,17 @@ export namespace data {
|
|
|
119
135
|
**/
|
|
120
136
|
|
|
121
137
|
export function id( ) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
return ( ownerCls: any, fldName: string ) => {
|
|
139
|
+
let metas = _getMetas( ownerCls );
|
|
140
|
+
metas.fields.push( {
|
|
141
|
+
name: fldName,
|
|
142
|
+
type: 'any',
|
|
143
|
+
required: true,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
metas.id = fldName;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
133
149
|
|
|
134
150
|
/**
|
|
135
151
|
* @ignore
|
|
@@ -254,12 +270,6 @@ export namespace data {
|
|
|
254
270
|
|
|
255
271
|
export class DataModel<T = any> {
|
|
256
272
|
|
|
257
|
-
constructor( fields?: FieldInfo[] ) {
|
|
258
|
-
if( fields && fields.length ) {
|
|
259
|
-
this.addField( ...fields );
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
273
|
/**
|
|
264
274
|
* dynamic DataModel
|
|
265
275
|
*/
|
|
@@ -270,11 +280,11 @@ export class DataModel<T = any> {
|
|
|
270
280
|
}
|
|
271
281
|
|
|
272
282
|
let metas = _getMetas( this, false );
|
|
273
|
-
|
|
283
|
+
metas.fields.push( ...fields );
|
|
284
|
+
|
|
285
|
+
if( !metas.id ) {
|
|
274
286
|
metas.id = fields[0].name;
|
|
275
287
|
}
|
|
276
|
-
|
|
277
|
-
metas.fields.push( ...fields );
|
|
278
288
|
}
|
|
279
289
|
|
|
280
290
|
/**
|
|
@@ -523,24 +533,16 @@ export class DataProxy extends CoreElement<DataEventMap> {
|
|
|
523
533
|
url += '?' + this.m_props.params.join( '&' );
|
|
524
534
|
}
|
|
525
535
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
json = this.m_props.solver( json );
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
this.fire( 'change', {value:json,context:raw} );
|
|
537
|
-
}
|
|
538
|
-
else {
|
|
539
|
-
console.error( r.statusText );
|
|
536
|
+
const r = await fetch( url );
|
|
537
|
+
if( r.ok ) {
|
|
538
|
+
const raw = await r.json( );
|
|
539
|
+
|
|
540
|
+
let json = raw;
|
|
541
|
+
if( this.m_props.solver ) {
|
|
542
|
+
json = this.m_props.solver( json );
|
|
540
543
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
console.error( e );
|
|
544
|
+
|
|
545
|
+
this.fire( 'change', {value:json,context:raw} );
|
|
544
546
|
}
|
|
545
547
|
}
|
|
546
548
|
}
|
|
@@ -608,6 +610,7 @@ export class DataStore<T = any> extends EventSource<DataStoreEventMap> {
|
|
|
608
610
|
|
|
609
611
|
/**
|
|
610
612
|
*
|
|
613
|
+
* @param records
|
|
611
614
|
*/
|
|
612
615
|
|
|
613
616
|
async load( url?: string ) {
|
|
@@ -671,7 +674,7 @@ export class DataStore<T = any> extends EventSource<DataStoreEventMap> {
|
|
|
671
674
|
|
|
672
675
|
/**
|
|
673
676
|
*
|
|
674
|
-
* @param
|
|
677
|
+
* @param data
|
|
675
678
|
*/
|
|
676
679
|
|
|
677
680
|
public appendRaw( rec: T ) {
|
|
@@ -1211,6 +1214,8 @@ export class DataView extends CoreElement<DataViewEventMap>
|
|
|
1211
1214
|
|
|
1212
1215
|
/**
|
|
1213
1216
|
*
|
|
1217
|
+
* @param columns
|
|
1218
|
+
* @param ascending
|
|
1214
1219
|
*/
|
|
1215
1220
|
|
|
1216
1221
|
public sort( props: SortProp[] ) {
|