Polymer / pwa-helpers

Small helper methods or mixins to help you build web apps.
BSD 3-Clause "New" or "Revised" License
439 stars 48 forks source link

Adds support for Context #64

Closed srikrsna closed 2 years ago

srikrsna commented 5 years ago

I was just curious if this would make for a good helper. With context you can inject arbitrary values in the dom tree.

This can also be used to inject the redux store with the added ability to mock the store rather than use a global.

I use it for passing in loggers's, user's authentication details and other things that are present across the entire app. This is essentially dependency injection for web components.

I haven't added any tests yet but tested out manually with an example and this is working.

jamesfulford commented 4 years ago

I've found that associating DI directly with the DOM works great for view-layer code. However, the moment you want to inject dependencies into data-layer code (like injecting an http-client into a Redux thunk), the DOM method usually suffers. This argument applies to React Context and its coupling with Virtual DOM, too. I credit Angular for thinking about DI for service code as well as components.

I've gone with variations of the globals approach, for what it's worth.