1

I've just started looking into unstated and I've bumped into an issue for which I can't find an answer yet.

Suppose I have two containers:

  • ContainerA
  • ContainerB

What should I do if I wanted to either access ContainerB state in ContainerA or even call a method of ContainerB in ContainerA?

The only way I see so far is to call ContainerA method and pass ContainerB instance manually as a separate argument which seems extremely bad and repetitive given I may need to do the same in multiple places...

Vytautas Butkus
  • 5,365
  • 6
  • 30
  • 45
  • haven't worked on this, but by looking at their library, for your use case, shouldn't you subscribe container b in container a? or vice versa – Aseem Upadhyay Aug 01 '18 at 08:49
  • 1
    As far as I understand no - you can't even reference other containers inside the one that you are trying to do that. Subscription is used to hook container into some component – Vytautas Butkus Aug 01 '18 at 09:01

1 Answers1

0

Have a look at the unstated docs around dependency injection. That allows you to instantiate your containers before adding them to your provider. So you can wire together your containers any way you like. Seems legit?

const containerA = new ContainerA();
const containerB = new ContainerB({ containerA });

render(
  <Provider inject={[containerA, containerB]}>
    <App />
  </Provider>
);
Jed Richards
  • 12,244
  • 3
  • 24
  • 35