@salesforce/lds-default-luvio 1.124.1 → 1.124.3
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/dist/es/es2018/main.js +117 -117
- package/dist/{types → es/es2018/types}/src/main.d.ts +30 -30
- package/{sfdc → dist/es/es2018/types/src}/registry.d.ts +58 -58
- package/{sfdc → dist/es/es2018/types/src}/sfdc.d.ts +2 -2
- package/package.json +5 -5
- package/sfdc/ldsEngine.d.ts +1 -1
- package/sfdc/ldsEngine.js +155 -155
- package/sfdc/ldsEngineNoAura.d.ts +1 -1
- package/sfdc/ldsEngineNoAura.js +117 -117
- package/sfdc/{main.d.ts → types/main.d.ts} +30 -30
- package/{dist/types/src → sfdc/types}/registry.d.ts +58 -58
- package/{dist/types/src → sfdc/types}/sfdc.d.ts +2 -2
- package/dist/umd/es2018/main.js +0 -150
- package/dist/umd/es5/main.js +0 -150
package/sfdc/ldsEngine.js
CHANGED
|
@@ -22,165 +22,165 @@ import { Luvio, Environment, InMemoryStore } from 'force/luvioEngine';
|
|
|
22
22
|
export { Environment, GraphNode, HttpStatusCode, InMemoryStore, Luvio, Reader, StoreResolveResultState, adapterToNetworkPriority, buildStaleWhileRevalidateImplementation, coerceAdapterRequestContext, createCustomAdapterEventEmitter, emitAdapterEvent } from 'force/luvioEngine';
|
|
23
23
|
import networkAdapter from 'force/ldsNetwork';
|
|
24
24
|
|
|
25
|
-
/*
|
|
26
|
-
* Copyright (c) 2022, Salesforce, Inc.,
|
|
27
|
-
* All rights reserved.
|
|
28
|
-
* For full license text, see the LICENSE.txt file
|
|
29
|
-
*/
|
|
30
|
-
/**
|
|
31
|
-
* Callbacks to be invoked when registrations happen,
|
|
32
|
-
*/
|
|
33
|
-
const callbacks$1 = [];
|
|
34
|
-
/**
|
|
35
|
-
* Registrations that have already occurred.
|
|
36
|
-
*
|
|
37
|
-
* Note that Registrations are maintained as a list rather than a map to allow
|
|
38
|
-
* the same id to be registered multiple times with potentially different
|
|
39
|
-
* data.
|
|
40
|
-
*/
|
|
41
|
-
const registrations = [];
|
|
42
|
-
/**
|
|
43
|
-
* Invokes callback for each Registration, both past & future. That is, callback
|
|
44
|
-
* will be invoked exactly as many times as register() is called.
|
|
45
|
-
*
|
|
46
|
-
* Note that Registration ids are not guaranteed to be unique. The meaning of
|
|
47
|
-
* multiple Registrations with the same id is determined by the caller(s) of
|
|
48
|
-
* register().
|
|
49
|
-
*/
|
|
50
|
-
function forEachRegistration(callback) {
|
|
51
|
-
callbacks$1.push(callback);
|
|
52
|
-
registrations.forEach((r) => callback(r));
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Invokes callback when the specified id is registered.
|
|
56
|
-
*
|
|
57
|
-
* Note that callback may be invoked:
|
|
58
|
-
*
|
|
59
|
-
* - multiple times if multiple calls to register() specify the id
|
|
60
|
-
* - never if the specified id is never registered
|
|
61
|
-
*/
|
|
62
|
-
function withRegistration(id, callback) {
|
|
63
|
-
forEachRegistration((r) => {
|
|
64
|
-
if (r.id === id) {
|
|
65
|
-
callback(r);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Register an id and associated data.
|
|
71
|
-
*
|
|
72
|
-
* Callers of register() should make types available that include:
|
|
73
|
-
*
|
|
74
|
-
* - the id they will register
|
|
75
|
-
* - definitions for any additional properties on their Registration objects
|
|
76
|
-
*
|
|
77
|
-
* For example:
|
|
78
|
-
*
|
|
79
|
-
* export type MyRegistration = {
|
|
80
|
-
* id: 'myRegistrationId',
|
|
81
|
-
*
|
|
82
|
-
* // some value that others might need
|
|
83
|
-
* myValue: string,
|
|
84
|
-
*
|
|
85
|
-
* // some function that others might want to call
|
|
86
|
-
* myFunction: () => void,
|
|
87
|
-
* };
|
|
88
|
-
* register({ id: 'myRegistrationId', myValue: 'foo', myFunction: () => {} } as MyRegistration);
|
|
89
|
-
*
|
|
90
|
-
* The registry itself does not dictate the format of ids nor attempt to coordinate
|
|
91
|
-
* uniqueness of id values.
|
|
92
|
-
*
|
|
93
|
-
* The same id can be registered multiple times with different Registration
|
|
94
|
-
* objects.
|
|
95
|
-
*/
|
|
96
|
-
function register(r) {
|
|
97
|
-
registrations.push(r);
|
|
98
|
-
callbacks$1.forEach((callback) => callback(r));
|
|
25
|
+
/*
|
|
26
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
27
|
+
* All rights reserved.
|
|
28
|
+
* For full license text, see the LICENSE.txt file
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* Callbacks to be invoked when registrations happen,
|
|
32
|
+
*/
|
|
33
|
+
const callbacks$1 = [];
|
|
34
|
+
/**
|
|
35
|
+
* Registrations that have already occurred.
|
|
36
|
+
*
|
|
37
|
+
* Note that Registrations are maintained as a list rather than a map to allow
|
|
38
|
+
* the same id to be registered multiple times with potentially different
|
|
39
|
+
* data.
|
|
40
|
+
*/
|
|
41
|
+
const registrations = [];
|
|
42
|
+
/**
|
|
43
|
+
* Invokes callback for each Registration, both past & future. That is, callback
|
|
44
|
+
* will be invoked exactly as many times as register() is called.
|
|
45
|
+
*
|
|
46
|
+
* Note that Registration ids are not guaranteed to be unique. The meaning of
|
|
47
|
+
* multiple Registrations with the same id is determined by the caller(s) of
|
|
48
|
+
* register().
|
|
49
|
+
*/
|
|
50
|
+
function forEachRegistration(callback) {
|
|
51
|
+
callbacks$1.push(callback);
|
|
52
|
+
registrations.forEach((r) => callback(r));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Invokes callback when the specified id is registered.
|
|
56
|
+
*
|
|
57
|
+
* Note that callback may be invoked:
|
|
58
|
+
*
|
|
59
|
+
* - multiple times if multiple calls to register() specify the id
|
|
60
|
+
* - never if the specified id is never registered
|
|
61
|
+
*/
|
|
62
|
+
function withRegistration(id, callback) {
|
|
63
|
+
forEachRegistration((r) => {
|
|
64
|
+
if (r.id === id) {
|
|
65
|
+
callback(r);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Register an id and associated data.
|
|
71
|
+
*
|
|
72
|
+
* Callers of register() should make types available that include:
|
|
73
|
+
*
|
|
74
|
+
* - the id they will register
|
|
75
|
+
* - definitions for any additional properties on their Registration objects
|
|
76
|
+
*
|
|
77
|
+
* For example:
|
|
78
|
+
*
|
|
79
|
+
* export type MyRegistration = {
|
|
80
|
+
* id: 'myRegistrationId',
|
|
81
|
+
*
|
|
82
|
+
* // some value that others might need
|
|
83
|
+
* myValue: string,
|
|
84
|
+
*
|
|
85
|
+
* // some function that others might want to call
|
|
86
|
+
* myFunction: () => void,
|
|
87
|
+
* };
|
|
88
|
+
* register({ id: 'myRegistrationId', myValue: 'foo', myFunction: () => {} } as MyRegistration);
|
|
89
|
+
*
|
|
90
|
+
* The registry itself does not dictate the format of ids nor attempt to coordinate
|
|
91
|
+
* uniqueness of id values.
|
|
92
|
+
*
|
|
93
|
+
* The same id can be registered multiple times with different Registration
|
|
94
|
+
* objects.
|
|
95
|
+
*/
|
|
96
|
+
function register(r) {
|
|
97
|
+
registrations.push(r);
|
|
98
|
+
callbacks$1.forEach((callback) => callback(r));
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
/*
|
|
102
|
-
* Copyright (c) 2022, Salesforce, Inc.,
|
|
103
|
-
* All rights reserved.
|
|
104
|
-
* For full license text, see the LICENSE.txt file
|
|
105
|
-
*/
|
|
106
|
-
// most recently set default Luvio instance
|
|
107
|
-
let defaultLuvio;
|
|
108
|
-
// callbacks to be invoked when default luvio instance is set/changed
|
|
109
|
-
let callbacks = [];
|
|
110
|
-
/**
|
|
111
|
-
* Constructs/sets the default Luvio instance. Any previously-set default luvio instance
|
|
112
|
-
* is overwritten.
|
|
113
|
-
*/
|
|
114
|
-
function setDefaultLuvio(params) {
|
|
115
|
-
const newLuvio = 'luvio' in params
|
|
116
|
-
? params.luvio
|
|
117
|
-
: 'environment' in params
|
|
118
|
-
? new Luvio(params.environment)
|
|
119
|
-
: 'networkAdapter' in params
|
|
120
|
-
? new Luvio(new Environment(params.store || new InMemoryStore(), params.networkAdapter))
|
|
121
|
-
: undefined;
|
|
122
|
-
if (newLuvio === undefined) {
|
|
123
|
-
// eslint-disable-next-line @salesforce/lds/no-error-in-production
|
|
124
|
-
throw new Error('unable to construct default Luvio instance from supplied parameters');
|
|
125
|
-
}
|
|
126
|
-
defaultLuvio = newLuvio;
|
|
127
|
-
// inform observers
|
|
128
|
-
for (let i = 0; i < callbacks.length; ++i) {
|
|
129
|
-
callbacks[i](defaultLuvio);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Registers a callback to be invoked with the default Luvio instance. Note that the
|
|
134
|
-
* callback may be invoked multiple times if the default Luvio changes.
|
|
135
|
-
*
|
|
136
|
-
* @param callback callback to be invoked with default Luvio instance
|
|
137
|
-
*/
|
|
138
|
-
function withDefaultLuvio(callback) {
|
|
139
|
-
if (defaultLuvio) {
|
|
140
|
-
callback(defaultLuvio);
|
|
141
|
-
}
|
|
142
|
-
callbacks.push(callback);
|
|
101
|
+
/*
|
|
102
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
103
|
+
* All rights reserved.
|
|
104
|
+
* For full license text, see the LICENSE.txt file
|
|
105
|
+
*/
|
|
106
|
+
// most recently set default Luvio instance
|
|
107
|
+
let defaultLuvio;
|
|
108
|
+
// callbacks to be invoked when default luvio instance is set/changed
|
|
109
|
+
let callbacks = [];
|
|
110
|
+
/**
|
|
111
|
+
* Constructs/sets the default Luvio instance. Any previously-set default luvio instance
|
|
112
|
+
* is overwritten.
|
|
113
|
+
*/
|
|
114
|
+
function setDefaultLuvio(params) {
|
|
115
|
+
const newLuvio = 'luvio' in params
|
|
116
|
+
? params.luvio
|
|
117
|
+
: 'environment' in params
|
|
118
|
+
? new Luvio(params.environment)
|
|
119
|
+
: 'networkAdapter' in params
|
|
120
|
+
? new Luvio(new Environment(params.store || new InMemoryStore(), params.networkAdapter))
|
|
121
|
+
: undefined;
|
|
122
|
+
if (newLuvio === undefined) {
|
|
123
|
+
// eslint-disable-next-line @salesforce/lds/no-error-in-production
|
|
124
|
+
throw new Error('unable to construct default Luvio instance from supplied parameters');
|
|
125
|
+
}
|
|
126
|
+
defaultLuvio = newLuvio;
|
|
127
|
+
// inform observers
|
|
128
|
+
for (let i = 0; i < callbacks.length; ++i) {
|
|
129
|
+
callbacks[i](defaultLuvio);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Registers a callback to be invoked with the default Luvio instance. Note that the
|
|
134
|
+
* callback may be invoked multiple times if the default Luvio changes.
|
|
135
|
+
*
|
|
136
|
+
* @param callback callback to be invoked with default Luvio instance
|
|
137
|
+
*/
|
|
138
|
+
function withDefaultLuvio(callback) {
|
|
139
|
+
if (defaultLuvio) {
|
|
140
|
+
callback(defaultLuvio);
|
|
141
|
+
}
|
|
142
|
+
callbacks.push(callback);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
/*
|
|
146
|
-
* Copyright (c) 2022, Salesforce, Inc.,
|
|
147
|
-
* All rights reserved.
|
|
148
|
-
* For full license text, see the LICENSE.txt file
|
|
149
|
-
*/
|
|
150
|
-
// The code in lds-runtime-aura (force/ldsEngineCreator) depends on Aura module
|
|
151
|
-
// services to invoke its LDS initialization logic. Unfortunately, Aura component
|
|
152
|
-
// tests do not support module services and have no analogous function. The net
|
|
153
|
-
// result is that LDS is never initialized in the iframe that loads the Aura
|
|
154
|
-
// component test & any attempts to create an LWC component that uses an LDS
|
|
155
|
-
// adapter fail because the wire adapter constructors are undefined (W-9233247).
|
|
156
|
-
//
|
|
157
|
-
// The code below is the least offensive workaround we could come up with. When
|
|
158
|
-
// this code (force/ldsEngine) is loaded via static imports in an Aura component
|
|
159
|
-
// test iframe, it will perform a minimal initialization of LDS that allows
|
|
160
|
-
// the test to run and access data on the server. The instrumentation and
|
|
161
|
-
// configuration initialization steps from lds-runtime-aura are skipped to
|
|
162
|
-
// keep the logic simpler & faster.
|
|
163
|
-
//
|
|
164
|
-
// For future reference, here are the values we see from getApp():
|
|
165
|
-
//
|
|
166
|
-
// - for a regular .app, the name of the app, e.g. "one:one"
|
|
167
|
-
// - for the top-level iframe of a .app loaded in JSTEST mode, "aurajstest:jstest"
|
|
168
|
-
// - for the top-level iframe of a .cmp loaded in JSTEST mode, undefined
|
|
169
|
-
// - for a test iframe of a .cmp or .app test loaded via
|
|
170
|
-
// /auratest/test.app?testName=..&aura.mode=AUTOJSTEST, undefined
|
|
171
|
-
// - for a test iframe loaded via /aura?... (no clue where/how these are
|
|
172
|
-
// generated), undefined
|
|
173
|
-
if (typeof $A !== 'undefined' &&
|
|
174
|
-
$A.getContext().getMode().indexOf('AUTOJSTEST') > -1 &&
|
|
175
|
-
$A.getContext().getApp() === undefined) {
|
|
176
|
-
const storeOptions = {
|
|
177
|
-
scheduler: () => { },
|
|
178
|
-
};
|
|
179
|
-
const store = new InMemoryStore(storeOptions);
|
|
180
|
-
const environment = new Environment(store, networkAdapter);
|
|
181
|
-
const luvio = new Luvio(environment);
|
|
182
|
-
setDefaultLuvio({ luvio });
|
|
145
|
+
/*
|
|
146
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
147
|
+
* All rights reserved.
|
|
148
|
+
* For full license text, see the LICENSE.txt file
|
|
149
|
+
*/
|
|
150
|
+
// The code in lds-runtime-aura (force/ldsEngineCreator) depends on Aura module
|
|
151
|
+
// services to invoke its LDS initialization logic. Unfortunately, Aura component
|
|
152
|
+
// tests do not support module services and have no analogous function. The net
|
|
153
|
+
// result is that LDS is never initialized in the iframe that loads the Aura
|
|
154
|
+
// component test & any attempts to create an LWC component that uses an LDS
|
|
155
|
+
// adapter fail because the wire adapter constructors are undefined (W-9233247).
|
|
156
|
+
//
|
|
157
|
+
// The code below is the least offensive workaround we could come up with. When
|
|
158
|
+
// this code (force/ldsEngine) is loaded via static imports in an Aura component
|
|
159
|
+
// test iframe, it will perform a minimal initialization of LDS that allows
|
|
160
|
+
// the test to run and access data on the server. The instrumentation and
|
|
161
|
+
// configuration initialization steps from lds-runtime-aura are skipped to
|
|
162
|
+
// keep the logic simpler & faster.
|
|
163
|
+
//
|
|
164
|
+
// For future reference, here are the values we see from getApp():
|
|
165
|
+
//
|
|
166
|
+
// - for a regular .app, the name of the app, e.g. "one:one"
|
|
167
|
+
// - for the top-level iframe of a .app loaded in JSTEST mode, "aurajstest:jstest"
|
|
168
|
+
// - for the top-level iframe of a .cmp loaded in JSTEST mode, undefined
|
|
169
|
+
// - for a test iframe of a .cmp or .app test loaded via
|
|
170
|
+
// /auratest/test.app?testName=..&aura.mode=AUTOJSTEST, undefined
|
|
171
|
+
// - for a test iframe loaded via /aura?... (no clue where/how these are
|
|
172
|
+
// generated), undefined
|
|
173
|
+
if (typeof $A !== 'undefined' &&
|
|
174
|
+
$A.getContext().getMode().indexOf('AUTOJSTEST') > -1 &&
|
|
175
|
+
$A.getContext().getApp() === undefined) {
|
|
176
|
+
const storeOptions = {
|
|
177
|
+
scheduler: () => { },
|
|
178
|
+
};
|
|
179
|
+
const store = new InMemoryStore(storeOptions);
|
|
180
|
+
const environment = new Environment(store, networkAdapter);
|
|
181
|
+
const luvio = new Luvio(environment);
|
|
182
|
+
setDefaultLuvio({ luvio });
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
export { forEachRegistration, register, setDefaultLuvio, withDefaultLuvio, withRegistration };
|
|
186
|
-
// version: 1.124.
|
|
186
|
+
// version: 1.124.3-cf2dbb2fa
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './main';
|
|
1
|
+
export * from './types/main';
|
package/sfdc/ldsEngineNoAura.js
CHANGED
|
@@ -20,125 +20,125 @@
|
|
|
20
20
|
/* proxy-compat-disable */
|
|
21
21
|
import { Luvio, Environment, InMemoryStore } from 'force/luvioEngine';
|
|
22
22
|
|
|
23
|
-
/*
|
|
24
|
-
* Copyright (c) 2022, Salesforce, Inc.,
|
|
25
|
-
* All rights reserved.
|
|
26
|
-
* For full license text, see the LICENSE.txt file
|
|
27
|
-
*/
|
|
28
|
-
/**
|
|
29
|
-
* Callbacks to be invoked when registrations happen,
|
|
30
|
-
*/
|
|
31
|
-
const callbacks$1 = [];
|
|
32
|
-
/**
|
|
33
|
-
* Registrations that have already occurred.
|
|
34
|
-
*
|
|
35
|
-
* Note that Registrations are maintained as a list rather than a map to allow
|
|
36
|
-
* the same id to be registered multiple times with potentially different
|
|
37
|
-
* data.
|
|
38
|
-
*/
|
|
39
|
-
const registrations = [];
|
|
40
|
-
/**
|
|
41
|
-
* Invokes callback for each Registration, both past & future. That is, callback
|
|
42
|
-
* will be invoked exactly as many times as register() is called.
|
|
43
|
-
*
|
|
44
|
-
* Note that Registration ids are not guaranteed to be unique. The meaning of
|
|
45
|
-
* multiple Registrations with the same id is determined by the caller(s) of
|
|
46
|
-
* register().
|
|
47
|
-
*/
|
|
48
|
-
function forEachRegistration(callback) {
|
|
49
|
-
callbacks$1.push(callback);
|
|
50
|
-
registrations.forEach((r) => callback(r));
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Invokes callback when the specified id is registered.
|
|
54
|
-
*
|
|
55
|
-
* Note that callback may be invoked:
|
|
56
|
-
*
|
|
57
|
-
* - multiple times if multiple calls to register() specify the id
|
|
58
|
-
* - never if the specified id is never registered
|
|
59
|
-
*/
|
|
60
|
-
function withRegistration(id, callback) {
|
|
61
|
-
forEachRegistration((r) => {
|
|
62
|
-
if (r.id === id) {
|
|
63
|
-
callback(r);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Register an id and associated data.
|
|
69
|
-
*
|
|
70
|
-
* Callers of register() should make types available that include:
|
|
71
|
-
*
|
|
72
|
-
* - the id they will register
|
|
73
|
-
* - definitions for any additional properties on their Registration objects
|
|
74
|
-
*
|
|
75
|
-
* For example:
|
|
76
|
-
*
|
|
77
|
-
* export type MyRegistration = {
|
|
78
|
-
* id: 'myRegistrationId',
|
|
79
|
-
*
|
|
80
|
-
* // some value that others might need
|
|
81
|
-
* myValue: string,
|
|
82
|
-
*
|
|
83
|
-
* // some function that others might want to call
|
|
84
|
-
* myFunction: () => void,
|
|
85
|
-
* };
|
|
86
|
-
* register({ id: 'myRegistrationId', myValue: 'foo', myFunction: () => {} } as MyRegistration);
|
|
87
|
-
*
|
|
88
|
-
* The registry itself does not dictate the format of ids nor attempt to coordinate
|
|
89
|
-
* uniqueness of id values.
|
|
90
|
-
*
|
|
91
|
-
* The same id can be registered multiple times with different Registration
|
|
92
|
-
* objects.
|
|
93
|
-
*/
|
|
94
|
-
function register(r) {
|
|
95
|
-
registrations.push(r);
|
|
96
|
-
callbacks$1.forEach((callback) => callback(r));
|
|
23
|
+
/*
|
|
24
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
25
|
+
* All rights reserved.
|
|
26
|
+
* For full license text, see the LICENSE.txt file
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Callbacks to be invoked when registrations happen,
|
|
30
|
+
*/
|
|
31
|
+
const callbacks$1 = [];
|
|
32
|
+
/**
|
|
33
|
+
* Registrations that have already occurred.
|
|
34
|
+
*
|
|
35
|
+
* Note that Registrations are maintained as a list rather than a map to allow
|
|
36
|
+
* the same id to be registered multiple times with potentially different
|
|
37
|
+
* data.
|
|
38
|
+
*/
|
|
39
|
+
const registrations = [];
|
|
40
|
+
/**
|
|
41
|
+
* Invokes callback for each Registration, both past & future. That is, callback
|
|
42
|
+
* will be invoked exactly as many times as register() is called.
|
|
43
|
+
*
|
|
44
|
+
* Note that Registration ids are not guaranteed to be unique. The meaning of
|
|
45
|
+
* multiple Registrations with the same id is determined by the caller(s) of
|
|
46
|
+
* register().
|
|
47
|
+
*/
|
|
48
|
+
function forEachRegistration(callback) {
|
|
49
|
+
callbacks$1.push(callback);
|
|
50
|
+
registrations.forEach((r) => callback(r));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Invokes callback when the specified id is registered.
|
|
54
|
+
*
|
|
55
|
+
* Note that callback may be invoked:
|
|
56
|
+
*
|
|
57
|
+
* - multiple times if multiple calls to register() specify the id
|
|
58
|
+
* - never if the specified id is never registered
|
|
59
|
+
*/
|
|
60
|
+
function withRegistration(id, callback) {
|
|
61
|
+
forEachRegistration((r) => {
|
|
62
|
+
if (r.id === id) {
|
|
63
|
+
callback(r);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Register an id and associated data.
|
|
69
|
+
*
|
|
70
|
+
* Callers of register() should make types available that include:
|
|
71
|
+
*
|
|
72
|
+
* - the id they will register
|
|
73
|
+
* - definitions for any additional properties on their Registration objects
|
|
74
|
+
*
|
|
75
|
+
* For example:
|
|
76
|
+
*
|
|
77
|
+
* export type MyRegistration = {
|
|
78
|
+
* id: 'myRegistrationId',
|
|
79
|
+
*
|
|
80
|
+
* // some value that others might need
|
|
81
|
+
* myValue: string,
|
|
82
|
+
*
|
|
83
|
+
* // some function that others might want to call
|
|
84
|
+
* myFunction: () => void,
|
|
85
|
+
* };
|
|
86
|
+
* register({ id: 'myRegistrationId', myValue: 'foo', myFunction: () => {} } as MyRegistration);
|
|
87
|
+
*
|
|
88
|
+
* The registry itself does not dictate the format of ids nor attempt to coordinate
|
|
89
|
+
* uniqueness of id values.
|
|
90
|
+
*
|
|
91
|
+
* The same id can be registered multiple times with different Registration
|
|
92
|
+
* objects.
|
|
93
|
+
*/
|
|
94
|
+
function register(r) {
|
|
95
|
+
registrations.push(r);
|
|
96
|
+
callbacks$1.forEach((callback) => callback(r));
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
/*
|
|
100
|
-
* Copyright (c) 2022, Salesforce, Inc.,
|
|
101
|
-
* All rights reserved.
|
|
102
|
-
* For full license text, see the LICENSE.txt file
|
|
103
|
-
*/
|
|
104
|
-
// most recently set default Luvio instance
|
|
105
|
-
let defaultLuvio;
|
|
106
|
-
// callbacks to be invoked when default luvio instance is set/changed
|
|
107
|
-
let callbacks = [];
|
|
108
|
-
/**
|
|
109
|
-
* Constructs/sets the default Luvio instance. Any previously-set default luvio instance
|
|
110
|
-
* is overwritten.
|
|
111
|
-
*/
|
|
112
|
-
function setDefaultLuvio(params) {
|
|
113
|
-
const newLuvio = 'luvio' in params
|
|
114
|
-
? params.luvio
|
|
115
|
-
: 'environment' in params
|
|
116
|
-
? new Luvio(params.environment)
|
|
117
|
-
: 'networkAdapter' in params
|
|
118
|
-
? new Luvio(new Environment(params.store || new InMemoryStore(), params.networkAdapter))
|
|
119
|
-
: undefined;
|
|
120
|
-
if (newLuvio === undefined) {
|
|
121
|
-
// eslint-disable-next-line @salesforce/lds/no-error-in-production
|
|
122
|
-
throw new Error('unable to construct default Luvio instance from supplied parameters');
|
|
123
|
-
}
|
|
124
|
-
defaultLuvio = newLuvio;
|
|
125
|
-
// inform observers
|
|
126
|
-
for (let i = 0; i < callbacks.length; ++i) {
|
|
127
|
-
callbacks[i](defaultLuvio);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Registers a callback to be invoked with the default Luvio instance. Note that the
|
|
132
|
-
* callback may be invoked multiple times if the default Luvio changes.
|
|
133
|
-
*
|
|
134
|
-
* @param callback callback to be invoked with default Luvio instance
|
|
135
|
-
*/
|
|
136
|
-
function withDefaultLuvio(callback) {
|
|
137
|
-
if (defaultLuvio) {
|
|
138
|
-
callback(defaultLuvio);
|
|
139
|
-
}
|
|
140
|
-
callbacks.push(callback);
|
|
99
|
+
/*
|
|
100
|
+
* Copyright (c) 2022, Salesforce, Inc.,
|
|
101
|
+
* All rights reserved.
|
|
102
|
+
* For full license text, see the LICENSE.txt file
|
|
103
|
+
*/
|
|
104
|
+
// most recently set default Luvio instance
|
|
105
|
+
let defaultLuvio;
|
|
106
|
+
// callbacks to be invoked when default luvio instance is set/changed
|
|
107
|
+
let callbacks = [];
|
|
108
|
+
/**
|
|
109
|
+
* Constructs/sets the default Luvio instance. Any previously-set default luvio instance
|
|
110
|
+
* is overwritten.
|
|
111
|
+
*/
|
|
112
|
+
function setDefaultLuvio(params) {
|
|
113
|
+
const newLuvio = 'luvio' in params
|
|
114
|
+
? params.luvio
|
|
115
|
+
: 'environment' in params
|
|
116
|
+
? new Luvio(params.environment)
|
|
117
|
+
: 'networkAdapter' in params
|
|
118
|
+
? new Luvio(new Environment(params.store || new InMemoryStore(), params.networkAdapter))
|
|
119
|
+
: undefined;
|
|
120
|
+
if (newLuvio === undefined) {
|
|
121
|
+
// eslint-disable-next-line @salesforce/lds/no-error-in-production
|
|
122
|
+
throw new Error('unable to construct default Luvio instance from supplied parameters');
|
|
123
|
+
}
|
|
124
|
+
defaultLuvio = newLuvio;
|
|
125
|
+
// inform observers
|
|
126
|
+
for (let i = 0; i < callbacks.length; ++i) {
|
|
127
|
+
callbacks[i](defaultLuvio);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Registers a callback to be invoked with the default Luvio instance. Note that the
|
|
132
|
+
* callback may be invoked multiple times if the default Luvio changes.
|
|
133
|
+
*
|
|
134
|
+
* @param callback callback to be invoked with default Luvio instance
|
|
135
|
+
*/
|
|
136
|
+
function withDefaultLuvio(callback) {
|
|
137
|
+
if (defaultLuvio) {
|
|
138
|
+
callback(defaultLuvio);
|
|
139
|
+
}
|
|
140
|
+
callbacks.push(callback);
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
export { forEachRegistration, register, setDefaultLuvio, withDefaultLuvio, withRegistration };
|
|
144
|
-
// version: 1.124.
|
|
144
|
+
// version: 1.124.3-cf2dbb2fa
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import type { NetworkAdapter } from '@luvio/engine';
|
|
2
|
-
import { Environment, Luvio, InMemoryStore } from '@luvio/engine';
|
|
3
|
-
/**
|
|
4
|
-
* Parameters accepted by setDefaultLuvio.
|
|
5
|
-
*/
|
|
6
|
-
export type SetDefaultLuvioParameters = {
|
|
7
|
-
luvio: Luvio;
|
|
8
|
-
} | {
|
|
9
|
-
environment: Environment;
|
|
10
|
-
} | {
|
|
11
|
-
store?: InMemoryStore;
|
|
12
|
-
networkAdapter: NetworkAdapter;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Callback used to inform interested parties that a new default Luvio has been set.
|
|
16
|
-
*/
|
|
17
|
-
export type Callback = (luvio: Luvio) => void;
|
|
18
|
-
/**
|
|
19
|
-
* Constructs/sets the default Luvio instance. Any previously-set default luvio instance
|
|
20
|
-
* is overwritten.
|
|
21
|
-
*/
|
|
22
|
-
export declare function setDefaultLuvio(params: SetDefaultLuvioParameters): void;
|
|
23
|
-
/**
|
|
24
|
-
* Registers a callback to be invoked with the default Luvio instance. Note that the
|
|
25
|
-
* callback may be invoked multiple times if the default Luvio changes.
|
|
26
|
-
*
|
|
27
|
-
* @param callback callback to be invoked with default Luvio instance
|
|
28
|
-
*/
|
|
29
|
-
export declare function withDefaultLuvio(callback: Callback): void;
|
|
30
|
-
export * from './registry';
|
|
1
|
+
import type { NetworkAdapter } from '@luvio/engine';
|
|
2
|
+
import { Environment, Luvio, InMemoryStore } from '@luvio/engine';
|
|
3
|
+
/**
|
|
4
|
+
* Parameters accepted by setDefaultLuvio.
|
|
5
|
+
*/
|
|
6
|
+
export type SetDefaultLuvioParameters = {
|
|
7
|
+
luvio: Luvio;
|
|
8
|
+
} | {
|
|
9
|
+
environment: Environment;
|
|
10
|
+
} | {
|
|
11
|
+
store?: InMemoryStore;
|
|
12
|
+
networkAdapter: NetworkAdapter;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Callback used to inform interested parties that a new default Luvio has been set.
|
|
16
|
+
*/
|
|
17
|
+
export type Callback = (luvio: Luvio) => void;
|
|
18
|
+
/**
|
|
19
|
+
* Constructs/sets the default Luvio instance. Any previously-set default luvio instance
|
|
20
|
+
* is overwritten.
|
|
21
|
+
*/
|
|
22
|
+
export declare function setDefaultLuvio(params: SetDefaultLuvioParameters): void;
|
|
23
|
+
/**
|
|
24
|
+
* Registers a callback to be invoked with the default Luvio instance. Note that the
|
|
25
|
+
* callback may be invoked multiple times if the default Luvio changes.
|
|
26
|
+
*
|
|
27
|
+
* @param callback callback to be invoked with default Luvio instance
|
|
28
|
+
*/
|
|
29
|
+
export declare function withDefaultLuvio(callback: Callback): void;
|
|
30
|
+
export * from './registry';
|