breeze-client 2.2.1 → 3.0.0
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/LICENSE +1 -1
- package/README.md +83 -63
- package/adapters/abstract-data-service-adapter.d.ts +120 -0
- package/adapters/abstract-data-service-adapter.js +395 -0
- package/adapters/abstract-data-service-adapter.js.map +1 -0
- package/adapters/adapter-ajax-fetch.d.ts +12 -0
- package/adapters/adapter-ajax-fetch.js +13 -0
- package/adapters/adapter-ajax-fetch.js.map +1 -0
- package/{adapter-ajax-post → adapters}/adapter-ajax-post.d.ts +40 -36
- package/{fesm2022/breeze-client-adapter-ajax-post.mjs → adapters/adapter-ajax-post.js} +80 -82
- package/adapters/adapter-ajax-post.js.map +1 -0
- package/{adapter-ajax-fetch → adapters}/adapter-core.d.ts +4 -4
- package/{fesm2022/breeze-client-adapter-uri-builder-json.mjs → adapters/adapter-core.js} +48 -91
- package/adapters/adapter-core.js.map +1 -0
- package/adapters/adapter-data-service-webapi.d.ts +9 -0
- package/{fesm2022/breeze-client-adapter-data-service-webapi.mjs → adapters/adapter-data-service-webapi.js} +105 -107
- package/adapters/adapter-data-service-webapi.js.map +1 -0
- package/adapters/adapter-model-library-backing-store.d.ts +32 -0
- package/adapters/adapter-model-library-backing-store.js +321 -0
- package/adapters/adapter-model-library-backing-store.js.map +1 -0
- package/adapters/adapter-uri-builder-json.d.ts +11 -0
- package/adapters/adapter-uri-builder-json.js +40 -0
- package/adapters/adapter-uri-builder-json.js.map +1 -0
- package/adapters/http.d.ts +52 -0
- package/adapters/http.js +202 -0
- package/adapters/http.js.map +1 -0
- package/angular/adapter-angular-httpclient.d.ts +21 -0
- package/angular/adapter-angular-httpclient.js +70 -0
- package/angular/adapter-angular-httpclient.js.map +1 -0
- package/breeze.d.ts +215 -0
- package/breeze.js +141 -0
- package/breeze.js.map +1 -0
- package/config/config.d.ts +212 -0
- package/config/config.js +392 -0
- package/config/config.js.map +1 -0
- package/config/configure.d.ts +66 -0
- package/config/configure.js +46 -0
- package/config/configure.js.map +1 -0
- package/config/default-adapters.d.ts +1 -0
- package/config/default-adapters.js +40 -0
- package/config/default-adapters.js.map +1 -0
- package/config/interface-registry.d.ts +191 -0
- package/config/interface-registry.js +5 -0
- package/config/interface-registry.js.map +1 -0
- package/{src → core}/assert-param.d.ts +52 -60
- package/core/assert-param.js +390 -0
- package/core/assert-param.js.map +1 -0
- package/core/core.d.ts +285 -0
- package/core/core.js +772 -0
- package/core/core.js.map +1 -0
- package/core/enum.d.ts +116 -0
- package/core/enum.js +167 -0
- package/core/enum.js.map +1 -0
- package/core/event.d.ts +169 -0
- package/core/event.js +338 -0
- package/core/event.js.map +1 -0
- package/entity/array.d.ts +3 -0
- package/entity/array.js +4 -0
- package/entity/array.js.map +1 -0
- package/entity/complex-array.d.ts +17 -0
- package/entity/complex-array.js +104 -0
- package/entity/complex-array.js.map +1 -0
- package/entity/default-property-interceptor.d.ts +1 -0
- package/entity/default-property-interceptor.js +496 -0
- package/entity/default-property-interceptor.js.map +1 -0
- package/{src → entity}/entity-action.d.ts +36 -42
- package/entity/entity-action.js +45 -0
- package/entity/entity-action.js.map +1 -0
- package/entity/entity-aspect.d.ts +457 -0
- package/entity/entity-aspect.js +1262 -0
- package/entity/entity-aspect.js.map +1 -0
- package/entity/entity-base.d.ts +55 -0
- package/entity/entity-base.js +41 -0
- package/entity/entity-base.js.map +1 -0
- package/entity/entity-group.d.ts +1 -0
- package/entity/entity-group.js +224 -0
- package/entity/entity-group.js.map +1 -0
- package/entity/entity-key.d.ts +95 -0
- package/entity/entity-key.js +189 -0
- package/entity/entity-key.js.map +1 -0
- package/{src → entity}/entity-state.d.ts +112 -84
- package/entity/entity-state.js +135 -0
- package/entity/entity-state.js.map +1 -0
- package/entity/key-generator.d.ts +57 -0
- package/entity/key-generator.js +155 -0
- package/entity/key-generator.js.map +1 -0
- package/entity/observable-array.d.ts +25 -0
- package/entity/observable-array.js +230 -0
- package/entity/observable-array.js.map +1 -0
- package/entity/primitive-array.d.ts +12 -0
- package/entity/primitive-array.js +71 -0
- package/entity/primitive-array.js.map +1 -0
- package/entity/relation-array.d.ts +24 -0
- package/entity/relation-array.js +176 -0
- package/entity/relation-array.js.map +1 -0
- package/entity/unattached-children-map.d.ts +1 -0
- package/entity/unattached-children-map.js +105 -0
- package/entity/unattached-children-map.js.map +1 -0
- package/generate-entity-classes.js +1176 -0
- package/manager/entity-manager.d.ts +801 -0
- package/manager/entity-manager.js +2395 -0
- package/manager/entity-manager.js.map +1 -0
- package/{src → manager}/save-options.d.ts +48 -42
- package/manager/save-options.js +51 -0
- package/manager/save-options.js.map +1 -0
- package/{src → metadata}/data-service.d.ts +229 -184
- package/metadata/data-service.js +246 -0
- package/metadata/data-service.js.map +1 -0
- package/metadata/data-type.d.ts +122 -0
- package/metadata/data-type.js +465 -0
- package/metadata/data-type.js.map +1 -0
- package/metadata/entity-metadata.d.ts +1193 -0
- package/metadata/entity-metadata.js +2502 -0
- package/metadata/entity-metadata.js.map +1 -0
- package/{src → metadata}/local-query-comparison-options.d.ts +65 -59
- package/metadata/local-query-comparison-options.js +69 -0
- package/metadata/local-query-comparison-options.js.map +1 -0
- package/{src → metadata}/naming-convention.d.ts +75 -72
- package/metadata/naming-convention.js +97 -0
- package/metadata/naming-convention.js.map +1 -0
- package/mixins/mixin-get-entity-graph.d.ts +63 -0
- package/{fesm2022/breeze-client-mixin-get-entity-graph.mjs → mixins/mixin-get-entity-graph.js} +331 -253
- package/mixins/mixin-get-entity-graph.js.map +1 -0
- package/mixins/mixin-save-queuing.d.ts +98 -0
- package/{fesm2022/breeze-client-mixin-save-queuing.mjs → mixins/mixin-save-queuing.js} +493 -365
- package/mixins/mixin-save-queuing.js.map +1 -0
- package/package.json +62 -93
- package/query/entity-query.d.ts +521 -0
- package/query/entity-query.js +1149 -0
- package/query/entity-query.js.map +1 -0
- package/{src → query}/mapping-context.d.ts +44 -46
- package/query/mapping-context.js +412 -0
- package/query/mapping-context.js.map +1 -0
- package/query/predicate.d.ts +394 -0
- package/query/predicate.js +1294 -0
- package/query/predicate.js.map +1 -0
- package/query/property-path.d.ts +252 -0
- package/query/property-path.js +2 -0
- package/query/property-path.js.map +1 -0
- package/{src → query}/query-options.d.ts +143 -119
- package/query/query-options.js +180 -0
- package/query/query-options.js.map +1 -0
- package/rxjs/breeze-rxjs.d.ts +72 -0
- package/rxjs/breeze-rxjs.js +117 -0
- package/rxjs/breeze-rxjs.js.map +1 -0
- package/validation/validate.d.ts +583 -0
- package/validation/validate.js +961 -0
- package/validation/validate.js.map +1 -0
- package/{src → validation}/validation-options.d.ts +67 -63
- package/validation/validation-options.js +70 -0
- package/validation/validation-options.js.map +1 -0
- package/adapter-ajax-angularjs/adapter-ajax-angularjs.d.ts +0 -17
- package/adapter-ajax-angularjs/adapter-core.d.ts +0 -4
- package/adapter-ajax-angularjs/index.d.ts +0 -5
- package/adapter-ajax-fetch/adapter-ajax-fetch.d.ts +0 -18
- package/adapter-ajax-fetch/index.d.ts +0 -5
- package/adapter-ajax-httpclient/adapter-ajax-httpclient.d.ts +0 -13
- package/adapter-ajax-httpclient/adapter-core.d.ts +0 -4
- package/adapter-ajax-httpclient/index.d.ts +0 -5
- package/adapter-ajax-jquery/adapter-ajax-jquery.d.ts +0 -15
- package/adapter-ajax-jquery/index.d.ts +0 -5
- package/adapter-ajax-post/index.d.ts +0 -5
- package/adapter-data-service-odata/adapter-core.d.ts +0 -4
- package/adapter-data-service-odata/adapter-data-service-odata.d.ts +0 -17
- package/adapter-data-service-odata/index.d.ts +0 -5
- package/adapter-data-service-webapi/adapter-data-service-webapi.d.ts +0 -15
- package/adapter-data-service-webapi/index.d.ts +0 -5
- package/adapter-model-library-backing-store/adapter-model-library-backing-store.d.ts +0 -10
- package/adapter-model-library-backing-store/index.d.ts +0 -5
- package/adapter-model-library-ko/adapter-model-library-ko.d.ts +0 -10
- package/adapter-model-library-ko/index.d.ts +0 -5
- package/adapter-uri-builder-json/adapter-core.d.ts +0 -4
- package/adapter-uri-builder-json/adapter-uri-builder-json.d.ts +0 -8
- package/adapter-uri-builder-json/index.d.ts +0 -5
- package/adapter-uri-builder-odata/adapter-core.d.ts +0 -4
- package/adapter-uri-builder-odata/adapter-uri-builder-odata.d.ts +0 -8
- package/adapter-uri-builder-odata/index.d.ts +0 -5
- package/esm2022/adapter-ajax-angularjs/adapter-ajax-angularjs.mjs +0 -135
- package/esm2022/adapter-ajax-angularjs/adapter-core.mjs +0 -49
- package/esm2022/adapter-ajax-angularjs/breeze-client-adapter-ajax-angularjs.mjs +0 -5
- package/esm2022/adapter-ajax-fetch/adapter-ajax-fetch.mjs +0 -135
- package/esm2022/adapter-ajax-fetch/adapter-core.mjs +0 -49
- package/esm2022/adapter-ajax-fetch/breeze-client-adapter-ajax-fetch.mjs +0 -5
- package/esm2022/adapter-ajax-httpclient/adapter-ajax-httpclient.mjs +0 -139
- package/esm2022/adapter-ajax-httpclient/adapter-core.mjs +0 -49
- package/esm2022/adapter-ajax-httpclient/breeze-client-adapter-ajax-httpclient.mjs +0 -5
- package/esm2022/adapter-ajax-jquery/adapter-ajax-jquery.mjs +0 -107
- package/esm2022/adapter-ajax-jquery/breeze-client-adapter-ajax-jquery.mjs +0 -5
- package/esm2022/adapter-ajax-post/adapter-ajax-post.mjs +0 -77
- package/esm2022/adapter-ajax-post/breeze-client-adapter-ajax-post.mjs +0 -5
- package/esm2022/adapter-data-service-odata/adapter-core.mjs +0 -49
- package/esm2022/adapter-data-service-odata/adapter-data-service-odata.mjs +0 -461
- package/esm2022/adapter-data-service-odata/breeze-client-adapter-data-service-odata.mjs +0 -5
- package/esm2022/adapter-data-service-webapi/adapter-data-service-webapi.mjs +0 -100
- package/esm2022/adapter-data-service-webapi/breeze-client-adapter-data-service-webapi.mjs +0 -5
- package/esm2022/adapter-model-library-backing-store/adapter-model-library-backing-store.mjs +0 -269
- package/esm2022/adapter-model-library-backing-store/breeze-client-adapter-model-library-backing-store.mjs +0 -5
- package/esm2022/adapter-model-library-ko/adapter-model-library-ko.mjs +0 -241
- package/esm2022/adapter-model-library-ko/breeze-client-adapter-model-library-ko.mjs +0 -5
- package/esm2022/adapter-uri-builder-json/adapter-core.mjs +0 -49
- package/esm2022/adapter-uri-builder-json/adapter-uri-builder-json.mjs +0 -37
- package/esm2022/adapter-uri-builder-json/breeze-client-adapter-uri-builder-json.mjs +0 -5
- package/esm2022/adapter-uri-builder-odata/adapter-core.mjs +0 -49
- package/esm2022/adapter-uri-builder-odata/adapter-uri-builder-odata.mjs +0 -191
- package/esm2022/adapter-uri-builder-odata/breeze-client-adapter-uri-builder-odata.mjs +0 -5
- package/esm2022/breeze-client.mjs +0 -5
- package/esm2022/index.mjs +0 -2
- package/esm2022/mixin-get-entity-graph/breeze-client-mixin-get-entity-graph.mjs +0 -5
- package/esm2022/mixin-get-entity-graph/mixin-get-entity-graph.mjs +0 -269
- package/esm2022/mixin-save-queuing/breeze-client-mixin-save-queuing.mjs +0 -5
- package/esm2022/mixin-save-queuing/mixin-save-queuing.mjs +0 -421
- package/esm2022/src/abstract-data-service-adapter.mjs +0 -325
- package/esm2022/src/array.mjs +0 -4
- package/esm2022/src/assert-param.mjs +0 -330
- package/esm2022/src/breeze.mjs +0 -85
- package/esm2022/src/complex-array.mjs +0 -117
- package/esm2022/src/config.mjs +0 -232
- package/esm2022/src/core.mjs +0 -712
- package/esm2022/src/csdl-metadata-parser.mjs +0 -385
- package/esm2022/src/data-service.mjs +0 -221
- package/esm2022/src/data-type.mjs +0 -510
- package/esm2022/src/default-property-interceptor.mjs +0 -460
- package/esm2022/src/entity-action.mjs +0 -45
- package/esm2022/src/entity-aspect.mjs +0 -897
- package/esm2022/src/entity-group.mjs +0 -192
- package/esm2022/src/entity-key.mjs +0 -125
- package/esm2022/src/entity-manager.mjs +0 -2163
- package/esm2022/src/entity-metadata.mjs +0 -2242
- package/esm2022/src/entity-query.mjs +0 -1024
- package/esm2022/src/entity-state.mjs +0 -107
- package/esm2022/src/enum.mjs +0 -143
- package/esm2022/src/event.mjs +0 -264
- package/esm2022/src/interface-registry.mjs +0 -39
- package/esm2022/src/key-generator.mjs +0 -110
- package/esm2022/src/local-query-comparison-options.mjs +0 -65
- package/esm2022/src/mapping-context.mjs +0 -411
- package/esm2022/src/naming-convention.mjs +0 -92
- package/esm2022/src/observable-array.mjs +0 -183
- package/esm2022/src/predicate.mjs +0 -1259
- package/esm2022/src/primitive-array.mjs +0 -85
- package/esm2022/src/query-options.mjs +0 -152
- package/esm2022/src/relation-array.mjs +0 -173
- package/esm2022/src/save-options.mjs +0 -41
- package/esm2022/src/unattached-children-map.mjs +0 -56
- package/esm2022/src/validate.mjs +0 -995
- package/esm2022/src/validation-options.mjs +0 -64
- package/fesm2022/breeze-client-adapter-ajax-angularjs.mjs +0 -190
- package/fesm2022/breeze-client-adapter-ajax-angularjs.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-ajax-fetch.mjs +0 -190
- package/fesm2022/breeze-client-adapter-ajax-fetch.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-ajax-httpclient.mjs +0 -194
- package/fesm2022/breeze-client-adapter-ajax-httpclient.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-ajax-jquery.mjs +0 -114
- package/fesm2022/breeze-client-adapter-ajax-jquery.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-ajax-post.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-data-service-odata.mjs +0 -516
- package/fesm2022/breeze-client-adapter-data-service-odata.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-data-service-webapi.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-model-library-backing-store.mjs +0 -276
- package/fesm2022/breeze-client-adapter-model-library-backing-store.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-model-library-ko.mjs +0 -248
- package/fesm2022/breeze-client-adapter-model-library-ko.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-uri-builder-json.mjs.map +0 -1
- package/fesm2022/breeze-client-adapter-uri-builder-odata.mjs +0 -246
- package/fesm2022/breeze-client-adapter-uri-builder-odata.mjs.map +0 -1
- package/fesm2022/breeze-client-mixin-get-entity-graph.mjs.map +0 -1
- package/fesm2022/breeze-client-mixin-save-queuing.mjs.map +0 -1
- package/fesm2022/breeze-client.mjs +0 -14144
- package/fesm2022/breeze-client.mjs.map +0 -1
- package/index.d.ts +0 -1
- package/mixin-get-entity-graph/index.d.ts +0 -5
- package/mixin-get-entity-graph/mixin-get-entity-graph.d.ts +0 -31
- package/mixin-save-queuing/index.d.ts +0 -5
- package/mixin-save-queuing/mixin-save-queuing.d.ts +0 -32
- package/src/abstract-data-service-adapter.d.ts +0 -84
- package/src/array.d.ts +0 -3
- package/src/breeze.d.ts +0 -139
- package/src/complex-array.d.ts +0 -13
- package/src/config.d.ts +0 -104
- package/src/core.d.ts +0 -164
- package/src/csdl-metadata-parser.d.ts +0 -7
- package/src/data-type.d.ts +0 -89
- package/src/default-property-interceptor.d.ts +0 -4
- package/src/entity-aspect.d.ts +0 -332
- package/src/entity-group.d.ts +0 -28
- package/src/entity-key.d.ts +0 -77
- package/src/entity-manager.d.ts +0 -680
- package/src/entity-metadata.d.ts +0 -988
- package/src/entity-query.d.ts +0 -444
- package/src/enum.d.ts +0 -100
- package/src/event.d.ts +0 -142
- package/src/interface-registry.d.ts +0 -150
- package/src/key-generator.d.ts +0 -12
- package/src/observable-array.d.ts +0 -52
- package/src/predicate.d.ts +0 -376
- package/src/primitive-array.d.ts +0 -7
- package/src/relation-array.d.ts +0 -18
- package/src/unattached-children-map.d.ts +0 -19
- package/src/validate.d.ts +0 -650
package/core/event.js
ADDED
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { core } from './core.js';
|
|
2
|
+
import { assertParam, paramError } from './assert-param.js';
|
|
3
|
+
function publishCore(that, data, errorCallback) {
|
|
4
|
+
let subscribers = that._subscribers;
|
|
5
|
+
if (!subscribers)
|
|
6
|
+
return true;
|
|
7
|
+
// subscribers from outer scope.
|
|
8
|
+
subscribers.forEach(function (s) {
|
|
9
|
+
try {
|
|
10
|
+
s.callback(data);
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
e.context = "unable to publish on topic: " + that.name;
|
|
14
|
+
if (errorCallback) {
|
|
15
|
+
errorCallback(e);
|
|
16
|
+
}
|
|
17
|
+
else if (that._defaultErrorCallback) {
|
|
18
|
+
that._defaultErrorCallback(e);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
fallbackErrorHandler(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Where a subscriber's exception goes when neither the `publish` call nor the event itself
|
|
28
|
+
* supplies an error callback.
|
|
29
|
+
*
|
|
30
|
+
* It used to go nowhere at all. That is the worst thing it could do: a bug in a handler leaves no
|
|
31
|
+
* trace, and the symptom is an event that looks as though it was never published. Reporting it
|
|
32
|
+
* costs nothing on the path that matters, because it only runs when a subscriber has thrown.
|
|
33
|
+
*
|
|
34
|
+
* It is still not rethrown. Subscribers are independent, and one that fails must not stop the
|
|
35
|
+
* others from being notified.
|
|
36
|
+
*/
|
|
37
|
+
function fallbackErrorHandler(e) {
|
|
38
|
+
const handler = BreezeEvent.unhandledErrorCallback;
|
|
39
|
+
if (handler)
|
|
40
|
+
handler(e);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
Class to support basic event publication and subscription semantics.
|
|
44
|
+
*/
|
|
45
|
+
export class BreezeEvent {
|
|
46
|
+
/**
|
|
47
|
+
* Names of every event constructed so far. A Set: it is membership, not mapping.
|
|
48
|
+
* @hidden @internal
|
|
49
|
+
*/
|
|
50
|
+
static __eventNameMap = new Set();
|
|
51
|
+
/** @hidden @internal */
|
|
52
|
+
static __nextUnsubKey = 1;
|
|
53
|
+
/**
|
|
54
|
+
* Called with any exception a subscriber throws that nothing else has handled - that is, when
|
|
55
|
+
* neither `publish` nor the event was given an error callback.
|
|
56
|
+
*
|
|
57
|
+
* It logs to `console.error` by default. Set your own to route it into a logger, or `null` to
|
|
58
|
+
* go back to discarding these silently (which is what Breeze did before 3.0, and why handler
|
|
59
|
+
* bugs were so hard to find).
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* BreezeEvent.unhandledErrorCallback = e => myLogger.error(e);
|
|
63
|
+
* BreezeEvent.unhandledErrorCallback = null; // say nothing
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
static unhandledErrorCallback = (e) => {
|
|
67
|
+
// `context` is set by publishCore and names the event.
|
|
68
|
+
const where = e.context || 'an event subscriber';
|
|
69
|
+
console.error(`breeze: ${where} threw and nothing handled it.`, e);
|
|
70
|
+
};
|
|
71
|
+
/** The name of this Event */
|
|
72
|
+
name;
|
|
73
|
+
/** The object doing the publication. i.e. the object to which this event is attached. */
|
|
74
|
+
publisher;
|
|
75
|
+
/**
|
|
76
|
+
* Whether anything is listening. Lets a caller skip building event arguments it would only
|
|
77
|
+
* throw away - `publish` on an unsubscribed event still walks the `_getEventParent` chain via
|
|
78
|
+
* `_isEnabled` before discovering there is nobody to tell.
|
|
79
|
+
* @hidden @internal
|
|
80
|
+
*/
|
|
81
|
+
get hasSubscribers() {
|
|
82
|
+
const subs = this._subscribers;
|
|
83
|
+
return subs != null && subs.length > 0;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
Constructor for an Event
|
|
87
|
+
```ts
|
|
88
|
+
salaryEvent = new BreezeEvent("salaryEvent", person);
|
|
89
|
+
```
|
|
90
|
+
@param name - The name of the event.
|
|
91
|
+
@param publisher - The object that will be doing the publication. i.e. the object to which this event is attached.
|
|
92
|
+
@param defaultErrorCallback - Function to call when an error occurs during subscription execution.
|
|
93
|
+
If omitted then subscriber notification failures will be ignored.
|
|
94
|
+
*/
|
|
95
|
+
constructor(name, publisher, defaultErrorCallback) {
|
|
96
|
+
// Checked inline rather than with assertParam: every entity constructs two of these,
|
|
97
|
+
// and the chain allocates several objects to answer what is one typeof. Same wording.
|
|
98
|
+
if (typeof name !== 'string' || name.length === 0) {
|
|
99
|
+
throw paramError('eventName', "must be a nonEmpty string");
|
|
100
|
+
}
|
|
101
|
+
if (publisher == null || typeof publisher !== 'object') {
|
|
102
|
+
throw paramError('publisher', "must be a 'object'");
|
|
103
|
+
}
|
|
104
|
+
this.name = name;
|
|
105
|
+
// register the name
|
|
106
|
+
BreezeEvent.__eventNameMap.add(name);
|
|
107
|
+
this.publisher = publisher;
|
|
108
|
+
if (defaultErrorCallback) {
|
|
109
|
+
this._defaultErrorCallback = defaultErrorCallback;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
Publish data for this event.
|
|
114
|
+
```ts
|
|
115
|
+
// Assume 'salaryEvent' is previously constructed Event
|
|
116
|
+
salaryEvent.publish( { eventType: "payRaise", amount: 100 });
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
This event can also be published asychronously
|
|
120
|
+
```ts
|
|
121
|
+
salaryEvent.publish( { eventType: "payRaise", amount: 100 }, true);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
And we can add a handler in case the subscriber 'mishandles' the event.
|
|
125
|
+
```ts
|
|
126
|
+
salaryEvent.publish( { eventType: "payRaise", amount: 100 }, true, function(error) {
|
|
127
|
+
// do something with the 'error' object
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
@param data - Data to publish
|
|
131
|
+
@param publishAsync - (default=false) Whether to publish asynchonously or not.
|
|
132
|
+
@param errorCallback - Function to be called for any errors that occur during publication. If omitted,
|
|
133
|
+
errors will be eaten.
|
|
134
|
+
@returns false if event is disabled; true otherwise.
|
|
135
|
+
*/
|
|
136
|
+
publish(data, publishAsync = false, errorCallback) {
|
|
137
|
+
if (!BreezeEvent._isEnabled(this.name, this.publisher))
|
|
138
|
+
return false;
|
|
139
|
+
if (publishAsync === true) {
|
|
140
|
+
setTimeout(publishCore, 0, this, data, errorCallback);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
publishCore(this, data, errorCallback);
|
|
144
|
+
}
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
Publish data for this event asynchronously.
|
|
149
|
+
```ts
|
|
150
|
+
// Assume 'salaryEvent' is previously constructed Event
|
|
151
|
+
salaryEvent.publishAsync( { eventType: "payRaise", amount: 100 });
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
And we can add a handler in case the subscriber 'mishandles' the event.
|
|
155
|
+
```ts
|
|
156
|
+
salaryEvent.publishAsync( { eventType: "payRaise", amount: 100 }, function(error) {
|
|
157
|
+
// do something with the 'error' object
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
@param data - Data to publish
|
|
161
|
+
@param errorCallback - Function to be called for any errors that occur during publication. If omitted,
|
|
162
|
+
errors will be eaten.
|
|
163
|
+
*/
|
|
164
|
+
publishAsync(data, errorCallback) {
|
|
165
|
+
this.publish(data, true, errorCallback);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
Subscribe to this event.
|
|
169
|
+
```ts
|
|
170
|
+
// Assume 'salaryEvent' is previously constructed Event
|
|
171
|
+
salaryEvent.subscribe(function (eventArgs) {
|
|
172
|
+
if (eventArgs.eventType === "payRaise") {
|
|
173
|
+
// do something
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
There are several built in Breeze events, such as {@link EntityAspect.propertyChanged}, {@link EntityAspect.validationErrorsChanged} as well.
|
|
179
|
+
```ts
|
|
180
|
+
// Assume order is a preexisting 'order' entity
|
|
181
|
+
order.entityAspect.propertyChanged.subscribe(function (pcEvent) {
|
|
182
|
+
if ( pcEvent.propertyName === "OrderDate") {
|
|
183
|
+
// do something
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
```
|
|
187
|
+
@param callback - Called whenever data is published for this event, with that data as its argument. What is published is documented on each specific event.
|
|
188
|
+
@returns This is a key for 'unsubscription'. It can be passed to the 'unsubscribe' method.
|
|
189
|
+
*/
|
|
190
|
+
subscribe(callback) {
|
|
191
|
+
if (!this._subscribers) {
|
|
192
|
+
this._subscribers = [];
|
|
193
|
+
}
|
|
194
|
+
let unsubKey = BreezeEvent.__nextUnsubKey;
|
|
195
|
+
this._subscribers.push({ unsubKey: unsubKey, callback: callback });
|
|
196
|
+
++BreezeEvent.__nextUnsubKey;
|
|
197
|
+
return unsubKey;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
Unsubscribe from this event.
|
|
201
|
+
```ts
|
|
202
|
+
// Assume order is a preexisting 'order' entity
|
|
203
|
+
let token = order.entityAspect.propertyChanged.subscribe(function (pcEvent) {
|
|
204
|
+
// do something
|
|
205
|
+
});
|
|
206
|
+
// sometime later
|
|
207
|
+
order.entityAspect.propertyChanged.unsubscribe(token);
|
|
208
|
+
```
|
|
209
|
+
@param unsubKey - The value returned from the 'subscribe' method may be used to unsubscribe here.
|
|
210
|
+
@returns Whether unsubscription occured. This will return false if already unsubscribed or if the key simply
|
|
211
|
+
cannot be found.
|
|
212
|
+
*/
|
|
213
|
+
// A method, not a field holding a function: written as a field, every event carried its own
|
|
214
|
+
// copy of it rather than sharing one on the prototype.
|
|
215
|
+
unsubscribe(unsubKey) {
|
|
216
|
+
if (!this._subscribers)
|
|
217
|
+
return false;
|
|
218
|
+
let subs = this._subscribers;
|
|
219
|
+
let ix = core.arrayIndexOf(subs, function (s) {
|
|
220
|
+
return s.unsubKey === unsubKey;
|
|
221
|
+
});
|
|
222
|
+
if (ix !== -1) {
|
|
223
|
+
subs.splice(ix, 1);
|
|
224
|
+
if (subs.length === 0) {
|
|
225
|
+
this._subscribers = null;
|
|
226
|
+
}
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/** remove all subscribers */
|
|
234
|
+
clear() {
|
|
235
|
+
this._subscribers = null;
|
|
236
|
+
}
|
|
237
|
+
/** event bubbling - document later. */
|
|
238
|
+
// null or undefined 'getParentFn' means Event does not need to bubble i.e. that it is always enabled - .
|
|
239
|
+
static bubbleEvent(target, getParentFn) {
|
|
240
|
+
target._getEventParent = getParentFn || null;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
Enables or disables the named event for an object and all of its children.
|
|
244
|
+
```ts
|
|
245
|
+
BreezeEvent.enable(“propertyChanged”, myEntityManager, false)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
will disable all EntityAspect.propertyChanged events within a EntityManager.
|
|
249
|
+
```ts
|
|
250
|
+
BreezeEvent.enable(“propertyChanged”, myEntityManager, true)
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
will enable all EntityAspect.propertyChanged events within a EntityManager.
|
|
254
|
+
```ts
|
|
255
|
+
BreezeEvent.enable(“propertyChanged”, myEntity.entityAspect, false)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
will disable EntityAspect.propertyChanged events for a specific entity.
|
|
259
|
+
```ts
|
|
260
|
+
BreezeEvent.enable(“propertyChanged”, myEntity.entityAspect, null)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
will removes any enabling / disabling at the entity aspect level so now any 'Event.enable' calls at the EntityManager level,
|
|
264
|
+
made either previously or in the future, will control notification.
|
|
265
|
+
```ts
|
|
266
|
+
BreezeEvent.enable(“validationErrorsChanged”, myEntityManager, function(em) {
|
|
267
|
+
return em.customTag === “blue”;
|
|
268
|
+
})
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
will either enable or disable myEntityManager based on the current value of a ‘customTag’ property on myEntityManager.
|
|
273
|
+
Note that this is dynamic, changing the customTag value will cause events to be enabled or disabled immediately.
|
|
274
|
+
@param eventName - The name of the event.
|
|
275
|
+
@param obj - The object at which enabling or disabling will occur. All event notifications that occur to this object or
|
|
276
|
+
children of this object will be enabled or disabled.
|
|
277
|
+
@param isEnabled - A boolean, a null or a function that returns either a boolean or a null.
|
|
278
|
+
*/
|
|
279
|
+
static enable(eventName, obj, isEnabled) {
|
|
280
|
+
assertParam(eventName, "eventName").isNonEmptyString().check();
|
|
281
|
+
assertParam(obj, "obj").isObject().check();
|
|
282
|
+
assertParam(isEnabled, "isEnabled").isBoolean().isOptional().or().isFunction().check();
|
|
283
|
+
let ob = obj;
|
|
284
|
+
if (!ob._$eventMap) {
|
|
285
|
+
ob._$eventMap = {};
|
|
286
|
+
}
|
|
287
|
+
ob._$eventMap[eventName] = isEnabled;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
Returns whether for a specific event and a specific object and its children, notification is enabled or disabled or not set.
|
|
291
|
+
```ts
|
|
292
|
+
BreezeEvent.isEnabled(“propertyChanged”, myEntityManager)
|
|
293
|
+
|
|
294
|
+
```
|
|
295
|
+
@param eventName - The name of the event.
|
|
296
|
+
@param obj - The object for which we want to know if notifications are enabled.
|
|
297
|
+
@returns Whether notifications are enabled. If nothing is set on the object, the answer comes from its parent chain, and defaults to true.
|
|
298
|
+
*/
|
|
299
|
+
static isEnabled(eventName, obj) {
|
|
300
|
+
assertParam(eventName, "eventName").isNonEmptyString().check();
|
|
301
|
+
assertParam(obj, "obj").isObject().check();
|
|
302
|
+
// null is ok - it just means that the object is at the top level.
|
|
303
|
+
if (obj._getEventParent === undefined) {
|
|
304
|
+
throw new Error("This object does not support event enabling/disabling");
|
|
305
|
+
}
|
|
306
|
+
return BreezeEvent._isEnabled(eventName, obj);
|
|
307
|
+
}
|
|
308
|
+
/** @hidden @internal */
|
|
309
|
+
static _isEnabled = function (eventName, obj) {
|
|
310
|
+
let isEnabled = null;
|
|
311
|
+
let ob = obj;
|
|
312
|
+
let eventMap = ob._$eventMap;
|
|
313
|
+
if (eventMap) {
|
|
314
|
+
isEnabled = eventMap[eventName];
|
|
315
|
+
}
|
|
316
|
+
if (isEnabled != null) {
|
|
317
|
+
if (typeof isEnabled === 'function') {
|
|
318
|
+
return !!isEnabled(obj);
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
return !!isEnabled;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
let parent = ob._getEventParent && ob._getEventParent();
|
|
326
|
+
if (parent) {
|
|
327
|
+
return !!this._isEnabled(eventName, parent);
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
// default if not explicitly disabled.
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
// legacy support - deliberately not typed
|
|
337
|
+
core.Event = BreezeEvent;
|
|
338
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/core/event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE5D,SAAS,WAAW,CAAI,IAAoB,EAAE,IAAO,EAAE,aAAiC;IACtF,IAAI,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;IACpC,IAAI,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IAC9B,gCAAgC;IAChC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC;QAC7B,IAAI,CAAC;YACH,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,CAAC,CAAC,OAAO,GAAG,8BAA8B,GAAG,IAAI,CAAC,IAAI,CAAC;YACvD,IAAI,aAAa,EAAE,CAAC;gBAClB,aAAa,CAAC,CAAC,CAAC,CAAC;YACnB,CAAC;iBAAM,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;gBACtC,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,oBAAoB,CAAC,CAAC,CAAC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C,GAAG,CAAC,CAAC;YAC1B,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,CAAC,SAAS,CAAC;YACrB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,IAAI,MAAM,GAAG,EAAE,CAAC,eAAe,IAAI,EAAE,CAAC,eAAe,EAAE,CAAC;YACxD,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC9C,CAAC;iBAAM,CAAC;gBACN,sCAAsC;gBACtC,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;IACH,CAAC,CAAC;;AAKJ,0CAA0C;AACzC,IAAY,CAAC,KAAK,GAAG,WAAW,CAAC","sourcesContent":["import { core } from './core.js';\r\nimport { assertParam, paramError } from './assert-param.js';\r\n\r\nfunction publishCore<T>(that: BreezeEvent<T>, data: T, errorCallback?: (e: Error) => any) {\r\n let subscribers = that._subscribers;\r\n if (!subscribers) return true;\r\n // subscribers from outer scope.\r\n subscribers.forEach(function (s) {\r\n try {\r\n s.callback(data);\r\n } catch (e) {\r\n e.context = \"unable to publish on topic: \" + that.name;\r\n if (errorCallback) {\r\n errorCallback(e);\r\n } else if (that._defaultErrorCallback) {\r\n that._defaultErrorCallback(e);\r\n } else {\r\n fallbackErrorHandler(e);\r\n }\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Where a subscriber's exception goes when neither the `publish` call nor the event itself\r\n * supplies an error callback.\r\n *\r\n * It used to go nowhere at all. That is the worst thing it could do: a bug in a handler leaves no\r\n * trace, and the symptom is an event that looks as though it was never published. Reporting it\r\n * costs nothing on the path that matters, because it only runs when a subscriber has thrown.\r\n *\r\n * It is still not rethrown. Subscribers are independent, and one that fails must not stop the\r\n * others from being notified.\r\n */\r\nfunction fallbackErrorHandler(e: Error) {\r\n const handler = BreezeEvent.unhandledErrorCallback;\r\n if (handler) handler(e);\r\n}\r\n\r\n\r\n/** @hidden @internal */\r\nexport interface Subscription {\r\n unsubKey: number;\r\n callback: (data: any) => any;\r\n}\r\n\r\n/**\r\nClass to support basic event publication and subscription semantics.\r\n*/\r\nexport class BreezeEvent<T> {\r\n /**\r\n * Names of every event constructed so far. A Set: it is membership, not mapping.\r\n * @hidden @internal\r\n */\r\n static __eventNameMap = new Set<string>();\r\n /** @hidden @internal */\r\n static __nextUnsubKey = 1;\r\n\r\n /**\r\n * Called with any exception a subscriber throws that nothing else has handled - that is, when\r\n * neither `publish` nor the event was given an error callback.\r\n *\r\n * It logs to `console.error` by default. Set your own to route it into a logger, or `null` to\r\n * go back to discarding these silently (which is what Breeze did before 3.0, and why handler\r\n * bugs were so hard to find).\r\n *\r\n * ```ts\r\n * BreezeEvent.unhandledErrorCallback = e => myLogger.error(e);\r\n * BreezeEvent.unhandledErrorCallback = null; // say nothing\r\n * ```\r\n */\r\n static unhandledErrorCallback: ((e: Error) => void) | null = (e: Error) => {\r\n // `context` is set by publishCore and names the event.\r\n const where = (e as any).context || 'an event subscriber';\r\n console.error(`breeze: ${where} threw and nothing handled it.`, e);\r\n };\r\n /** The name of this Event */\r\n name: string;\r\n /** The object doing the publication. i.e. the object to which this event is attached. */\r\n publisher: Object;\r\n\r\n // `declare`, so that neither becomes an own property set to undefined on every instance. An\r\n // event is constructed twice for every entity in the cache and most are never subscribed to,\r\n // so the slots would be pure weight. Both are read defensively below.\r\n /** @hidden @internal */\r\n declare _subscribers: Subscription[];\r\n /** @hidden @internal */\r\n declare _defaultErrorCallback: (e: Error) => any;\r\n\r\n /**\r\n * Whether anything is listening. Lets a caller skip building event arguments it would only\r\n * throw away - `publish` on an unsubscribed event still walks the `_getEventParent` chain via\r\n * `_isEnabled` before discovering there is nobody to tell.\r\n * @hidden @internal\r\n */\r\n get hasSubscribers(): boolean {\r\n const subs = this._subscribers;\r\n return subs != null && subs.length > 0;\r\n }\r\n\r\n\r\n /**\r\n Constructor for an Event\r\n ```ts\r\n salaryEvent = new BreezeEvent(\"salaryEvent\", person);\r\n ```\r\n @param name - The name of the event.\r\n @param publisher - The object that will be doing the publication. i.e. the object to which this event is attached.\r\n @param defaultErrorCallback - Function to call when an error occurs during subscription execution. \r\n If omitted then subscriber notification failures will be ignored.\r\n */\r\n constructor(name: string, publisher: Object, defaultErrorCallback?: (e: Error) => any) {\r\n // Checked inline rather than with assertParam: every entity constructs two of these,\r\n // and the chain allocates several objects to answer what is one typeof. Same wording.\r\n if (typeof name !== 'string' || name.length === 0) {\r\n throw paramError('eventName', \"must be a nonEmpty string\");\r\n }\r\n if (publisher == null || typeof publisher !== 'object') {\r\n throw paramError('publisher', \"must be a 'object'\");\r\n }\r\n\r\n this.name = name;\r\n // register the name\r\n BreezeEvent.__eventNameMap.add(name);\r\n this.publisher = publisher;\r\n if (defaultErrorCallback) {\r\n this._defaultErrorCallback = defaultErrorCallback;\r\n }\r\n }\r\n\r\n /**\r\n Publish data for this event.\r\n ```ts\r\n // Assume 'salaryEvent' is previously constructed Event\r\n salaryEvent.publish( { eventType: \"payRaise\", amount: 100 });\r\n ```\r\n\r\n This event can also be published asychronously\r\n ```ts\r\n salaryEvent.publish( { eventType: \"payRaise\", amount: 100 }, true);\r\n ```\r\n\r\n And we can add a handler in case the subscriber 'mishandles' the event.\r\n ```ts\r\n salaryEvent.publish( { eventType: \"payRaise\", amount: 100 }, true, function(error) {\r\n // do something with the 'error' object\r\n });\r\n ```\r\n @param data - Data to publish\r\n @param publishAsync - (default=false) Whether to publish asynchonously or not.\r\n @param errorCallback - Function to be called for any errors that occur during publication. If omitted,\r\n errors will be eaten.\r\n @returns false if event is disabled; true otherwise.\r\n */\r\n publish(data: T, publishAsync: boolean = false, errorCallback?: (e: Error) => any) {\r\n\r\n if (!BreezeEvent._isEnabled(this.name, this.publisher)) return false;\r\n\r\n if (publishAsync === true) {\r\n setTimeout(publishCore, 0, this, data, errorCallback);\r\n } else {\r\n publishCore(this, data, errorCallback);\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n Publish data for this event asynchronously.\r\n ```ts\r\n // Assume 'salaryEvent' is previously constructed Event\r\n salaryEvent.publishAsync( { eventType: \"payRaise\", amount: 100 });\r\n ```\r\n\r\n And we can add a handler in case the subscriber 'mishandles' the event.\r\n ```ts\r\n salaryEvent.publishAsync( { eventType: \"payRaise\", amount: 100 }, function(error) {\r\n // do something with the 'error' object\r\n });\r\n ```\r\n @param data - Data to publish\r\n @param errorCallback - Function to be called for any errors that occur during publication. If omitted,\r\n errors will be eaten.\r\n */\r\n publishAsync(data: T, errorCallback: (e: Error) => any) {\r\n this.publish(data, true, errorCallback);\r\n }\r\n\r\n /**\r\n Subscribe to this event.\r\n ```ts\r\n // Assume 'salaryEvent' is previously constructed Event\r\n salaryEvent.subscribe(function (eventArgs) {\r\n if (eventArgs.eventType === \"payRaise\") {\r\n // do something\r\n }\r\n });\r\n ```\r\n\r\n There are several built in Breeze events, such as {@link EntityAspect.propertyChanged}, {@link EntityAspect.validationErrorsChanged} as well.\r\n ```ts\r\n // Assume order is a preexisting 'order' entity\r\n order.entityAspect.propertyChanged.subscribe(function (pcEvent) {\r\n if ( pcEvent.propertyName === \"OrderDate\") {\r\n // do something\r\n }\r\n });\r\n ```\r\n @param callback - Called whenever data is published for this event, with that data as its argument. What is published is documented on each specific event.\r\n @returns This is a key for 'unsubscription'. It can be passed to the 'unsubscribe' method.\r\n */\r\n subscribe(callback: (data: T) => any) {\r\n if (!this._subscribers) {\r\n this._subscribers = [];\r\n }\r\n\r\n let unsubKey = BreezeEvent.__nextUnsubKey;\r\n this._subscribers.push({ unsubKey: unsubKey, callback: callback });\r\n ++BreezeEvent.__nextUnsubKey;\r\n return unsubKey;\r\n }\r\n\r\n /**\r\n Unsubscribe from this event.\r\n ```ts\r\n // Assume order is a preexisting 'order' entity\r\n let token = order.entityAspect.propertyChanged.subscribe(function (pcEvent) {\r\n // do something\r\n });\r\n // sometime later\r\n order.entityAspect.propertyChanged.unsubscribe(token);\r\n ```\r\n @param unsubKey - The value returned from the 'subscribe' method may be used to unsubscribe here.\r\n @returns Whether unsubscription occured. This will return false if already unsubscribed or if the key simply\r\n cannot be found.\r\n */\r\n // A method, not a field holding a function: written as a field, every event carried its own\r\n // copy of it rather than sharing one on the prototype.\r\n unsubscribe(unsubKey: number) {\r\n if (!this._subscribers) return false;\r\n let subs = this._subscribers;\r\n let ix = core.arrayIndexOf(subs, function (s) {\r\n return s.unsubKey === unsubKey;\r\n });\r\n if (ix !== -1) {\r\n subs.splice(ix, 1);\r\n if (subs.length === 0) {\r\n this._subscribers = <any>null;\r\n }\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n /** remove all subscribers */\r\n clear() {\r\n this._subscribers = <any>null;\r\n }\r\n\r\n /** event bubbling - document later. */\r\n\r\n // null or undefined 'getParentFn' means Event does not need to bubble i.e. that it is always enabled - .\r\n static bubbleEvent(target: any, getParentFn?: (() => any)) {\r\n target._getEventParent = getParentFn || null;\r\n }\r\n\r\n /**\r\n Enables or disables the named event for an object and all of its children.\r\n ```ts\r\n BreezeEvent.enable(“propertyChanged”, myEntityManager, false)\r\n ```\r\n\r\n will disable all EntityAspect.propertyChanged events within a EntityManager.\r\n ```ts\r\n BreezeEvent.enable(“propertyChanged”, myEntityManager, true)\r\n ```\r\n\r\n will enable all EntityAspect.propertyChanged events within a EntityManager.\r\n ```ts\r\n BreezeEvent.enable(“propertyChanged”, myEntity.entityAspect, false)\r\n ```\r\n\r\n will disable EntityAspect.propertyChanged events for a specific entity.\r\n ```ts\r\n BreezeEvent.enable(“propertyChanged”, myEntity.entityAspect, null)\r\n ```\r\n\r\n will removes any enabling / disabling at the entity aspect level so now any 'Event.enable' calls at the EntityManager level,\r\n made either previously or in the future, will control notification.\r\n ```ts\r\n BreezeEvent.enable(“validationErrorsChanged”, myEntityManager, function(em) {\r\n return em.customTag === “blue”;\r\n })\r\n ```\r\n\r\n\r\n will either enable or disable myEntityManager based on the current value of a ‘customTag’ property on myEntityManager.\r\n Note that this is dynamic, changing the customTag value will cause events to be enabled or disabled immediately.\r\n @param eventName - The name of the event.\r\n @param obj - The object at which enabling or disabling will occur. All event notifications that occur to this object or\r\n children of this object will be enabled or disabled.\r\n @param isEnabled - A boolean, a null or a function that returns either a boolean or a null.\r\n */\r\n static enable(eventName: string, obj: Object, isEnabled: boolean | ((x: any) => boolean)) {\r\n assertParam(eventName, \"eventName\").isNonEmptyString().check();\r\n assertParam(obj, \"obj\").isObject().check();\r\n assertParam(isEnabled, \"isEnabled\").isBoolean().isOptional().or().isFunction().check();\r\n let ob = <any>obj;\r\n if (!ob._$eventMap) {\r\n ob._$eventMap = {};\r\n }\r\n ob._$eventMap[eventName] = isEnabled;\r\n }\r\n\r\n /**\r\n Returns whether for a specific event and a specific object and its children, notification is enabled or disabled or not set.\r\n ```ts\r\n BreezeEvent.isEnabled(“propertyChanged”, myEntityManager)\r\n\r\n ```\r\n @param eventName - The name of the event.\r\n @param obj - The object for which we want to know if notifications are enabled.\r\n @returns Whether notifications are enabled. If nothing is set on the object, the answer comes from its parent chain, and defaults to true.\r\n */\r\n static isEnabled(eventName: string, obj: Object) {\r\n assertParam(eventName, \"eventName\").isNonEmptyString().check();\r\n assertParam(obj, \"obj\").isObject().check();\r\n // null is ok - it just means that the object is at the top level.\r\n if ((<any>obj)._getEventParent === undefined) {\r\n throw new Error(\"This object does not support event enabling/disabling\");\r\n }\r\n return BreezeEvent._isEnabled(eventName, obj);\r\n }\r\n\r\n /** @hidden @internal */\r\n static _isEnabled = function (eventName: string, obj: Object) {\r\n let isEnabled: any = null;\r\n let ob = <any>obj;\r\n let eventMap = ob._$eventMap;\r\n if (eventMap) {\r\n isEnabled = eventMap[eventName];\r\n }\r\n if (isEnabled != null) {\r\n if (typeof isEnabled === 'function') {\r\n return !!isEnabled(obj);\r\n } else {\r\n return !!isEnabled;\r\n }\r\n } else {\r\n let parent = ob._getEventParent && ob._getEventParent();\r\n if (parent) {\r\n return !!this._isEnabled(eventName, parent);\r\n } else {\r\n // default if not explicitly disabled.\r\n return true;\r\n }\r\n }\r\n };\r\n\r\n\r\n}\r\n\r\n// legacy support - deliberately not typed\r\n(core as any).Event = BreezeEvent;"]}
|
package/entity/array.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../src/entity/array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC","sourcesContent":["export { makeRelationArray } from './relation-array.js';\r\nexport { makeComplexArray } from './complex-array.js';\r\nexport { makePrimitiveArray } from './primitive-array.js';\r\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ObservableArray } from './observable-array.js';
|
|
2
|
+
import type { ComplexObject, StructuralObject } from './entity-aspect.js';
|
|
3
|
+
import type { DataProperty } from '../metadata/entity-metadata.js';
|
|
4
|
+
/** The value of a complex property that holds an array of complex objects. It is a real array:
|
|
5
|
+
adding or removing an element marks the owning entity Modified, can be undone by `rejectChanges`,
|
|
6
|
+
and raises the array's `arrayChanged` event with an {@link ArrayChangedArgs}. */
|
|
7
|
+
export interface ComplexArray<T extends ComplexObject = ComplexObject> extends ObservableArray<T> {
|
|
8
|
+
/** The entity or complex object that owns this array. */
|
|
9
|
+
parent?: StructuralObject;
|
|
10
|
+
/** The complex {@link DataProperty} of `parent` that holds this array. */
|
|
11
|
+
parentProperty?: DataProperty;
|
|
12
|
+
}
|
|
13
|
+
/** For use by breeze plugin authors only. The class is for use in building a {@link ModelLibraryAdapter} implementation.
|
|
14
|
+
@adapter (see {@link ModelLibraryAdapter})
|
|
15
|
+
@hidden
|
|
16
|
+
*/
|
|
17
|
+
export declare function makeComplexArray(arr: any[], parent: StructuralObject, parentProperty: DataProperty): ComplexArray;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { BreezeEvent } from '../core/event.js';
|
|
2
|
+
import { observableArray } from './observable-array.js';
|
|
3
|
+
/*
|
|
4
|
+
Complex arrays are not a class: they are real arrays whose mutating methods are replaced, so that
|
|
5
|
+
changing one updates the entity that owns it. A complex array is a collection of complexTypes
|
|
6
|
+
associated with a data property on a single entity or other complex object, i.e. customer.orders
|
|
7
|
+
or order.orderDetails.
|
|
8
|
+
@class {complexArray}
|
|
9
|
+
*/
|
|
10
|
+
/*
|
|
11
|
+
An {@link BreezeEvent} that fires whenever the contents of this array changed. This event
|
|
12
|
+
is fired any time a new entity is attached or added to the EntityManager and happens to belong to this collection.
|
|
13
|
+
Adds that occur as a result of query or import operations are batched so that all of the adds or removes to any individual
|
|
14
|
+
collections are collected into a single notification event for each relation array.
|
|
15
|
+
@example
|
|
16
|
+
// assume order is an order entity attached to an EntityManager.
|
|
17
|
+
orders.arrayChanged.subscribe(
|
|
18
|
+
function (arrayChangedArgs) {
|
|
19
|
+
var addedEntities = arrayChangedArgs.added;
|
|
20
|
+
var removedEntities = arrayChanged.removed;
|
|
21
|
+
});
|
|
22
|
+
@event arrayChanged
|
|
23
|
+
@param added {Array of Entity} An array of all of the entities added to this collection.
|
|
24
|
+
@param removed {Array of Entity} An array of all of the removed from this collection.
|
|
25
|
+
@readOnly
|
|
26
|
+
*/
|
|
27
|
+
const complexArrayOps = {
|
|
28
|
+
// skip any that are already attached to this same parent
|
|
29
|
+
getGoodAdds: function (arr, adds) {
|
|
30
|
+
return adds.filter(function (a) {
|
|
31
|
+
return a.complexAspect == null || a.complexAspect.parent !== arr.parent;
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
beforeChange: function (arr) {
|
|
35
|
+
observableArray.updateEntityState(arr);
|
|
36
|
+
},
|
|
37
|
+
processAdds: function (arr, adds) {
|
|
38
|
+
adds.forEach(function (a) {
|
|
39
|
+
if (a.complexAspect && a.complexAspect.parent != null) {
|
|
40
|
+
throw new Error("The complexObject is already attached. Either clone it or remove it from its current owner");
|
|
41
|
+
}
|
|
42
|
+
setAspect(a, arr);
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
processRemoves: function (arr, removes) {
|
|
46
|
+
removes.forEach(function (a) {
|
|
47
|
+
clearAspect(a, arr);
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
getEventParent: function (arr) {
|
|
51
|
+
return observableArray.getEntityAspect(arr);
|
|
52
|
+
},
|
|
53
|
+
getPendingPubs: function (arr) {
|
|
54
|
+
const em = observableArray.getEntityAspect(arr).entityManager;
|
|
55
|
+
return em && em._pendingPubs;
|
|
56
|
+
},
|
|
57
|
+
rejectChanges: function (arr) {
|
|
58
|
+
const origValues = arr._obs.origValues;
|
|
59
|
+
if (!origValues)
|
|
60
|
+
return;
|
|
61
|
+
arr.forEach(function (co) {
|
|
62
|
+
clearAspect(co, arr);
|
|
63
|
+
});
|
|
64
|
+
arr.length = 0;
|
|
65
|
+
origValues.forEach(function (co) {
|
|
66
|
+
arr.push(co);
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
acceptChanges: function (arr) {
|
|
70
|
+
arr._obs.origValues = null;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
// local functions
|
|
74
|
+
function clearAspect(co, arr) {
|
|
75
|
+
let coAspect = co.complexAspect;
|
|
76
|
+
// if not already attached - exit
|
|
77
|
+
if (coAspect.parent !== arr.parent)
|
|
78
|
+
return null;
|
|
79
|
+
coAspect.parent = undefined;
|
|
80
|
+
coAspect.parentProperty = undefined;
|
|
81
|
+
return coAspect;
|
|
82
|
+
}
|
|
83
|
+
function setAspect(co, arr) {
|
|
84
|
+
let coAspect = co.complexAspect;
|
|
85
|
+
// if already attached - exit
|
|
86
|
+
if (coAspect.parent === arr.parent)
|
|
87
|
+
return null;
|
|
88
|
+
coAspect.parent = arr.parent;
|
|
89
|
+
coAspect.parentProperty = arr.parentProperty;
|
|
90
|
+
return coAspect;
|
|
91
|
+
}
|
|
92
|
+
/** For use by breeze plugin authors only. The class is for use in building a {@link ModelLibraryAdapter} implementation.
|
|
93
|
+
@adapter (see {@link ModelLibraryAdapter})
|
|
94
|
+
@hidden
|
|
95
|
+
*/
|
|
96
|
+
export function makeComplexArray(arr, parent, parentProperty) {
|
|
97
|
+
const arrX = arr;
|
|
98
|
+
arrX.parent = parent;
|
|
99
|
+
arrX.parentProperty = parentProperty;
|
|
100
|
+
arrX.arrayChanged = new BreezeEvent("arrayChanged", arrX);
|
|
101
|
+
observableArray.initialize(arrX, complexArrayOps);
|
|
102
|
+
return arrX;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=complex-array.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"complex-array.js","sourceRoot":"","sources":["../../src/entity/complex-array.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAuC,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAc7F;;;;;;GAMG;AAEH;;;;;;;;;;;;;;;;EAgBE;AAEF,MAAM,eAAe,GAAuB;IAE1C,yDAAyD;IACzD,WAAW,EAAE,UAAU,GAAiB,EAAE,IAAqB;QAC7D,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;YAC5B,OAAO,CAAC,CAAC,aAAa,IAAI,IAAI,IAAI,CAAC,CAAC,aAAa,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC;QAC1E,CAAC,CAAC,CAAC;IACL,CAAC;IAED,YAAY,EAAE,UAAU,GAAiB;QACvC,eAAe,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;IAED,WAAW,EAAE,UAAU,GAAiB,EAAE,IAAqB;QAC7D,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;YACtB,IAAI,CAAC,CAAC,aAAa,IAAI,CAAC,CAAC,aAAa,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;gBACtD,MAAM,IAAI,KAAK,CAAC,4FAA4F,CAAC,CAAC;YA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,IAAI,CAAC;IAEhD,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC;IAC5B,QAAQ,CAAC,cAAc,GAAG,SAAS,CAAC;IACpC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,SAAS,SAAS,CAAC,EAAiB,EAAE,GAAiB;IACrD,IAAI,QAAQ,GAAG,EAAE,CAAC,aAAa,CAAC;IAChC,6BAA6B;IAC7B,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAChD,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,GAAG,GAAG,CAAC,cAAc,CAAC;IAE7C,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;EAGE;AACF,MAAM,UAAU,gBAAgB,CAAC,GAAU,EAAE,MAAwB,EAAE,cAA4B;IACjG,MAAM,IAAI,GAAG,GAAU,CAAC;IACxB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACrB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACrC,IAAI,CAAC,YAAY,GAAG,IAAI,WAAW,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IAC1D,eAAe,CAAC,UAAU,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IAClD,OAAO,IAAoB,CAAC;AAC9B,CAAC","sourcesContent":["import { BreezeEvent } from '../core/event.js';\r\nimport { ObservableArray, ObservableArrayOps, observableArray } from './observable-array.js';\r\nimport type { ComplexObject, StructuralObject } from './entity-aspect.js';\r\nimport type { DataProperty } from '../metadata/entity-metadata.js';\r\n\r\n/** The value of a complex property that holds an array of complex objects. It is a real array:\r\nadding or removing an element marks the owning entity Modified, can be undone by `rejectChanges`,\r\nand raises the array's `arrayChanged` event with an {@link ArrayChangedArgs}. */\r\nexport interface ComplexArray<T extends ComplexObject = ComplexObject> extends ObservableArray<T> {\r\n /** The entity or complex object that owns this array. */\r\n parent?: StructuralObject;\r\n /** The complex {@link DataProperty} of `parent` that holds this array. */\r\n parentProperty?: DataProperty;\r\n}\r\n\r\n/*\r\n Complex arrays are not a class: they are real arrays whose mutating methods are replaced, so that\r\n changing one updates the entity that owns it. A complex array is a collection of complexTypes\r\n associated with a data property on a single entity or other complex object, i.e. customer.orders\r\n or order.orderDetails.\r\n @class {complexArray}\r\n */\r\n\r\n/*\r\nAn {@link BreezeEvent} that fires whenever the contents of this array changed. This event\r\nis fired any time a new entity is attached or added to the EntityManager and happens to belong to this collection.\r\nAdds that occur as a result of query or import operations are batched so that all of the adds or removes to any individual\r\ncollections are collected into a single notification event for each relation array.\r\n@example\r\n // assume order is an order entity attached to an EntityManager.\r\n orders.arrayChanged.subscribe(\r\n function (arrayChangedArgs) {\r\n var addedEntities = arrayChangedArgs.added;\r\n var removedEntities = arrayChanged.removed;\r\n });\r\n@event arrayChanged\r\n@param added {Array of Entity} An array of all of the entities added to this collection.\r\n@param removed {Array of Entity} An array of all of the removed from this collection.\r\n@readOnly\r\n*/\r\n\r\nconst complexArrayOps: ObservableArrayOps = {\r\n\r\n // skip any that are already attached to this same parent\r\n getGoodAdds: function (arr: ComplexArray, adds: ComplexObject[]) {\r\n return adds.filter(function (a) {\r\n return a.complexAspect == null || a.complexAspect.parent !== arr.parent;\r\n });\r\n },\r\n\r\n beforeChange: function (arr: ComplexArray) {\r\n observableArray.updateEntityState(arr);\r\n },\r\n\r\n processAdds: function (arr: ComplexArray, adds: ComplexObject[]) {\r\n adds.forEach(function (a) {\r\n if (a.complexAspect && a.complexAspect.parent != null) {\r\n throw new Error(\"The complexObject is already attached. Either clone it or remove it from its current owner\");\r\n }\r\n setAspect(a, arr);\r\n });\r\n },\r\n\r\n processRemoves: function (arr: ComplexArray, removes: ComplexObject[]) {\r\n removes.forEach(function (a) {\r\n clearAspect(a, arr);\r\n });\r\n },\r\n\r\n getEventParent: function (arr: ComplexArray) {\r\n return observableArray.getEntityAspect(arr);\r\n },\r\n\r\n getPendingPubs: function (arr: ComplexArray) {\r\n const em = observableArray.getEntityAspect(arr).entityManager;\r\n return em && (em as any)._pendingPubs;\r\n },\r\n\r\n rejectChanges: function (arr: ComplexArray) {\r\n const origValues = arr._obs.origValues;\r\n if (!origValues) return;\r\n arr.forEach(function (co: ComplexObject) {\r\n clearAspect(co, arr);\r\n });\r\n arr.length = 0;\r\n origValues.forEach(function (co: ComplexObject) {\r\n arr.push(co);\r\n });\r\n },\r\n\r\n acceptChanges: function (arr: ComplexArray) {\r\n arr._obs.origValues = null;\r\n }\r\n};\r\n\r\n// local functions\r\n\r\nfunction clearAspect(co: ComplexObject, arr: ComplexArray) {\r\n let coAspect = co.complexAspect;\r\n // if not already attached - exit\r\n if (coAspect.parent !== arr.parent) return null;\r\n\r\n coAspect.parent = undefined;\r\n coAspect.parentProperty = undefined;\r\n return coAspect;\r\n}\r\n\r\nfunction setAspect(co: ComplexObject, arr: ComplexArray) {\r\n let coAspect = co.complexAspect;\r\n // if already attached - exit\r\n if (coAspect.parent === arr.parent) return null;\r\n coAspect.parent = arr.parent;\r\n coAspect.parentProperty = arr.parentProperty;\r\n\r\n return coAspect;\r\n}\r\n\r\n/** For use by breeze plugin authors only. The class is for use in building a {@link ModelLibraryAdapter} implementation.\r\n@adapter (see {@link ModelLibraryAdapter})\r\n@hidden\r\n*/\r\nexport function makeComplexArray(arr: any[], parent: StructuralObject, parentProperty: DataProperty): ComplexArray {\r\n const arrX = arr as any;\r\n arrX.parent = parent;\r\n arrX.parentProperty = parentProperty;\r\n arrX.arrayChanged = new BreezeEvent(\"arrayChanged\", arrX);\r\n observableArray.initialize(arrX, complexArrayOps);\r\n return arrX as ComplexArray;\r\n}\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|