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

Implement factory method for new instance creation in CustomJS #78

Merged
merged 1 commit into from
Dec 29, 2023

Conversation

PxaMMaxP
Copy link
Contributor

Resolves #77 - Enhance instance creation flexibility in CustomJS

This pull request addresses the issue raised in #77, where the CustomJS plugin was limited to creating and providing only a singleton instance of each class. The proposed change allows for greater flexibility by enabling the creation of new instances on demand.

Changes made:

  • Retained the existing behavior of storing the singleton instance in window.customJS.
  • Introduced a new factory method, createClassNameInstance, to allow users to create new instances as needed.

With this update, users can continue to access the singleton instance for shared state scenarios or opt to create separate instances for isolated state management. This enhancement maintains backward compatibility while providing additional functionality.

Please review the changes and let me know if there are any concerns or additional modifications needed.

This commit introduces a new factory method to the CustomJS evalFile function, allowing the creation of new instances of dynamically imported classes. This change enables users to instantiate new objects as needed, instead of relying solely on a single, shared instance. The method `createClassNameInstance` has been added to the `window.customJS` object, which returns a new instance of the specified class each time it is called.
@saml-dev
Copy link
Owner

Good idea, thanks

@saml-dev saml-dev merged commit aa1cee7 into saml-dev:master Dec 29, 2023
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.

Enhancement: Support for Both Singleton and New Instances in CustomJS Plugin
2 participants