akiran / react-foundation-apps

Foundation Apps components built with React
http://webrafter.com/opensource/react-foundation-apps
MIT License
292 stars 46 forks source link

Alternative to use of ids for referring components #2

Closed akiran closed 9 years ago

akiran commented 9 years ago

When I asked for feedback in twitter , @gaearon mentioned that

I'm not in favor of using global ids for inter-app communication.

Opening this issue to discuss more about this.

akiran commented 9 years ago

Most of the components in Foundation for Apps are layered i.e components are originally hidden and they are revealed on a trigger. foundation-apps uses id's to refer components and pubsub pattern to trigger the components. This gives us the flexibility to place the target component at required location and trigger it from any where in the application by passing its id without having to pass the actual DOM reference. This method is handy especially if we have to trigger same component from multiple locations.

In some cases where there is only one trigger and if trigger and target component can be in same render method, id based referencing may not be a ideal solution.

To support both the use-cases, I can make changes in trigger and components to accept either target id or target jsx

<Trigger open="id-of-target-component">
  <a className='button'>Open</a>
</Trigger>
<Trigger open={<jsx of target component/>} >
  <a className='button'>Open</a>
</Trigger>

With these changes users can pass either id or jsx according to the use-case and their preference.

@gaearon what do you thing ?