#Calling an invoke or transitioning on every new day

1 messages ยท Page 1 of 1 (latest)

queen totem
#

Hi ๐Ÿ™ , I feel like I'm the noobest newbie.

I have a machine that I overly simplified here: https://codesandbox.io/s/suspicious-fast-49rcps?file=/src/index.ts

I need to have something that ends up calling that invoke you see in the example every new day right after midnight. I'll be using date-fns to catch the new day, and I'm guessing a setInterval every few seconds will do the rest but... how do I model it in XState? Do I need some sort of long-running... thing that exists and works for the entire lifespan of my application no matter what state the machine is in?

I tried my luck with the search engine here on Discord but didn't find anything (probably because I'm too much of a noob even for choosing the right search terms).

high flax
queen totem
#

Oooh interesting! Thanks @high flax !

Do you think this would be a way to integrate it in my original example? https://stately.ai/viz/97744b56-ea89-40a1-b5f9-c8ed6432f51e
I don't think it's working, yet, but it should explain my use case a bit better. Any pointers about why it doesn't seem to be working e.g. if I click on one of the events?

high flax
#

How does getStatus work in your real app? Does it have to be a callback invocation?

queen totem
#

Well, it's a synchronous operation, so I thought a callback would be the right thing vs a Promise

high flax
queen totem
#

I can't find a way to both come back to #dataPolling.waiting and go to #application.foo (or bar) ๐Ÿ˜ฌ

high flax
queen totem
#

๐Ÿค” didn't know I could do that!

if I do this, though:

      application: {
        id: "application",
        initial: "unknown",
        on: {
          NEW_STATUS: [
            {
              target: "foo",
              cond: "canGoToFoo",
            },
            { target: "bar" },
          ],
        },
        states: {
          unknown: {},
          foo: {},
          bar: {},
        },
      },
    },

I get a Invalid transition definition for state node 'application': Child state 'foo' does not exist on '(machine)' error notification

#

oooh the . thing!

#

I think it works now!

high flax
#

Can you add this to your machine in the visualizer please?

#

Glad you figured it out ๐Ÿ™‚

queen totem
#

Thank you so much! ๐Ÿ™‡โ€โ™‚๏ธ I can't wait to put it to work in the real thing tonight!