Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(load): updated queue utils #12

Merged
merged 3 commits into from
Sep 26, 2024
Merged

fix(load): updated queue utils #12

merged 3 commits into from
Sep 26, 2024

Conversation

makhnatkin
Copy link
Contributor

No description provided.

@makhnatkin makhnatkin linked an issue Sep 17, 2024 that may be closed by this pull request
isQueueCreated?: boolean;

// Callback to handle queue creation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interface members should be annotated with JSDoc-styled comments as well /** */

if (isBrowser()) {
(window as Window)[key] = (window as Window)[key] || [];
return (window as Window)[key];
// Initialize the store if it does not exist or check that it is an array

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, this commenting style is too verbose. JSDoc is fine, but I don't think we really need to comment on every other statement.

window[QUEUES_SYMBOL] = {};
}
} else {
throw new Error('This functionality should be employed on the client-side.');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this error message is self-descriptive enough. The message should mention that it comes from a load queue. Maybe something along the lines of Cannot initialize QueueStore in a non-browser environment?

store.splice(index, 1);
}
};
} else {
// eslint-disable-next-line no-console
console.warn('Store is not provided to useController'); // Replace console.warn with a logging function if necessary

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say just throwing makes more sense here, maybe even removing the if (store) check altogether, since store cannot be nullable judging from the argument types

src/lib/index.ts Outdated

export {
AttrsParser,
createLoadQueue,
getQueueStore,
getScriptStore,
handleQueueCreated,
createHandleQueueCreated,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to export this? This seems like an internal handler.

}: CreateLoadQueueArgs<T>) => {
queueKey = SINGLE_QUEUE_SYMBOL,
isQueueCreated = getQueueStore(queueKey),
onQueueCreated = createHandleQueueCreated(queueKey),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say I like the fact we can pass in custom onQueueCreated, which would effectively break the whole system — the default handler does a very important job of tracking which queues were initialized. So my guess is we don't want to expose this option to the end user.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not want to associate the createLoadQueue with the window runtime, assuming that the queue logic could generally work with any data source (store). I suggested leaving the prop onQueueCreated.

However, I agree that createHandleQueueCreated function could not be exported.

Copy link

@brotheroftux brotheroftux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decision on whether or not to fix the nitpick mentioned is ultimately up to you. Everything else looks good.

/**
* The store where callbacks are saved.
*
* @type {ScriptStore<T>}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nitpick, but I'd say it makes very little sense to use JSDoc type annotations in presence of TypeScript.

@makhnatkin makhnatkin merged commit 3c56969 into master Sep 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the typing of the extension-load-queue
3 participants