cbcore-ts 1.1.16 → 1.1.18
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/compiledScripts/CBCore.d.ts +16 -16
- package/compiledScripts/CBCore.js +19 -19
- package/compiledScripts/CBCore.js.map +2 -2
- package/compiledScripts/CBSocketCallbackHolder.d.ts +5 -5
- package/compiledScripts/CBSocketCallbackHolder.js +12 -12
- package/compiledScripts/CBSocketCallbackHolder.js.map +2 -2
- package/compiledScripts/CBSocketClient.d.ts +11 -12
- package/compiledScripts/CBSocketClient.js +5 -5
- package/compiledScripts/CBSocketClient.js.map +2 -2
- package/package.json +2 -2
- package/scripts/CBCore.ts +23 -23
- package/scripts/CBSocketCallbackHolder.ts +15 -15
- package/scripts/CBSocketClient.ts +18 -19
package/scripts/CBCore.ts
CHANGED
|
@@ -41,17 +41,17 @@ declare const CBCoreInitializerObject: any
|
|
|
41
41
|
* // Additional session-level state goes here.
|
|
42
42
|
* mySessionData: MySessionData | undefined = undefined
|
|
43
43
|
*
|
|
44
|
-
* // Override
|
|
44
|
+
* // Override userProfileDidChange to fetch session data before the
|
|
45
45
|
* // userDidLogIn broadcast fires. Call super only after your data
|
|
46
46
|
* // is ready so that every listener receives a fully populated core.
|
|
47
|
-
* override async
|
|
47
|
+
* override async userProfileDidChange() {
|
|
48
48
|
* if (IS(this.userProfile)) {
|
|
49
49
|
* this.mySessionData = await fetchMySessionData()
|
|
50
50
|
* }
|
|
51
51
|
* else {
|
|
52
52
|
* this.mySessionData = undefined
|
|
53
53
|
* }
|
|
54
|
-
* super.
|
|
54
|
+
* super.userProfileDidChange()
|
|
55
55
|
* }
|
|
56
56
|
*
|
|
57
57
|
* // Expose a typed singleton so callers never need CBCore.sharedInstance.
|
|
@@ -65,7 +65,7 @@ declare const CBCoreInitializerObject: any
|
|
|
65
65
|
* 2. Register the subclass at app startup, before UICore is initialised:
|
|
66
66
|
*
|
|
67
67
|
* ```typescript
|
|
68
|
-
* CBCore.
|
|
68
|
+
* CBCore.registerSharedInstance(new MyAppCore())
|
|
69
69
|
* CBCore.initIfNeededWithViewCore(new UICore(...))
|
|
70
70
|
* ```
|
|
71
71
|
*
|
|
@@ -108,13 +108,13 @@ export class CBCore extends UIObject {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
if (event.key == "CBLanguageKey") {
|
|
111
|
-
this.
|
|
111
|
+
this.languageKeyDidChange()
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
}.bind(this))
|
|
115
115
|
|
|
116
116
|
|
|
117
|
-
this.
|
|
117
|
+
this.languageKeyDidChange()
|
|
118
118
|
|
|
119
119
|
|
|
120
120
|
}
|
|
@@ -130,10 +130,10 @@ export class CBCore extends UIObject {
|
|
|
130
130
|
/**
|
|
131
131
|
* Returns the shared singleton instance.
|
|
132
132
|
*
|
|
133
|
-
* If `
|
|
133
|
+
* If `registerSharedInstance` was called before this getter was first accessed,
|
|
134
134
|
* that instance is returned. Otherwise a default `CBCore` is created.
|
|
135
135
|
* Library-internal code always goes through this getter, so registering a
|
|
136
|
-
* subclass via `
|
|
136
|
+
* subclass via `registerSharedInstance` is sufficient to replace the singleton
|
|
137
137
|
* for the entire session.
|
|
138
138
|
*/
|
|
139
139
|
static get sharedInstance() {
|
|
@@ -154,16 +154,16 @@ export class CBCore extends UIObject {
|
|
|
154
154
|
*
|
|
155
155
|
* ```typescript
|
|
156
156
|
* // App entry point — must be the very first thing that runs.
|
|
157
|
-
* CBCore.
|
|
157
|
+
* CBCore.registerSharedInstance(new MyAppCore())
|
|
158
158
|
* CBCore.initIfNeededWithViewCore(new UICore("root", RootViewController))
|
|
159
159
|
* ```
|
|
160
160
|
*/
|
|
161
|
-
static
|
|
161
|
+
static registerSharedInstance(instance: CBCore) {
|
|
162
162
|
|
|
163
163
|
if (CBCore._sharedInstance) {
|
|
164
164
|
/// #if DEV
|
|
165
165
|
throw new Error(
|
|
166
|
-
"CBCore.
|
|
166
|
+
"CBCore.registerSharedInstance must be called before sharedInstance is first accessed. " +
|
|
167
167
|
"Move the call to the very top of your app entry point."
|
|
168
168
|
)
|
|
169
169
|
/// #endif
|
|
@@ -201,10 +201,10 @@ export class CBCore extends UIObject {
|
|
|
201
201
|
set isUserLoggedIn(isUserLoggedIn: boolean) {
|
|
202
202
|
const previousValue = this.isUserLoggedIn
|
|
203
203
|
this._isUserLoggedIn = isUserLoggedIn
|
|
204
|
-
this.
|
|
204
|
+
this.userLoginStateDidChange(previousValue)
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
userLoginStateDidChange(previousValue: boolean) {
|
|
208
208
|
|
|
209
209
|
const isUserLoggedIn = this.isUserLoggedIn
|
|
210
210
|
|
|
@@ -221,7 +221,7 @@ export class CBCore extends UIObject {
|
|
|
221
221
|
}
|
|
222
222
|
else if (previousValue != isUserLoggedIn) {
|
|
223
223
|
|
|
224
|
-
this.
|
|
224
|
+
this.userDidLogOut()
|
|
225
225
|
|
|
226
226
|
}
|
|
227
227
|
|
|
@@ -233,7 +233,7 @@ export class CBCore extends UIObject {
|
|
|
233
233
|
* Subclasses may override this to suppress the route change when they intend
|
|
234
234
|
* to navigate somewhere specific immediately after logout.
|
|
235
235
|
*/
|
|
236
|
-
|
|
236
|
+
userDidLogOut() {
|
|
237
237
|
|
|
238
238
|
this.performFunctionWithDelay(0.01, function (this: CBCore) {
|
|
239
239
|
|
|
@@ -273,33 +273,33 @@ export class CBCore extends UIObject {
|
|
|
273
273
|
|
|
274
274
|
set userProfile(userProfile: CBUserProfile) {
|
|
275
275
|
this._userProfile = userProfile
|
|
276
|
-
this.
|
|
276
|
+
this.userProfileDidChange()
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
/**
|
|
280
280
|
* Called whenever `userProfile` is assigned.
|
|
281
281
|
*
|
|
282
282
|
* The default implementation derives `isUserLoggedIn` from the profile
|
|
283
|
-
* and triggers the login/logout broadcast via `
|
|
283
|
+
* and triggers the login/logout broadcast via `userLoginStateDidChange`.
|
|
284
284
|
*
|
|
285
285
|
* Subclasses may override this to fetch additional session data before
|
|
286
286
|
* the broadcast fires. The override must be `async` and must call
|
|
287
|
-
* `super.
|
|
287
|
+
* `super.userProfileDidChange()` after it has finished populating any
|
|
288
288
|
* extra state, so that all broadcast listeners receive a complete core:
|
|
289
289
|
*
|
|
290
290
|
* ```typescript
|
|
291
|
-
* override async
|
|
291
|
+
* override async userProfileDidChange() {
|
|
292
292
|
* if (IS(this.userProfile)) {
|
|
293
293
|
* this.companyStatus = (await SocketClient.CurrentUserStatusInCompany()).result
|
|
294
294
|
* }
|
|
295
295
|
* else {
|
|
296
296
|
* this.companyStatus = undefined
|
|
297
297
|
* }
|
|
298
|
-
* super.
|
|
298
|
+
* super.userProfileDidChange() // broadcast fires here
|
|
299
299
|
* }
|
|
300
300
|
* ```
|
|
301
301
|
*/
|
|
302
|
-
|
|
302
|
+
userProfileDidChange() {
|
|
303
303
|
this.isUserLoggedIn = IS(this.userProfile)
|
|
304
304
|
}
|
|
305
305
|
|
|
@@ -309,7 +309,7 @@ export class CBCore extends UIObject {
|
|
|
309
309
|
localStorage.removeItem("CBLanguageKey")
|
|
310
310
|
}
|
|
311
311
|
localStorage.setItem("CBLanguageKey", JSON.stringify(languageKey))
|
|
312
|
-
this.
|
|
312
|
+
this.languageKeyDidChange()
|
|
313
313
|
}
|
|
314
314
|
|
|
315
315
|
get languageKey() {
|
|
@@ -319,7 +319,7 @@ export class CBCore extends UIObject {
|
|
|
319
319
|
).replace("\"", "")
|
|
320
320
|
}
|
|
321
321
|
|
|
322
|
-
|
|
322
|
+
languageKeyDidChange() {
|
|
323
323
|
UIRoute.currentRoute.routeWithComponent(
|
|
324
324
|
"settings",
|
|
325
325
|
{ "language": this.languageKey },
|
|
@@ -38,15 +38,15 @@ interface CBSocketCallbackHolderMessageDescriptor {
|
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Called when a keepalive frame arrives for this descriptor's request.
|
|
41
|
-
* Registered via CBSocketRequestPromise.
|
|
41
|
+
* Registered via CBSocketRequestPromise.addKeepaliveHandler().
|
|
42
42
|
*/
|
|
43
43
|
keepaliveHandler?: (payload: CBSocketKeepalivePayload) => void;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
|
-
* When true the
|
|
46
|
+
* When true the default keepalive handler on CBSocketClient is NOT called
|
|
47
47
|
* for this descriptor — only keepaliveHandler fires.
|
|
48
48
|
*/
|
|
49
|
-
|
|
49
|
+
skipsDefaultKeepaliveHandler: boolean;
|
|
50
50
|
|
|
51
51
|
}
|
|
52
52
|
|
|
@@ -72,7 +72,7 @@ export class CBSocketCallbackHolder extends UIObject {
|
|
|
72
72
|
[x: string]: CBSocketMessageHandlerFunction[]
|
|
73
73
|
} = {}
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
oneTimeHandlers: {
|
|
76
76
|
[x: string]: CBSocketMessageHandlerFunction[]
|
|
77
77
|
} = {}
|
|
78
78
|
|
|
@@ -164,15 +164,15 @@ export class CBSocketCallbackHolder extends UIObject {
|
|
|
164
164
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
|
|
167
|
+
registerOneTimeHandler(key: string, handlerFunction: CBSocketMessageHandlerFunction) {
|
|
168
168
|
|
|
169
|
-
if (!this.
|
|
169
|
+
if (!this.oneTimeHandlers[key]) {
|
|
170
170
|
|
|
171
|
-
this.
|
|
171
|
+
this.oneTimeHandlers[key] = []
|
|
172
172
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
this.
|
|
175
|
+
this.oneTimeHandlers[key].push(handlerFunction)
|
|
176
176
|
|
|
177
177
|
}
|
|
178
178
|
|
|
@@ -503,7 +503,7 @@ export class CBSocketCallbackHolder extends UIObject {
|
|
|
503
503
|
completionFunction: completionFunction,
|
|
504
504
|
|
|
505
505
|
keepaliveHandler: undefined,
|
|
506
|
-
|
|
506
|
+
skipsDefaultKeepaliveHandler: NO
|
|
507
507
|
|
|
508
508
|
})
|
|
509
509
|
|
|
@@ -625,7 +625,7 @@ export class CBSocketCallbackHolder extends UIObject {
|
|
|
625
625
|
}.bind(this),
|
|
626
626
|
|
|
627
627
|
keepaliveHandler: undefined,
|
|
628
|
-
|
|
628
|
+
skipsDefaultKeepaliveHandler: NO
|
|
629
629
|
|
|
630
630
|
})
|
|
631
631
|
|
|
@@ -664,9 +664,9 @@ export class CBSocketCallbackHolder extends UIObject {
|
|
|
664
664
|
|
|
665
665
|
}
|
|
666
666
|
|
|
667
|
-
if (this.
|
|
667
|
+
if (this.oneTimeHandlers[key]) {
|
|
668
668
|
|
|
669
|
-
this.
|
|
669
|
+
this.oneTimeHandlers[key].forEach(function (
|
|
670
670
|
this: CBSocketCallbackHolder,
|
|
671
671
|
handler: CBSocketMessageHandlerFunction
|
|
672
672
|
) {
|
|
@@ -675,7 +675,7 @@ export class CBSocketCallbackHolder extends UIObject {
|
|
|
675
675
|
|
|
676
676
|
}.bind(this))
|
|
677
677
|
|
|
678
|
-
delete this.
|
|
678
|
+
delete this.oneTimeHandlers[key]
|
|
679
679
|
|
|
680
680
|
}
|
|
681
681
|
|
|
@@ -706,8 +706,8 @@ export class CBSocketCallbackHolder extends UIObject {
|
|
|
706
706
|
this._resetTimeoutForDescriptor(descriptor)
|
|
707
707
|
|
|
708
708
|
// Fire the default handler unless the per-call handler overrides it
|
|
709
|
-
if (!descriptor.
|
|
710
|
-
this._socketClient.
|
|
709
|
+
if (!descriptor.skipsDefaultKeepaliveHandler) {
|
|
710
|
+
this._socketClient.keepaliveDidArrive?.(payload)
|
|
711
711
|
}
|
|
712
712
|
|
|
713
713
|
// Fire the per-call handler if one was registered
|
|
@@ -65,7 +65,7 @@ export function IS_NOT_SOCKET_ERROR(object: any) {
|
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* A Promise returned by resultForMessageForKey.
|
|
68
|
-
* Exposes
|
|
68
|
+
* Exposes addKeepaliveHandler() for registering a keepalive callback
|
|
69
69
|
* in the same fluent style as the rest of the API.
|
|
70
70
|
*/
|
|
71
71
|
export interface CBSocketRequestPromise<T> extends Promise<T> {
|
|
@@ -73,16 +73,15 @@ export interface CBSocketRequestPromise<T> extends Promise<T> {
|
|
|
73
73
|
* Register a handler to be called each time a keepalive frame arrives
|
|
74
74
|
* for this request.
|
|
75
75
|
*
|
|
76
|
-
* @param handler
|
|
77
|
-
* @param
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* request.
|
|
76
|
+
* @param handler Called with the payload sent by the server.
|
|
77
|
+
* @param callsDefaultHandler When true (default) the application-level
|
|
78
|
+
* keepaliveDidArrive fires first, then this
|
|
79
|
+
* handler. When false this handler fires alone
|
|
80
|
+
* and the default is suppressed for this request.
|
|
82
81
|
*/
|
|
83
|
-
|
|
82
|
+
addKeepaliveHandler(
|
|
84
83
|
handler: (payload: CBSocketKeepalivePayload) => void,
|
|
85
|
-
|
|
84
|
+
callsDefaultHandler?: boolean
|
|
86
85
|
): CBSocketRequestPromise<T>
|
|
87
86
|
}
|
|
88
87
|
|
|
@@ -142,12 +141,12 @@ export class CBSocketClient extends UIObject {
|
|
|
142
141
|
/**
|
|
143
142
|
* Application-level keepalive handler. Called for every keepalive frame
|
|
144
143
|
* received on any request, unless the per-call handler was registered with
|
|
145
|
-
*
|
|
144
|
+
* callsDefaultHandler = false.
|
|
146
145
|
*
|
|
147
146
|
* Configure once at application startup:
|
|
148
|
-
* CBSocketClient.sharedInstance.
|
|
147
|
+
* CBSocketClient.sharedInstance.keepaliveDidArrive = payload => { ... }
|
|
149
148
|
*/
|
|
150
|
-
|
|
149
|
+
keepaliveDidArrive?: (payload: CBSocketKeepalivePayload) => void
|
|
151
150
|
|
|
152
151
|
|
|
153
152
|
constructor(core: CBCore) {
|
|
@@ -490,15 +489,15 @@ export class CBSocketClient extends UIObject {
|
|
|
490
489
|
|
|
491
490
|
const requestPromise = basePromise as CBSocketRequestPromise<any>
|
|
492
491
|
|
|
493
|
-
requestPromise.
|
|
492
|
+
requestPromise.addKeepaliveHandler = (
|
|
494
493
|
handler: (payload: CBSocketKeepalivePayload) => void,
|
|
495
|
-
|
|
494
|
+
callsDefaultHandler = YES
|
|
496
495
|
): CBSocketRequestPromise<any> => {
|
|
497
496
|
|
|
498
497
|
// The descriptor is pushed synchronously before _sendMessageForKey returns,
|
|
499
498
|
// so capturedIdentifier is already set at this point.
|
|
500
499
|
if (capturedIdentifier) {
|
|
501
|
-
this.
|
|
500
|
+
this._attachKeepaliveHandlerForRequestIdentifier(capturedIdentifier, handler, callsDefaultHandler)
|
|
502
501
|
}
|
|
503
502
|
|
|
504
503
|
return requestPromise
|
|
@@ -514,10 +513,10 @@ export class CBSocketClient extends UIObject {
|
|
|
514
513
|
* Finds the descriptor for the given request identifier and attaches the
|
|
515
514
|
* keepalive handler fields to it.
|
|
516
515
|
*/
|
|
517
|
-
|
|
516
|
+
_attachKeepaliveHandlerForRequestIdentifier(
|
|
518
517
|
identifier: string,
|
|
519
518
|
handler: (payload: CBSocketKeepalivePayload) => void,
|
|
520
|
-
|
|
519
|
+
callsDefaultHandler: boolean
|
|
521
520
|
) {
|
|
522
521
|
|
|
523
522
|
const descriptorKey = this._callbackHolder.keysForIdentifiers[identifier]
|
|
@@ -536,7 +535,7 @@ export class CBSocketClient extends UIObject {
|
|
|
536
535
|
}
|
|
537
536
|
|
|
538
537
|
descriptor.keepaliveHandler = handler
|
|
539
|
-
descriptor.
|
|
538
|
+
descriptor.skipsDefaultKeepaliveHandler = !callsDefaultHandler
|
|
540
539
|
|
|
541
540
|
}
|
|
542
541
|
|
|
@@ -780,7 +779,7 @@ export class CBSocketClient extends UIObject {
|
|
|
780
779
|
|
|
781
780
|
addTargetForOneMessageForKey(key: string, handlerFunction: CBSocketMessageHandlerFunction) {
|
|
782
781
|
|
|
783
|
-
this._callbackHolder.
|
|
782
|
+
this._callbackHolder.registerOneTimeHandler(key, handlerFunction)
|
|
784
783
|
|
|
785
784
|
if (IS_NOT(this._subscribedKeys[key])) {
|
|
786
785
|
|