I have an object instance that's used by several different modules in my code. The instance itself gets edited during different events, then the modules use it to redraw the page.
For example:
// index.js
import populateProjects from 'populateProjects.js'
import populateItems from 'populateItems.js'
let projects = new projectList() // Projects in index.js's scope
projects.addProject('Project 1')
projects.getProject(0).addItem('Item 1')
// Note how I need to pass the 'projects' into the modules below
populateProjects(projects)
populateItems(projects)
//I would prefer both modules to have access to the same instance of 'projects' so that I don't need to pass it into them:
populateProjects() //'projects' is imported in the modules
populateItems() //regardless of where they're called
Right now, I keep passing it into the module functions when they're called, but that means that I need to always have it in the scope of the script that's calling the module. I can get around this by using global variables but I'd rather not pollute the namespace for other modules that don't rely on it.
Is there a way that I can make this instance accessible in the specific modules that need it and still have it editable? Maybe using import?