Skip to content

Commit 66cac0c

Browse files
committed
wip
1 parent 56f10f3 commit 66cac0c

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

addons/html_builder/static/src/website_builder/plugins/website_theme_config_plugin.js

+38-23
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class WebsiteThemeConfigPlugin extends Plugin {
88

99
cache = {};
1010
activeViews = {};
11+
pendingRequests = new Set();
12+
resolves = {};
1113

1214
resources = {
1315
builder_actions: {
@@ -26,6 +28,42 @@ class WebsiteThemeConfigPlugin extends Plugin {
2628
},
2729
};
2830

31+
loadConfigKey(keys) {
32+
if (!Array.isArray(keys)) {
33+
keys = [keys];
34+
}
35+
for (const key of keys) {
36+
if (!(key in this.cache)) {
37+
this.cache[key] = this._loadBatchKey(key);
38+
}
39+
}
40+
return Promise.all(keys.map((key) => this.cache[key]));
41+
}
42+
43+
_loadBatchKey(key) {
44+
this.pendingRequests.add(key);
45+
return new Promise((resolve) => {
46+
this.resolves[key] = resolve;
47+
setTimeout(() => {
48+
if (this.pendingRequests.size && !this.isDestroyed) {
49+
const keys = [...this.pendingRequests];
50+
this.pendingRequests.clear();
51+
rpc("/website/theme_customize_data_get", {
52+
keys,
53+
is_view_data: true,
54+
}).then((r) => {
55+
if (!this.isDestroyed) {
56+
for (const key of keys) {
57+
this.activeViews[key] = r.includes(key);
58+
this.resolves[key]();
59+
}
60+
}
61+
});
62+
}
63+
}, 0);
64+
});
65+
}
66+
2967
async toggleConfig(action, apply) {
3068
if (this.dependencies.history.getIsPreviewing()) {
3169
// ignore previews!
@@ -78,29 +116,6 @@ class WebsiteThemeConfigPlugin extends Plugin {
78116
this.dispatchTo("reload_editor", { target });
79117
}
80118

81-
async loadConfigKey(keys) {
82-
if (!Array.isArray(keys)) {
83-
keys = [keys];
84-
}
85-
for (const key of keys) {
86-
if (!(key in this.cache)) {
87-
this.cache[key] = rpc("/website/theme_customize_data_get", {
88-
keys: [key],
89-
is_view_data: true,
90-
}).then((r) => {
91-
this.activeViews[key] = r.includes(key);
92-
});
93-
}
94-
}
95-
const proms = keys.map((key) => this.cache[key]);
96-
await Promise.all(proms);
97-
const result = {};
98-
for (const key of keys) {
99-
result[key] = this.activeViews[key];
100-
}
101-
return result;
102-
}
103-
104119
getConfigKey(key) {
105120
return this.activeViews[key];
106121
}

0 commit comments

Comments
 (0)