@onecx/accelerator 3.8.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onecx/accelerator",
3
- "version": "3.8.1",
3
+ "version": "4.0.0",
4
4
  "peerDependencies": {
5
5
  "tslib": "^2.3.0",
6
6
  "rxjs": "7.8.1"
package/src/index.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export * from './lib/topic/topic';
2
+ export * from './lib/topic/syncable-topic';
package/src/index.js CHANGED
@@ -2,4 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./lib/topic/topic"), exports);
5
+ tslib_1.__exportStar(require("./lib/topic/syncable-topic"), exports);
5
6
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/accelerator/src/index.ts"],"names":[],"mappings":";;;AAAA,4DAAiC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/accelerator/src/index.ts"],"names":[],"mappings":";;;AAAA,4DAAiC;AACjC,qEAA0C"}
@@ -0,0 +1,22 @@
1
+ import { Topic } from './topic';
2
+ /**
3
+ * This class allows sync access to the value of a Topic.
4
+ * If you use this as a super class, you have to make sure that
5
+ * in all cases when the value is accessed it is initialized.
6
+ * This means that you have to make sure that in all possible
7
+ * code paths reaching your sync access you made sure that it
8
+ * is initialized (in standalone and shell mode).
9
+ * Keep in mind that there can be multiple instances of the Topic
10
+ * so you cannot rely on the fact that the shell has already checked
11
+ * that it is initialized.
12
+ */
13
+ export declare class SyncableTopic<T> extends Topic<T> {
14
+ constructor(name: string, version: number);
15
+ /**
16
+ * This function does not offer read after write consistency!
17
+ * This means you cannot call it directly after publish, because the new value will not be there yet!
18
+ * This function will return undefined until the isInitialized Promise is resolved.
19
+ * @returns the current value of the Topic in a synchronous way
20
+ */
21
+ getValue(): T | undefined;
22
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SyncableTopic = void 0;
4
+ const topic_1 = require("./topic");
5
+ /**
6
+ * This class allows sync access to the value of a Topic.
7
+ * If you use this as a super class, you have to make sure that
8
+ * in all cases when the value is accessed it is initialized.
9
+ * This means that you have to make sure that in all possible
10
+ * code paths reaching your sync access you made sure that it
11
+ * is initialized (in standalone and shell mode).
12
+ * Keep in mind that there can be multiple instances of the Topic
13
+ * so you cannot rely on the fact that the shell has already checked
14
+ * that it is initialized.
15
+ */
16
+ class SyncableTopic extends topic_1.Topic {
17
+ constructor(name, version) {
18
+ super(name, version);
19
+ }
20
+ /**
21
+ * This function does not offer read after write consistency!
22
+ * This means you cannot call it directly after publish, because the new value will not be there yet!
23
+ * This function will return undefined until the isInitialized Promise is resolved.
24
+ * @returns the current value of the Topic in a synchronous way
25
+ */
26
+ getValue() {
27
+ return this.isInit ? this.data.value.data : undefined;
28
+ }
29
+ }
30
+ exports.SyncableTopic = SyncableTopic;
31
+ //# sourceMappingURL=syncable-topic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"syncable-topic.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/topic/syncable-topic.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAG/B;;;;;;;;;;GAUG;AACH,MAAa,aAAiB,SAAQ,aAAQ;IAC5C,YAAY,IAAY,EAAE,OAAe;QACvC,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IACtB,CAAC;IAED;;;;;OAKG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAuB,IAAI,CAAC,IAAI,CAAC,KAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAA;IAC9E,CAAC;CACF;AAdD,sCAcC"}
@@ -1,22 +1,18 @@
1
- import { Observable, Observer, OperatorFunction, Subscribable, Subscription, UnaryFunction } from 'rxjs';
1
+ import { BehaviorSubject, Observable, Observer, OperatorFunction, Subscribable, Subscription, UnaryFunction } from 'rxjs';
2
+ import { TopicDataMessage } from './topic-data-message';
2
3
  export declare class Topic<T> implements Subscribable<T> {
3
4
  private name;
4
5
  private version;
5
- isInitialized: Promise<void>;
6
- private data;
7
- private isInit;
6
+ protected isInitializedPromise: Promise<void>;
7
+ protected data: BehaviorSubject<TopicDataMessage<T> | undefined>;
8
+ protected isInit: boolean;
8
9
  private resolveInitPromise;
9
10
  private eventListener;
11
+ private publishPromiseResolver;
10
12
  constructor(name: string, version: number);
13
+ get isInitialized(): Promise<void>;
11
14
  asObservable(): Observable<T>;
12
15
  subscribe(observerOrNext?: Partial<Observer<T>> | ((value: T) => void), error?: (error: any) => void, complete?: () => void): Subscription;
13
- /**
14
- * This function does not offer read after write consistency!
15
- * This means you cannot call it directly after publish, because the new value will not be there yet!
16
- * This function will return undefined unti the isInitialized promise is resolved.
17
- * @returns the current value of the topic in a synchronous way
18
- */
19
- getValue(): T | undefined;
20
16
  pipe(): Observable<T>;
21
17
  pipe<A>(op1: UnaryFunction<Observable<T>, A>): A;
22
18
  pipe<A, B>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>): B;
@@ -29,7 +25,7 @@ export declare class Topic<T> implements Subscribable<T> {
29
25
  pipe<A, B, C, D, E, F, G, H, I>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>, op8: UnaryFunction<G, H>, op9: UnaryFunction<H, I>): I;
30
26
  pipe<A, B, C, D, E, F, G, H, I>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>, op8: UnaryFunction<G, H>, op9: UnaryFunction<H, I>, ...operations: OperatorFunction<any, any>[]): Observable<unknown>;
31
27
  pipe<A, B, C, D, E, F, G, H, I>(op1: UnaryFunction<Observable<T>, A>, op2: UnaryFunction<A, B>, op3: UnaryFunction<B, C>, op4: UnaryFunction<C, D>, op5: UnaryFunction<D, E>, op6: UnaryFunction<E, F>, op7: UnaryFunction<F, G>, op8: UnaryFunction<G, H>, op9: UnaryFunction<H, I>, ...operations: UnaryFunction<any, any>[]): unknown;
32
- publish(value: T): void;
28
+ publish(value: T): Promise<void>;
33
29
  destroy(): void;
34
30
  private onMessage;
35
31
  }
@@ -8,42 +8,41 @@ const topic_message_1 = require("./topic-message");
8
8
  class Topic {
9
9
  name;
10
10
  version;
11
- isInitialized;
11
+ isInitializedPromise;
12
12
  data = new rxjs_1.BehaviorSubject(undefined);
13
13
  isInit = false;
14
14
  resolveInitPromise;
15
15
  eventListener = (m) => this.onMessage(m);
16
+ publishPromiseResolver = {};
16
17
  constructor(name, version) {
17
18
  this.name = name;
18
19
  this.version = version;
19
- this.isInitialized = new Promise((resolve) => {
20
+ this.isInitializedPromise = new Promise((resolve) => {
20
21
  this.resolveInitPromise = resolve;
21
22
  });
22
23
  window.addEventListener('message', this.eventListener);
23
24
  const message = new topic_message_1.TopicMessage("TopicGet" /* TopicMessageType.TopicGet */, this.name, this.version);
24
25
  window.postMessage(message, '*');
25
26
  }
27
+ get isInitialized() {
28
+ return this.isInitializedPromise;
29
+ }
26
30
  asObservable() {
27
31
  return this.data.asObservable().pipe((0, operators_1.filter)(() => this.isInit), (0, operators_1.map)((d) => d.data));
28
32
  }
29
33
  subscribe(observerOrNext, error, complete) {
30
34
  return this.asObservable().subscribe(observerOrNext, error, complete);
31
35
  }
32
- /**
33
- * This function does not offer read after write consistency!
34
- * This means you cannot call it directly after publish, because the new value will not be there yet!
35
- * This function will return undefined unti the isInitialized promise is resolved.
36
- * @returns the current value of the topic in a synchronous way
37
- */
38
- getValue() {
39
- return this.isInit ? this.data.value.data : undefined;
40
- }
41
36
  pipe(...operations) {
42
37
  return this.asObservable().pipe(...operations);
43
38
  }
44
39
  publish(value) {
45
40
  const message = new topic_data_message_1.TopicDataMessage("TopicNext" /* TopicMessageType.TopicNext */, this.name, this.version, value);
41
+ const promise = new Promise((resolve) => {
42
+ this.publishPromiseResolver[message.timestamp] = resolve;
43
+ });
46
44
  window.postMessage(message, '*');
45
+ return promise;
47
46
  }
48
47
  destroy() {
49
48
  window.removeEventListener('message', this.eventListener, true);
@@ -57,6 +56,11 @@ class Topic {
57
56
  this.isInit = true;
58
57
  this.data.next(m.data);
59
58
  this.resolveInitPromise();
59
+ const publishPromiseResolver = this.publishPromiseResolver[m.data.timestamp];
60
+ if (publishPromiseResolver) {
61
+ publishPromiseResolver();
62
+ delete this.publishPromiseResolver[m.data.timestamp];
63
+ }
60
64
  }
61
65
  break;
62
66
  case "TopicGet" /* TopicMessageType.TopicGet */:
@@ -1 +1 @@
1
- {"version":3,"file":"topic.js","sourceRoot":"","sources":["../../../../../../libs/accelerator/src/lib/topic/topic.ts"],"names":[],"mappings":";;;AAAA,8CAA4C;AAC5C,+BAAyH;AACzH,6DAAuD;AACvD,mDAA8C;AAG9C,MAAa,KAAK;IAQI;IAAsB;IAPnC,aAAa,CAAe;IAC3B,IAAI,GAAG,IAAI,sBAAe,CAAkC,SAAS,CAAC,CAAA;IAEtE,MAAM,GAAG,KAAK,CAAA;IACd,kBAAkB,CAA4C;IAC9D,aAAa,GAAG,CAAC,CAA6B,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IAE5E,YAAoB,IAAY,EAAU,OAAe;QAArC,SAAI,GAAJ,IAAI,CAAQ;QAAU,YAAO,GAAP,OAAO,CAAQ;QACvD,IAAI,CAAC,aAAa,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YACjD,IAAI,CAAC,kBAAkB,GAAG,OAAO,CAAA;QACnC,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,gBAAg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