@sumaris-net/ngx-components 2.0.0-rc39 → 2.0.0-rc40

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.
@@ -11168,7 +11168,6 @@ EntityClasses.CLASSES_BY_NAME = new Map();
11168
11168
  function EntityClass(opts) {
11169
11169
  // eslint-disable-next-line prefer-arrow/prefer-arrow-functions
11170
11170
  return function (constructor) {
11171
- var _a, _b;
11172
11171
  // Make sure the class extends Entity
11173
11172
  if (!environment.production) {
11174
11173
  const obj = new constructor();
@@ -11176,61 +11175,82 @@ function EntityClass(opts) {
11176
11175
  throw new Error(`Class ${constructor.name} must extends <<Entity>> to be able to use @FromObject!`);
11177
11176
  }
11178
11177
  }
11179
- const typename = opts?.typename || `${constructor.name}VO`;
11180
- if (opts?.fromObjectReuseStrategy === 'clone') {
11181
- const decoratedClass = (_a = class extends constructor {
11182
- static fromObject(source, opts) {
11183
- if (!source)
11184
- return undefined;
11185
- if (source instanceof decoratedClass)
11186
- return source.clone(opts);
11187
- const target = new decoratedClass();
11188
- target.fromObject(source, opts);
11189
- return target;
11190
- }
11191
- static asObject(source, opts) {
11192
- if (!source)
11193
- return undefined;
11194
- if (source instanceof decoratedClass)
11195
- return source.asObject(opts);
11196
- return Object.assign({}, source);
11197
- }
11198
- },
11199
- _a.TYPENAME = typename,
11200
- _a);
11201
- // Register the entity class
11202
- EntityClasses.register(typename, decoratedClass);
11203
- return decoratedClass;
11204
- }
11205
- const decoratedClass = (_b = class extends constructor {
11206
- static fromObject(source, opts) {
11178
+ const clazz = constructor;
11179
+ const typename = opts.typename || `${constructor.name}VO`;
11180
+ // Define static field TYPENAME
11181
+ clazz.TYPENAME = typename;
11182
+ // Define static fromObject()
11183
+ if (!clazz.fromObject) {
11184
+ if (opts.fromObjectReuseStrategy === 'clone') {
11185
+ constructor.fromObject = function (source, opts) {
11186
+ if (!source)
11187
+ return undefined;
11188
+ if (source instanceof constructor)
11189
+ return source.clone(opts);
11190
+ const target = new constructor();
11191
+ target.fromObject(source, opts);
11192
+ return target;
11193
+ };
11194
+ constructor.asObject = function (source, opts) {
11207
11195
  if (!source)
11208
11196
  return undefined;
11209
- if (source instanceof decoratedClass) {
11197
+ if (source instanceof constructor)
11198
+ return source.asObject(opts);
11199
+ return Object.assign({}, source);
11200
+ };
11201
+ }
11202
+ else {
11203
+ clazz.fromObject = function (source, opts) {
11204
+ if (!source)
11205
+ return undefined;
11206
+ if (source instanceof constructor) {
11210
11207
  // DEBUG
11211
11208
  //console.debug('@EntityClass() fromObject() => will recycle existing object: ', source);
11212
11209
  return source;
11213
11210
  }
11214
- const target = new decoratedClass();
11211
+ const target = new constructor();
11215
11212
  target.fromObject(source, opts);
11216
11213
  return target;
11217
- }
11218
- static asObject(source, opts) {
11214
+ };
11215
+ clazz.asObject = function (source, opts) {
11219
11216
  if (!source)
11220
11217
  return undefined;
11221
- if (source instanceof decoratedClass) {
11218
+ if (source instanceof constructor) {
11222
11219
  return source.asObject(opts);
11223
11220
  }
11224
11221
  // DEBUG
11225
11222
  //console.debug('@EntityClass() asObject() => will recycle existing object: ', source);
11226
11223
  return source;
11227
- }
11228
- },
11229
- _b.TYPENAME = typename,
11230
- _b);
11224
+ };
11225
+ }
11226
+ }
11227
+ // Define static asObject()
11228
+ if (!clazz.asObject) {
11229
+ if (opts.fromObjectReuseStrategy === 'clone') {
11230
+ clazz.asObject = function (source, opts) {
11231
+ if (!source)
11232
+ return undefined;
11233
+ if (source instanceof constructor)
11234
+ return source.asObject(opts);
11235
+ return Object.assign({}, source);
11236
+ };
11237
+ }
11238
+ else {
11239
+ clazz.asObject = function (source, opts) {
11240
+ if (!source)
11241
+ return undefined;
11242
+ if (source instanceof constructor) {
11243
+ return source.asObject(opts);
11244
+ }
11245
+ // DEBUG
11246
+ //console.debug('@EntityClass() asObject() => will recycle existing object: ', source);
11247
+ return source;
11248
+ };
11249
+ }
11250
+ }
11231
11251
  // Register the entity class
11232
- EntityClasses.register(typename, decoratedClass);
11233
- return decoratedClass;
11252
+ EntityClasses.register(typename, constructor);
11253
+ return constructor;
11234
11254
  };
11235
11255
  }
11236
11256