Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Treating Relay.Store as a global store (i.e. redux store)

Tags:

redux

relayjs

I'm refactoring (for fun, ha) my redux application to relay. In the redux application a failed event would dispatch an action with the failure message.

This would be picked up by an 'Alert' reducer that would then present an alert to the user. This would be kept in the global state for x seconds before being removed.

The Alert component would sit empty until there were alerts dispatched to fill it.

How would this be done under Relay? Is there a way to mutate only the Store rather than dispatching a GraphQL mutation?

Thanks for the help :)

like image 355
JBux Avatar asked Aug 20 '16 15:08

JBux


1 Answers

One option would be to have alert in your schema (you could even just include it in your local schema, though you'd probably have to change the way babelRelayPlugin gets its schema) and use applyUpdate to change it. I have never tried that, nor do I think it's what the devs had in mind for it, but it might just work.

In its current version Relay isn't really made for local state, but apparently it's on the roadmap for Relay 2.

like image 74
Gregor Weber Avatar answered Sep 28 '22 06:09

Gregor Weber