-
Notifications
You must be signed in to change notification settings - Fork 642
An extension of #109 for stopping cycles #129
Conversation
This diff looks kind of strange because I had to switch the order of |
@jlongster Nice — I think we're onto something here. It's getting late in Norway so I'll take this for a spin tomorrow when I'm more awake ;) |
Cool! No rush, I probably won't be too active this weekend. Also I left |
Hey @kjbekkelund, do you think you'll be able to check this out in the next few days? I'd like to clean this up before I go off on holiday, but I don't want to invest too much in this if you see any problems. Not a big deal if you don't have time. |
I thought it could be related to async. With a small change I get the test running: - it('handles toggle after store change', () => {
+ it.only('handles toggle after history change', (done) => {
let currentPath
+ let finished = false
const historyUnsubscribe = history.listen(location => {
currentPath = location.pathname
+
+ if (finished) {
+ expect(currentPath).toEqual('/foo2')
+ historyUnsubscribe()
+ done()
+ }
})
// DevTools action #2
history.pushState(null, '/foo2')
// DevTools action #3
history.pushState(null, '/foo3')
// When we toggle an action, the devtools will revert the action
// and we therefore expect the history to update to the previous path
+ finished = true;
devToolsStore.dispatch(ActionCreators.toggleAction(3))
- expect(currentPath).toEqual('/foo2')
-
- historyUnsubscribe()
}) but for some strange reason it fails when run without If you add a I've tested the branch in my app, and as far as I can see everything works as expected (however, I don't rely on I think this is an interesting approach and something we should clean up and try to get into master. Could you also bring in the additional tests in #109, so we're sure to cover that case? |
Thanks for taking a look. I will port over the tests from your PR. I've never heard of |
I'm not a Redux expert, but I feel like you'd be better off using a simpler middleware-based approach. The idea is, you stamp the action with a bit indicating whether or not the action came from the Router (v. being manually initiated).
Anything coming through the router will hit (2). Anything coming from a user will hit (1), get dropped, then hit (2) via the I think this would get rid of most of your stateful book-keeping. |
Closing in favor of #141 |
@kjbekkelund This is somewhat similar to #109 but takes the idea even farther. We can remove
avoidRouterUpdate
andchangeId
completely with this. It uses a local variable to tell the store listener not to update the router, but also uses a reference identity check of the router state for the store listener to know when to update the router.Most tests pass; the only failing ones are with the devtools. The test about toggling routing actions fails, even though it works for me in the basic example. I can toggle route actions and it updates the router just fine.
What do you think?