Skip to content

Commit

Permalink
overriden: add singleton class
Browse files Browse the repository at this point in the history
* Singleton class meant to manage the
  global overriden components
* closes inveniosoftware/invenio-app-rdm#2018
  • Loading branch information
jrcastro2 committed Jan 20, 2023
1 parent 17bf9e9 commit 59adaa5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
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
Expand All @@ -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();

0 comments on commit 59adaa5

Please sign in to comment.