#How to either guard or conditionally act on another actor's state?

1 messages · Page 1 of 1 (latest)

slow lion
#

Let's take the todo app idea.
I have a few machines.
AuthMachine, TodosMachine, TodoMachine

Like in the examples, TodosMachine keeps the array of Todos where TodoMachine is around the display/editing of a single Todo.

Let's also say that we have a drag/drop/sortable state for display. We will call it SortableMachine.

Finally, Todos might get a push update from the server. So in TodosMachine there is a subscription that might update the Todos list.

Here is where I get confused.

  1. We only want to subscribe to updates on server when AuthMachine is in the "logged in" state.
  2. When dragging or modifying a todo, we want to batch the server updates. We don't want to drop them, but only apply them after the drag event.

I'll pause there, as there is complexity in event conflicts (server and client both make changes to a todo) That seems like a smaller aspect state machine in resolving that though.

My big question is - how do I get data from one machine from another? I want to only subscribe to server todo updates when auth is logged in. want to add a change stack, but only take actions on that stack when todos are not being modified.

stable geode
#

When the Auth is in a logged in state, it can notify Todos by sending it an event, so that Todos can transition to a state where it is subscribing to server updates

#

In a dragging state, you can "defer" those events by assigning them somewhere in context, and replaying when dragging is done

#

Deferring can look like this: (pseudocode)

dragging: {
  on: {
    'todos.update': {
      actions: assign({ deferredEvents: ({ event }) => /* concat */ })
    }
  }
}