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

Remove the global requirement of this module #3

Open
ScopeyNZ opened this issue Apr 1, 2019 · 0 comments
Open

Remove the global requirement of this module #3

ScopeyNZ opened this issue Apr 1, 2019 · 0 comments

Comments

@ScopeyNZ
Copy link
Contributor

ScopeyNZ commented Apr 1, 2019

Currently this module requires consuming packages to add something like this to their webpack config:

	// ...
    entry: {
      bundle: `${PATHS.SRC}/bundles/bundle.js`,
      injector: `${PATHS.MODULES}/@silverstripe/react-injector/dist/injector.js`,
    },
    externals: {
      'lib/Injector': 'Injector',
    },
	// ...

Only one consumer needs to define the entry and actually include the stand-alone injector.js file. The others have to include the externals config and just hope the API is there in globals.

This can potentially be improved by defining a global store in the module. This could look like this:

// configure Injector before use
Injector.configure({
  store: () => window.ss.injector; // Default = window.injectorStore (?)
});
// Use of injector with multiple stores
Injector.component.register('MyComponent', MyComponent, { store: window.vendorInjectorStore });

This would allow use as a more standard NPM module, no externals config required. Duplication of the injector code in different bundles would be acceptable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant