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

overriden: add singleton class #186

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is part of React-Invenio-Forms
// Copyright (C) 2020 CERN.
// Copyright (C) 2020, 2023 CERN.
// Copyright (C) 2020 Northwestern University.
//
// React-Invenio-Forms is free software; you can redistribute it and/or modify it
@@ -8,3 +8,4 @@
export * from "./elements";
export * from "./forms";
export * from "./api";
export { overridableRegistry } from "./overridenSingleton";
30 changes: 30 additions & 0 deletions src/lib/overridenSingleton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This file is part of React-Invenio-Forms
// Copyright (C) 2023 CERN.
//
// React-Invenio-Forms is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

let components;

/**
* Singleton class to provide a global access point to the overriden components
*/
class OverridenSingleton {
constructor() {
if (!OverridenSingleton.instance) {
OverridenSingleton.instance = this;
}

return OverridenSingleton.instance;
}

getComponents() {
return components;
}

addComponents(newComponents) {
components = { ...components, ...newComponents };
}
}

export const overridableRegistry = new OverridenSingleton();