@singularsystems/neo-core 0.10.61 → 0.10.62

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.
@@ -4,7 +4,7 @@ import { ITooltipOptions } from "./TooltipOptions";
4
4
  export interface IButtonOptions {
5
5
  /** True if the click event of this button must be invoked when the parent form of this button is submitted. */
6
6
  isSubmit?: boolean;
7
- /** The id of the form this button should attached to. Use this if the button is not a descendent of the form. */
7
+ /** The id of the form this button should attach to. Use this if the button is not nested within the form. */
8
8
  form?: string;
9
9
  /** Bootstrap variant */
10
10
  variant?: variant;
@@ -1,4 +1,4 @@
1
- import { TransformMetaType, PartialPlainObject, PlainFlatObject, PartialOrNull } from './IModelBase';
1
+ import { TransformMetaType, PartialPlainObject, PlainFlatObject, PartialOrNull, IMakeBindableOptions } from './IModelBase';
2
2
  import { NeoTypeInfo } from './NeoTypeInfo';
3
3
  import { IDeserialiseOptions } from '../Data/Deserialiser';
4
4
  export declare abstract class BindableBase {
@@ -30,6 +30,12 @@ export declare abstract class BindableBase {
30
30
  * This method can be used as an alternative to the @NeoModel decorator.
31
31
  */
32
32
  protected makeObservable(): void;
33
+ /**
34
+ * Makes the model bindable (and observable if it inherits from ModelBase) by creating its 'meta' object.
35
+ * Must be called in the constructor, preferably directly after the super() call.
36
+ * This method can be used as an alternative to the @NeoModel decorator.
37
+ */
38
+ protected makeBindable(options?: IMakeBindableOptions): void;
33
39
  static neo: NeoTypeInfo;
34
40
  /**
35
41
  * Creates a new instance of this type, and deserialises the plain javascript object graph into it.
@@ -1,7 +1,7 @@
1
1
  import { __assign, __decorate, __metadata } from "tslib";
2
2
  import { NoTracking, Observable } from './Decorators';
3
3
  import { JSFormatter } from '../Data/Serialiser';
4
- import { ensureTypeInfo } from './NeoTypeInfo';
4
+ import { NeoTypeInfo } from './NeoTypeInfo';
5
5
  import { Utils } from '../Utils';
6
6
  import { SerialiseType } from './Misc';
7
7
  var BindableBase = /** @class */ (function () {
@@ -42,11 +42,15 @@ var BindableBase = /** @class */ (function () {
42
42
  * This method can be used as an alternative to the @NeoModel decorator.
43
43
  */
44
44
  BindableBase.prototype.makeObservable = function () {
45
- // Ensure neo info is set
46
- var ctor = this.constructor;
47
- // Call this in case no property decorators were added
48
- ensureTypeInfo(ctor);
49
- ctor.neo.makeObservable(this);
45
+ this.makeBindable({ makeObservable: true });
46
+ };
47
+ /**
48
+ * Makes the model bindable (and observable if it inherits from ModelBase) by creating its 'meta' object.
49
+ * Must be called in the constructor, preferably directly after the super() call.
50
+ * This method can be used as an alternative to the @NeoModel decorator.
51
+ */
52
+ BindableBase.prototype.makeBindable = function (options) {
53
+ NeoTypeInfo.makeObservable(this, options);
50
54
  };
51
55
  /**
52
56
  * Creates a new instance of this type, and deserialises the plain javascript object graph into it.
@@ -41,6 +41,19 @@ export declare type PartialPlainNonTrackedObject<T> = PartialPlainObject<T> & {
41
41
  export interface NeoModelConstructor extends Function {
42
42
  neo: NeoTypeInfo;
43
43
  }
44
+ export interface IMakeBindableOptions {
45
+ /**
46
+ * Specifies whether properties should be observable
47
+ * * If this is `true`, all properties will be observable by default.
48
+ * * If `false` only properties decorated with @Attributes.Observable will be made observable.
49
+ * * If `undefined`, only types that inherit from `ModelBase` will be observable by default.
50
+ */
51
+ makeObservable?: boolean;
52
+ /**
53
+ * If `true`, this instance will not be converted. In inheritence heirarchies, use this to ensure only the last derived type converts the instance.
54
+ */
55
+ skipConversion?: boolean;
56
+ }
44
57
  export interface IDebounceOptions {
45
58
  delayMs?: number;
46
59
  }
@@ -1,9 +1,9 @@
1
1
  import { NeoTypeInfo } from './NeoTypeInfo';
2
- import { NeoModelConstructor } from './IModelBase';
2
+ import { IMakeBindableOptions, NeoModelConstructor } from './IModelBase';
3
3
  export default interface IModelCreatorBase {
4
4
  shouldInitialiseAllMembers: boolean;
5
5
  initialise(typeInfo: NeoTypeInfo, originalConstructor: NeoModelConstructor): void;
6
6
  isBindableBase(type: NeoModelConstructor): boolean;
7
7
  isModelBase(type: NeoModelConstructor): boolean;
8
- convertInstance(instance: {}): {};
8
+ convertInstance(instance: {}, options: IMakeBindableOptions): {};
9
9
  }
@@ -2,6 +2,7 @@ import { __assign, __extends } from "tslib";
2
2
  import { JSFormatter } from '../Data/Serialiser';
3
3
  import { Utils } from '../Utils';
4
4
  import { ObservableValue } from './ObservableValue';
5
+ import { NeoTypeInfo } from './NeoTypeInfo';
5
6
  var List = /** @class */ (function (_super) {
6
7
  __extends(List, _super);
7
8
  function List(childObjectType) {
@@ -179,8 +180,7 @@ var List = /** @class */ (function (_super) {
179
180
  }
180
181
  else {
181
182
  var ctor = this.childObjectType.prototype.constructor;
182
- ctor.neo.ensureInitialised();
183
- return ctor.neo.metaItem;
183
+ return NeoTypeInfo.ensureInitialised(ctor).metaItem;
184
184
  }
185
185
  };
186
186
  Object.defineProperty(List.prototype, "isValid", {
@@ -1,7 +1,8 @@
1
1
  import { NeoTypeInfo } from './NeoTypeInfo';
2
- import { NeoModelConstructor } from './IModelBase';
2
+ import { IMakeBindableOptions, NeoModelConstructor } from './IModelBase';
3
3
  import PropertyInfo from './PropertyInfo';
4
- export declare abstract class ModelCreatorBase {
4
+ import IModelCreatorBase from './IModelCreatorBase';
5
+ export declare abstract class ModelCreatorBase implements IModelCreatorBase {
5
6
  protected typeInfo: NeoTypeInfo;
6
7
  protected alwaysInitialiseMembers: boolean;
7
8
  /**
@@ -19,5 +20,5 @@ export declare abstract class ModelCreatorBase {
19
20
  protected ensureChildInfo(instance: {}, propertyInfo: PropertyInfo): void;
20
21
  protected addMethodInfo(methodName: string, method: Function): void;
21
22
  protected addProperty(propertyName: string, descriptor: PropertyDescriptor): void;
22
- abstract convertInstance(instance: {}): {};
23
+ abstract convertInstance(instance: {}, options: IMakeBindableOptions): {};
23
24
  }
@@ -1,10 +1,11 @@
1
1
  import { Rule } from '../Validation/Rules';
2
2
  import { PropertyInstanceMap } from './PropertyInstance';
3
3
  import PropertyInfo, { PropertyInfoMap } from './PropertyInfo';
4
- import { NeoModelConstructor, IModelBase, IMetaItem } from './IModelBase';
4
+ import { NeoModelConstructor, IModelBase, IMetaItem, IMakeBindableOptions } from './IModelBase';
5
5
  export declare class NeoTypeInfo {
6
6
  private modelCreator;
7
7
  private objectConstructor;
8
+ private wrapperConstructor?;
8
9
  private _inheritsBindableBase;
9
10
  private _inheritsModelBase;
10
11
  private _metaItem;
@@ -35,7 +36,16 @@ export declare class NeoTypeInfo {
35
36
  ensureInitialised(): void;
36
37
  /** Gets the override constructor which can setup a neo model. */
37
38
  getOverrideConstructor(): Function;
38
- makeObservable(instance: any): {};
39
+ private createWrapperConstructor;
40
+ makeObservable(instance: any, options?: IMakeBindableOptions): any;
39
41
  private defineProxyProperty;
42
+ /**
43
+ * Makes a class instance observable.
44
+ * Must be called in the constructor, preferably directly after the super() call.
45
+ * This method can be used as an alternative to the @NeoModel decorator.
46
+ */
47
+ static makeObservable(instance: any, options?: IMakeBindableOptions): void;
48
+ /** Ensures the type and its metadata are initialised. */
49
+ static ensureInitialised(constructor: NeoModelConstructor): NeoTypeInfo;
40
50
  }
41
51
  export declare function ensureTypeInfo(constructor: NeoModelConstructor): NeoModelConstructor;
@@ -9,6 +9,7 @@ import NeoTypes from '../AppServices/NeoTypes';
9
9
  import { RelationType } from './Misc';
10
10
  var ignoredPropertyNames = ["$mobx"];
11
11
  var inversifyMetadataKey = "inversify:tagged";
12
+ var hasConvertedSymbol = Symbol("hasConvertedModel");
12
13
  var NeoTypeInfo = /** @class */ (function () {
13
14
  function NeoTypeInfo() {
14
15
  this._inheritsBindableBase = false;
@@ -164,11 +165,22 @@ var NeoTypeInfo = /** @class */ (function () {
164
165
  NeoTypeInfo.prototype.ensureInitialised = function () {
165
166
  if (!this.modelCreator) {
166
167
  // create a new instance which will cause the type to be setup.
167
- this.getOverrideConstructor()();
168
+ if (this.wrapperConstructor) {
169
+ this.wrapperConstructor();
170
+ }
171
+ else {
172
+ void new this.objectConstructor();
173
+ }
168
174
  }
169
175
  };
170
176
  /** Gets the override constructor which can setup a neo model. */
171
177
  NeoTypeInfo.prototype.getOverrideConstructor = function () {
178
+ if (!this.wrapperConstructor) {
179
+ this.wrapperConstructor = this.createWrapperConstructor();
180
+ }
181
+ return this.wrapperConstructor;
182
+ };
183
+ NeoTypeInfo.prototype.createWrapperConstructor = function () {
172
184
  var _a;
173
185
  var self = this;
174
186
  var baseType = Object.getPrototypeOf(self.objectConstructor);
@@ -214,9 +226,22 @@ var NeoTypeInfo = /** @class */ (function () {
214
226
  newConstructor.prototype = self.objectConstructor.prototype;
215
227
  return newConstructor;
216
228
  };
217
- NeoTypeInfo.prototype.makeObservable = function (instance) {
218
- this.ensureStaticRuntimeInfo(instance);
219
- return this.modelCreator.convertInstance(instance);
229
+ NeoTypeInfo.prototype.makeObservable = function (instance, options) {
230
+ options = (options !== null && options !== void 0 ? options : {});
231
+ if (!options.skipConversion) {
232
+ this.ensureStaticRuntimeInfo(instance);
233
+ if (options.makeObservable === undefined) {
234
+ options.makeObservable = this.inheritsModelBase;
235
+ }
236
+ if (instance[hasConvertedSymbol]) {
237
+ throw Error("makeObservable() or makeBindable() has been called multiple times on type " + this.objectConstructor.name + ". Make sure this is only called on the last derived type.");
238
+ }
239
+ else {
240
+ instance[hasConvertedSymbol] = true;
241
+ }
242
+ return this.modelCreator.convertInstance(instance, options);
243
+ }
244
+ return instance;
220
245
  };
221
246
  NeoTypeInfo.prototype.defineProxyProperty = function (baseType, newConstructor, propertyKey) {
222
247
  Object.defineProperty(newConstructor, propertyKey, {
@@ -224,6 +249,22 @@ var NeoTypeInfo = /** @class */ (function () {
224
249
  set: function (value) { return baseType[propertyKey] = value; }
225
250
  });
226
251
  };
252
+ /**
253
+ * Makes a class instance observable.
254
+ * Must be called in the constructor, preferably directly after the super() call.
255
+ * This method can be used as an alternative to the @NeoModel decorator.
256
+ */
257
+ NeoTypeInfo.makeObservable = function (instance, options) {
258
+ var ctor = instance.constructor;
259
+ ensureTypeInfo(ctor);
260
+ ctor.neo.makeObservable(instance, options);
261
+ };
262
+ /** Ensures the type and its metadata are initialised. */
263
+ NeoTypeInfo.ensureInitialised = function (constructor) {
264
+ var typeInfo = ensureTypeInfo(constructor).neo;
265
+ typeInfo.ensureInitialised();
266
+ return typeInfo;
267
+ };
227
268
  return NeoTypeInfo;
228
269
  }());
229
270
  export { NeoTypeInfo };
@@ -1,4 +1,4 @@
1
- export { IBindableBase, IModelBase, NeoModelConstructor, PlainObject, PlainTrackedObject, PartialPlainObject, PartialPlainNonTrackedObject, TransformMetaType } from './IModelBase';
1
+ export { IBindableBase, IModelBase, NeoModelConstructor, PlainObject, PlainTrackedObject, PartialPlainObject, PartialPlainNonTrackedObject, TransformMetaType, IMakeBindableOptions } from './IModelBase';
2
2
  export { ILookupBase } from './LookupBase';
3
3
  export { IPropertyInstance, PropertyAccessor } from './PropertyInstance';
4
4
  export { IObservableValue, ObservableValue } from './ObservableValue';
@@ -1,5 +1,4 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
- import NeoModel from '../../Model/NeoModel';
3
2
  import { Observable, Computed } from '../../Model/Decorators';
4
3
  import PropertyInstance from '../../Model/PropertyInstance';
5
4
  import RuleValidator from './RuleValidator';
@@ -7,6 +6,7 @@ import { ContainerValidationState } from '../ValidationState';
7
6
  import PropertyValidator from './PropertyValidator';
8
7
  import PropertyInfo from '../../Model/PropertyInfo';
9
8
  import ValidationDisplayHelper from '../DisplayHelper';
9
+ import { NeoTypeInfo } from '../../Model/NeoTypeInfo';
10
10
  var ModelValidator = /** @class */ (function () {
11
11
  function ModelValidator(model, objectRules) {
12
12
  var _this = this;
@@ -25,6 +25,7 @@ var ModelValidator = /** @class */ (function () {
25
25
  _this.objectRules.push(new RuleValidator(tempPropertyInstance_1, rule));
26
26
  });
27
27
  }
28
+ NeoTypeInfo.makeObservable(this);
28
29
  }
29
30
  ModelValidator.prototype.addProperty = function (property) {
30
31
  this.ruleProperties.push(property);
@@ -128,10 +129,6 @@ var ModelValidator = /** @class */ (function () {
128
129
  __metadata("design:type", ContainerValidationState),
129
130
  __metadata("design:paramtypes", [])
130
131
  ], ModelValidator.prototype, "ruleState", null);
131
- ModelValidator = __decorate([
132
- NeoModel,
133
- __metadata("design:paramtypes", [Object, Array])
134
- ], ModelValidator);
135
132
  return ModelValidator;
136
133
  }());
137
134
  export default ModelValidator;
@@ -2,14 +2,15 @@ import { __decorate, __metadata } from "tslib";
2
2
  import { ContainerValidationState } from '../ValidationState';
3
3
  import { ValidationDisplayMode } from '../Misc';
4
4
  import { ValidationDisplayInfo } from '../DisplayHelper';
5
- import NeoModel from '../../Model/NeoModel';
6
5
  import { Observable, Computed } from '../../Model/Decorators';
6
+ import { NeoTypeInfo } from '../../Model/NeoTypeInfo';
7
7
  var PropertyValidator = /** @class */ (function () {
8
8
  function PropertyValidator(propertyInstance, ruleList) {
9
9
  this.propertyInstance = propertyInstance;
10
10
  this.ruleList = ruleList;
11
11
  /** True if an element bound to this property has lost focus. Used for displaying rules. */
12
12
  this.hasBlurred = false;
13
+ NeoTypeInfo.makeObservable(this);
13
14
  }
14
15
  Object.defineProperty(PropertyValidator.prototype, "ruleState", {
15
16
  get: function () {
@@ -58,10 +59,6 @@ var PropertyValidator = /** @class */ (function () {
58
59
  __metadata("design:type", ContainerValidationState),
59
60
  __metadata("design:paramtypes", [])
60
61
  ], PropertyValidator.prototype, "ruleState", null);
61
- PropertyValidator = __decorate([
62
- NeoModel,
63
- __metadata("design:paramtypes", [Object, Array])
64
- ], PropertyValidator);
65
62
  return PropertyValidator;
66
63
  }());
67
64
  export default PropertyValidator;
@@ -1,8 +1,7 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
- import { Rule } from '../Rules';
3
2
  import { RuleContext, AsyncStage } from '../RuleContext';
4
- import NeoModel from '../../Model/NeoModel';
5
3
  import { Observable, Computed } from '../../Model/Decorators';
4
+ import { NeoTypeInfo } from '../../Model/NeoTypeInfo';
6
5
  var RuleValidator = /** @class */ (function () {
7
6
  function RuleValidator(propertyInstance, rule) {
8
7
  this.propertyInstance = propertyInstance;
@@ -13,6 +12,7 @@ var RuleValidator = /** @class */ (function () {
13
12
  // Properties this rule has been added to, including the primary property.
14
13
  this.properties = [];
15
14
  this.refreshValue = 0;
15
+ NeoTypeInfo.makeObservable(this);
16
16
  }
17
17
  Object.defineProperty(RuleValidator.prototype, "ruleId", {
18
18
  get: function () {
@@ -46,10 +46,6 @@ var RuleValidator = /** @class */ (function () {
46
46
  __metadata("design:type", Object),
47
47
  __metadata("design:paramtypes", [])
48
48
  ], RuleValidator.prototype, "ruleContext", null);
49
- RuleValidator = __decorate([
50
- NeoModel,
51
- __metadata("design:paramtypes", [Object, Rule])
52
- ], RuleValidator);
53
49
  return RuleValidator;
54
50
  }());
55
51
  export default RuleValidator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularsystems/neo-core",
3
- "version": "0.10.61",
3
+ "version": "0.10.62",
4
4
  "description": "Core functionality for the Neo client library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",