@lwc/wire-service 2.26.1 → 2.26.2

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.
@@ -11,7 +11,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
11
11
  function isUndefined(obj) {
12
12
  return obj === undefined;
13
13
  }
14
- /** version: 2.26.1 */
14
+ /** version: 2.26.2 */
15
15
 
16
16
  /*
17
17
  * Copyright (c) 2018, salesforce.com, inc.
@@ -189,4 +189,4 @@ class LegacyWireAdapterBridge {
189
189
  exports.ValueChangedEvent = ValueChangedEvent;
190
190
  exports.register = register;
191
191
  exports.registerWireService = registerWireService;
192
- /** version: 2.26.1 */
192
+ /** version: 2.26.2 */
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Copyright (C) 2018 salesforce.com, inc.
3
+ */
4
+ /**
5
+ * Copyright (C) 2018 salesforce.com, inc.
6
+ */
7
+ function isUndefined(obj) {
8
+ return obj === undefined;
9
+ }
10
+ /** version: 2.26.2 */
11
+
12
+ /*
13
+ * Copyright (c) 2018, salesforce.com, inc.
14
+ * All rights reserved.
15
+ * SPDX-License-Identifier: MIT
16
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
17
+ */
18
+ const ValueChangedEventType = 'ValueChangedEvent';
19
+ /**
20
+ * Event fired by wire adapters to emit a new value.
21
+ */
22
+ class ValueChangedEvent {
23
+ constructor(value) {
24
+ this.type = ValueChangedEventType;
25
+ this.value = value;
26
+ }
27
+ }
28
+
29
+ /*
30
+ * Copyright (c) 2018, salesforce.com, inc.
31
+ * All rights reserved.
32
+ * SPDX-License-Identifier: MIT
33
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
34
+ */
35
+ const { freeze, defineProperty, isExtensible } = Object;
36
+ // This value needs to be in sync with wiring.ts from @lwc/engine-core
37
+ const DeprecatedWiredElementHost = '$$DeprecatedWiredElementHostKey$$';
38
+ const DeprecatedWiredParamsMeta = '$$DeprecatedWiredParamsMetaKey$$';
39
+ /**
40
+ * Registers a wire adapter factory for Lightning Platform.
41
+ * @deprecated
42
+ */
43
+ function register(adapterId, adapterEventTargetCallback) {
44
+ if (adapterId == null || !isExtensible(adapterId)) {
45
+ throw new TypeError('adapter id must be extensible');
46
+ }
47
+ if (typeof adapterEventTargetCallback !== 'function') {
48
+ throw new TypeError('adapter factory must be a callable');
49
+ }
50
+ if ('adapter' in adapterId) {
51
+ throw new TypeError('adapter id is already associated to an adapter factory');
52
+ }
53
+ const AdapterClass = class extends LegacyWireAdapterBridge {
54
+ constructor(dataCallback) {
55
+ super(dataCallback);
56
+ adapterEventTargetCallback(this.eventTarget);
57
+ }
58
+ };
59
+ freeze(AdapterClass);
60
+ freeze(AdapterClass.prototype);
61
+ defineProperty(adapterId, 'adapter', {
62
+ writable: false,
63
+ configurable: false,
64
+ value: AdapterClass,
65
+ });
66
+ }
67
+ /**
68
+ * Registers the wire service. noop
69
+ * @deprecated
70
+ */
71
+ function registerWireService() { }
72
+ const { forEach, splice: ArraySplice, indexOf: ArrayIndexOf } = Array.prototype;
73
+ // wire event target life cycle connectedCallback hook event type
74
+ const CONNECT = 'connect';
75
+ // wire event target life cycle disconnectedCallback hook event type
76
+ const DISCONNECT = 'disconnect';
77
+ // wire event target life cycle config changed hook event type
78
+ const CONFIG = 'config';
79
+ function removeListener(listeners, toRemove) {
80
+ const idx = ArrayIndexOf.call(listeners, toRemove);
81
+ if (idx > -1) {
82
+ ArraySplice.call(listeners, idx, 1);
83
+ }
84
+ }
85
+ function isEmptyConfig(config) {
86
+ return Object.keys(config).length === 0;
87
+ }
88
+ function isValidConfig(config, params) {
89
+ // The config is valid if there is no params, or if exist a param for which config[param] !== undefined.
90
+ return params.length === 0 || params.some((param) => !isUndefined(config[param]));
91
+ }
92
+ function isDifferentConfig(newConfig, oldConfig, params) {
93
+ return params.some((param) => newConfig[param] !== oldConfig[param]);
94
+ }
95
+ class LegacyWireAdapterBridge {
96
+ constructor(callback) {
97
+ this.connecting = [];
98
+ this.disconnecting = [];
99
+ this.configuring = [];
100
+ this.isFirstUpdate = true;
101
+ this.callback = callback;
102
+ this.wiredElementHost = callback[DeprecatedWiredElementHost];
103
+ this.dynamicParamsNames = callback[DeprecatedWiredParamsMeta];
104
+ this.eventTarget = {
105
+ addEventListener: (type, listener) => {
106
+ switch (type) {
107
+ case CONNECT: {
108
+ this.connecting.push(listener);
109
+ break;
110
+ }
111
+ case DISCONNECT: {
112
+ this.disconnecting.push(listener);
113
+ break;
114
+ }
115
+ case CONFIG: {
116
+ this.configuring.push(listener);
117
+ if (this.currentConfig !== undefined) {
118
+ listener.call(undefined, this.currentConfig);
119
+ }
120
+ break;
121
+ }
122
+ default:
123
+ throw new Error(`Invalid event type ${type}.`);
124
+ }
125
+ },
126
+ removeEventListener: (type, listener) => {
127
+ switch (type) {
128
+ case CONNECT: {
129
+ removeListener(this.connecting, listener);
130
+ break;
131
+ }
132
+ case DISCONNECT: {
133
+ removeListener(this.disconnecting, listener);
134
+ break;
135
+ }
136
+ case CONFIG: {
137
+ removeListener(this.configuring, listener);
138
+ break;
139
+ }
140
+ default:
141
+ throw new Error(`Invalid event type ${type}.`);
142
+ }
143
+ },
144
+ dispatchEvent: (evt) => {
145
+ if (evt instanceof ValueChangedEvent) {
146
+ const value = evt.value;
147
+ this.callback(value);
148
+ }
149
+ else if (evt.type === 'wirecontextevent') {
150
+ // TODO [#1357]: remove this branch
151
+ return this.wiredElementHost.dispatchEvent(evt);
152
+ }
153
+ else {
154
+ throw new Error(`Invalid event type ${evt.type}.`);
155
+ }
156
+ return false; // canceling signal since we don't want this to propagate
157
+ },
158
+ };
159
+ }
160
+ update(config) {
161
+ if (this.isFirstUpdate) {
162
+ // this is a special case for legacy wire adapters: when all the config params are undefined,
163
+ // the config on the wire adapter should not be called until one of them changes.
164
+ this.isFirstUpdate = false;
165
+ if (!isEmptyConfig(config) && !isValidConfig(config, this.dynamicParamsNames)) {
166
+ return;
167
+ }
168
+ }
169
+ if (isUndefined(this.currentConfig) ||
170
+ isDifferentConfig(config, this.currentConfig, this.dynamicParamsNames)) {
171
+ this.currentConfig = config;
172
+ forEach.call(this.configuring, (listener) => {
173
+ listener.call(undefined, config);
174
+ });
175
+ }
176
+ }
177
+ connect() {
178
+ forEach.call(this.connecting, (listener) => listener.call(undefined));
179
+ }
180
+ disconnect() {
181
+ forEach.call(this.disconnecting, (listener) => listener.call(undefined));
182
+ }
183
+ }
184
+
185
+ export { ValueChangedEvent, register, registerWireService };
186
+ /** version: 2.26.2 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lwc/wire-service",
3
- "version": "2.26.1",
3
+ "version": "2.26.2",
4
4
  "description": "@wire service",
5
5
  "homepage": "https://lwc.dev/",
6
6
  "repository": {
@@ -24,8 +24,8 @@
24
24
  "types/"
25
25
  ],
26
26
  "devDependencies": {
27
- "@lwc/engine-core": "2.26.1",
28
- "@lwc/shared": "2.26.1"
27
+ "@lwc/engine-core": "2.26.2",
28
+ "@lwc/shared": "2.26.2"
29
29
  },
30
30
  "lwc": {
31
31
  "modules": [