jhnns / rewire-webpack

Dependency injection for webpack bundles
The Unlicense
121 stars 20 forks source link

Problems getting started #21

Open essekia opened 8 years ago

essekia commented 8 years ago

Hi,

    var rewire = require('rewire-webpack');
    var testStore = rewire('stores/test-store');
    console.log("testStore: " +  !!testStore);

I have a feeling that I am missing something obvious, but shouldn't testStore return true? I get 'false'. And I cannot set or get anything as 'testStore' always seems to be undefined.

other info:

  1. no babel, no es6, just a simple test store (singleton).
  2. rewire is installed, and !!rewire.apply returns true. ( so I am guessing rewire is setup correctly.)
  3. using webpack.
  4. using "require" in place of rewire returns 'true'.
  5. I should also mention that I use AMD format for all my modules.
essekia commented 8 years ago

Never mind. As I suspected, it was something silly on my part.

essekia commented 8 years ago

Another query regarding matching view with the rewired store.

So here is my problem, I have a rewired 'flightStore' and a 'flightView' which has 'flightStore' as its dependency. How do I match the current rewired version of the flightStore in the flightView? Should I use rewire the view and use 'set' on it somehow to match the stores (or) the variables used in the view? Is there another simpler way to do this?

                var registeredCallback = flightStore.__get__("registeredCallback");

                registeredCallback({
                    actionType: 'choose-flight',
                    type: 'business-class'
                });

                ReactDOM.render(
                    React.createElement(flightView, {
                        className: parentID,
                        key: parentID
                    }),
                    document.getElementById(tempID)
                );

Thanks much!