@builder.io/sdk-svelte 1.0.16 → 1.0.17

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.
@@ -122,41 +122,40 @@ function onClick(event) {
122
122
  clicked = true;
123
123
  }
124
124
  }
125
- function evalExpression(expression) {
126
- return expression.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
127
- code: group,
128
- context: context || {},
129
- localState: undefined,
130
- rootState: $builderContextSignal.rootState,
131
- rootSetState: $builderContextSignal.rootSetState,
132
- enableCache: true,
133
- })));
134
- }
135
- function handleRequest({ url, key }) {
136
- fetch(url)
137
- .then((response) => response.json())
138
- .then((json) => {
139
- const newState = {
140
- ...$builderContextSignal.rootState,
141
- [key]: json,
142
- };
143
- $builderContextSignal.rootSetState?.(newState);
144
- httpReqsData[key] = true;
145
- })
146
- .catch((err) => {
147
- console.error("error fetching dynamic data", url, err);
148
- });
149
- }
150
125
  function runHttpRequests() {
151
126
  const requests = $builderContextSignal.content?.data?.httpRequests ?? {};
152
127
  Object.entries(requests).forEach(([key, url]) => {
153
- if (url && (!httpReqsData[key] || isEditing())) {
154
- const evaluatedUrl = evalExpression(url);
155
- handleRequest({
156
- url: evaluatedUrl,
157
- key,
128
+ if (!url)
129
+ return;
130
+ // request already in progress
131
+ if (httpReqsPending[key])
132
+ return;
133
+ // request already completed, and not in edit mode
134
+ if (httpReqsData[key] && !isEditing())
135
+ return;
136
+ httpReqsPending[key] = true;
137
+ const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
138
+ code: group,
139
+ context: context || {},
140
+ localState: undefined,
141
+ rootState: $builderContextSignal.rootState,
142
+ rootSetState: $builderContextSignal.rootSetState,
143
+ enableCache: true,
144
+ })));
145
+ fetch(evaluatedUrl)
146
+ .then((response) => response.json())
147
+ .then((json) => {
148
+ mergeNewRootState({
149
+ [key]: json,
158
150
  });
159
- }
151
+ httpReqsData[key] = true;
152
+ })
153
+ .catch((err) => {
154
+ console.error("error fetching dynamic data", url, err);
155
+ })
156
+ .finally(() => {
157
+ httpReqsPending[key] = false;
158
+ });
160
159
  });
161
160
  }
162
161
  function emitStateUpdate() {
@@ -228,6 +227,7 @@ function elementRef_onInitpreviewingbldr(event) {
228
227
  let elementRef;
229
228
  let ContentWrapper = contentWrapper || "div";
230
229
  let httpReqsData = {};
230
+ let httpReqsPending = {};
231
231
  let clicked = false;
232
232
  onMount(() => {
233
233
  if (isBrowser()) {
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.16";
1
+ export declare const SDK_VERSION = "1.0.17";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.16";
1
+ export const SDK_VERSION = "1.0.17";
@@ -122,41 +122,40 @@ function onClick(event) {
122
122
  clicked = true;
123
123
  }
124
124
  }
125
- function evalExpression(expression) {
126
- return expression.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
127
- code: group,
128
- context: context || {},
129
- localState: undefined,
130
- rootState: $builderContextSignal.rootState,
131
- rootSetState: $builderContextSignal.rootSetState,
132
- enableCache: true,
133
- })));
134
- }
135
- function handleRequest({ url, key }) {
136
- fetch(url)
137
- .then((response) => response.json())
138
- .then((json) => {
139
- const newState = {
140
- ...$builderContextSignal.rootState,
141
- [key]: json,
142
- };
143
- $builderContextSignal.rootSetState?.(newState);
144
- httpReqsData[key] = true;
145
- })
146
- .catch((err) => {
147
- console.error("error fetching dynamic data", url, err);
148
- });
149
- }
150
125
  function runHttpRequests() {
151
126
  const requests = $builderContextSignal.content?.data?.httpRequests ?? {};
152
127
  Object.entries(requests).forEach(([key, url]) => {
153
- if (url && (!httpReqsData[key] || isEditing())) {
154
- const evaluatedUrl = evalExpression(url);
155
- handleRequest({
156
- url: evaluatedUrl,
157
- key,
128
+ if (!url)
129
+ return;
130
+ // request already in progress
131
+ if (httpReqsPending[key])
132
+ return;
133
+ // request already completed, and not in edit mode
134
+ if (httpReqsData[key] && !isEditing())
135
+ return;
136
+ httpReqsPending[key] = true;
137
+ const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
138
+ code: group,
139
+ context: context || {},
140
+ localState: undefined,
141
+ rootState: $builderContextSignal.rootState,
142
+ rootSetState: $builderContextSignal.rootSetState,
143
+ enableCache: true,
144
+ })));
145
+ fetch(evaluatedUrl)
146
+ .then((response) => response.json())
147
+ .then((json) => {
148
+ mergeNewRootState({
149
+ [key]: json,
158
150
  });
159
- }
151
+ httpReqsData[key] = true;
152
+ })
153
+ .catch((err) => {
154
+ console.error("error fetching dynamic data", url, err);
155
+ })
156
+ .finally(() => {
157
+ httpReqsPending[key] = false;
158
+ });
160
159
  });
161
160
  }
162
161
  function emitStateUpdate() {
@@ -228,6 +227,7 @@ function elementRef_onInitpreviewingbldr(event) {
228
227
  let elementRef;
229
228
  let ContentWrapper = contentWrapper || "div";
230
229
  let httpReqsData = {};
230
+ let httpReqsPending = {};
231
231
  let clicked = false;
232
232
  onMount(() => {
233
233
  if (isBrowser()) {
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.16";
1
+ export declare const SDK_VERSION = "1.0.17";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.16";
1
+ export const SDK_VERSION = "1.0.17";
@@ -122,41 +122,40 @@ function onClick(event) {
122
122
  clicked = true;
123
123
  }
124
124
  }
125
- function evalExpression(expression) {
126
- return expression.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
127
- code: group,
128
- context: context || {},
129
- localState: undefined,
130
- rootState: $builderContextSignal.rootState,
131
- rootSetState: $builderContextSignal.rootSetState,
132
- enableCache: true,
133
- })));
134
- }
135
- function handleRequest({ url, key }) {
136
- fetch(url)
137
- .then((response) => response.json())
138
- .then((json) => {
139
- const newState = {
140
- ...$builderContextSignal.rootState,
141
- [key]: json,
142
- };
143
- $builderContextSignal.rootSetState?.(newState);
144
- httpReqsData[key] = true;
145
- })
146
- .catch((err) => {
147
- console.error("error fetching dynamic data", url, err);
148
- });
149
- }
150
125
  function runHttpRequests() {
151
126
  const requests = $builderContextSignal.content?.data?.httpRequests ?? {};
152
127
  Object.entries(requests).forEach(([key, url]) => {
153
- if (url && (!httpReqsData[key] || isEditing())) {
154
- const evaluatedUrl = evalExpression(url);
155
- handleRequest({
156
- url: evaluatedUrl,
157
- key,
128
+ if (!url)
129
+ return;
130
+ // request already in progress
131
+ if (httpReqsPending[key])
132
+ return;
133
+ // request already completed, and not in edit mode
134
+ if (httpReqsData[key] && !isEditing())
135
+ return;
136
+ httpReqsPending[key] = true;
137
+ const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
138
+ code: group,
139
+ context: context || {},
140
+ localState: undefined,
141
+ rootState: $builderContextSignal.rootState,
142
+ rootSetState: $builderContextSignal.rootSetState,
143
+ enableCache: true,
144
+ })));
145
+ fetch(evaluatedUrl)
146
+ .then((response) => response.json())
147
+ .then((json) => {
148
+ mergeNewRootState({
149
+ [key]: json,
158
150
  });
159
- }
151
+ httpReqsData[key] = true;
152
+ })
153
+ .catch((err) => {
154
+ console.error("error fetching dynamic data", url, err);
155
+ })
156
+ .finally(() => {
157
+ httpReqsPending[key] = false;
158
+ });
160
159
  });
161
160
  }
162
161
  function emitStateUpdate() {
@@ -228,6 +227,7 @@ function elementRef_onInitpreviewingbldr(event) {
228
227
  let elementRef;
229
228
  let ContentWrapper = contentWrapper || "div";
230
229
  let httpReqsData = {};
230
+ let httpReqsPending = {};
231
231
  let clicked = false;
232
232
  onMount(() => {
233
233
  if (isBrowser()) {
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "1.0.16";
1
+ export declare const SDK_VERSION = "1.0.17";
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.16";
1
+ export const SDK_VERSION = "1.0.17";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "1.0.16",
4
+ "version": "1.0.17",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "lib",
@@ -154,47 +154,45 @@
154
154
  clicked = true;
155
155
  }
156
156
  }
157
- function evalExpression(expression: string) {
158
- return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
159
- String(
160
- evaluate({
161
- code: group,
162
- context: context || {},
163
- localState: undefined,
164
- rootState: $builderContextSignal.rootState,
165
- rootSetState: $builderContextSignal.rootSetState,
166
- enableCache: true,
167
- })
168
- )
169
- );
170
- }
171
- function handleRequest({ url, key }: { key: string; url: string }) {
172
- fetch(url)
173
- .then((response) => response.json())
174
- .then((json) => {
175
- const newState = {
176
- ...$builderContextSignal.rootState,
177
- [key]: json,
178
- };
179
- $builderContextSignal.rootSetState?.(newState);
180
- httpReqsData[key] = true;
181
- })
182
- .catch((err) => {
183
- console.error("error fetching dynamic data", url, err);
184
- });
185
- }
186
157
  function runHttpRequests() {
187
158
  const requests: {
188
159
  [key: string]: string;
189
160
  } = $builderContextSignal.content?.data?.httpRequests ?? {};
190
161
  Object.entries(requests).forEach(([key, url]) => {
191
- if (url && (!httpReqsData[key] || isEditing())) {
192
- const evaluatedUrl = evalExpression(url);
193
- handleRequest({
194
- url: evaluatedUrl,
195
- key,
162
+ if (!url) return;
163
+
164
+ // request already in progress
165
+ if (httpReqsPending[key]) return;
166
+
167
+ // request already completed, and not in edit mode
168
+ if (httpReqsData[key] && !isEditing()) return;
169
+ httpReqsPending[key] = true;
170
+ const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) =>
171
+ String(
172
+ evaluate({
173
+ code: group,
174
+ context: context || {},
175
+ localState: undefined,
176
+ rootState: $builderContextSignal.rootState,
177
+ rootSetState: $builderContextSignal.rootSetState,
178
+ enableCache: true,
179
+ })
180
+ )
181
+ );
182
+ fetch(evaluatedUrl)
183
+ .then((response) => response.json())
184
+ .then((json) => {
185
+ mergeNewRootState({
186
+ [key]: json,
187
+ });
188
+ httpReqsData[key] = true;
189
+ })
190
+ .catch((err) => {
191
+ console.error("error fetching dynamic data", url, err);
192
+ })
193
+ .finally(() => {
194
+ httpReqsPending[key] = false;
196
195
  });
197
- }
198
196
  });
199
197
  }
200
198
  function emitStateUpdate() {
@@ -284,6 +282,7 @@
284
282
 
285
283
  let ContentWrapper = contentWrapper || "div";
286
284
  let httpReqsData = {};
285
+ let httpReqsPending = {};
287
286
  let clicked = false;
288
287
 
289
288
  onMount(() => {
@@ -1 +1 @@
1
- export const SDK_VERSION = "1.0.16"
1
+ export const SDK_VERSION = "1.0.17"