Skip to content

Commit

Permalink
feat: Remove useless queue (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
wheeyls authored Mar 18, 2024
1 parent 048502a commit e9ef281
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 102 deletions.
31 changes: 16 additions & 15 deletions src/initWidgets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import queue from './queue';
import { extractOptions } from '@g2crowd/extract-options';
import camelize from './camelize';
import { strategies } from './strategies';
Expand Down Expand Up @@ -62,30 +61,32 @@ const wrapPlugin = function wrapPlugin(name, pluginFn, element) {
};
};

const loadWidget = function (element, name, widgetQueue, registered, initiatedWidgets) {
const pluginFn = registered[name];
async function startWidget(name, pluginFn, element) {
const wrapped = wrapPlugin(name, pluginFn, element);
const strategy = strategies.get(pluginFn.init);

strategy(wrapped, element);
}

const loadWidget = async function (element, name, availableWidgets, initiatedWidgets) {
const pluginFn = availableWidgets[name];

if (!pluginFn) {
return;
}

const existingPlugin = initiatedWidgets.get(name, element);
const wrapped = wrapPlugin(name, pluginFn, element);
if (initiatedWidgets.get(name, element)) {
return;
}

if (!existingPlugin) {
widgetQueue.add(() => {
strategies.get(pluginFn.init)(wrapped, element);
});
widgetQueue.flush();
startWidget(name, pluginFn, element);

initiatedWidgets.set(name, element, true);
element.dataset[`vvidget_${camelize(name)}`] = true;
}
initiatedWidgets.set(name, element, true);
element.dataset[`vvidget_${camelize(name)}`] = true;
};

const initiatedWidgets = widgetTracker();
export const widgetInitiator = function ({ attr, data, registered }, fn = loadWidget) {
const widgetQueue = queue();
registered = registered || {};

return function initWidgets(elements) {
Expand All @@ -95,7 +96,7 @@ export const widgetInitiator = function ({ attr, data, registered }, fn = loadWi
names
.split(' ')
.filter((i) => i)
.forEach((name) => fn(element, name, widgetQueue, registered, initiatedWidgets));
.forEach((name) => fn(element, name, registered, initiatedWidgets));
});
};
};
37 changes: 0 additions & 37 deletions src/queue.js

This file was deleted.

50 changes: 0 additions & 50 deletions test/queue.test.js

This file was deleted.

0 comments on commit e9ef281

Please sign in to comment.