samiskin / redux-electron-store

⎋ A redux store enhancer that allows automatic synchronization between electron processes
MIT License
375 stars 32 forks source link

Possible race condition ? #47

Open magne4000 opened 7 years ago

magne4000 commented 7 years ago

As far as I understand how this works, each renderer is responsible for generating its own state diff and send it to main.

Now an example: Here is the main store

store = {
  items: {
  }
}

Now let's assume that we have 2 renderers that are concurrently generating the following states: Renderer 1

store = {
  items: {
    item1: 'renderer1'
  }
}

Renderer 2

store = {
  items: {
    item1: 'renderer2'
  }
}

At the same time, they will send a diff to main that could look like this (jsdiff notation): Renderer 1

{ "op": "add", "path": "/items", "value": { "item1": "renderer1" } }

Renderer 2

{ "op": "add", "path": "/items", "value": { "item1": "renderer2" } }

In this case, main will successfully apply the first one it receives, but the second one will fail (because of the item1 key).

Did I misunderstood something, or could this really happen ?

magne4000 commented 7 years ago

Answered my own question I think. I saw your comment on #28, and the main does not receive a diff but an action, which then generates the diff

magne4000 commented 7 years ago

Actually my point is still valid because of what you said here