Update context with assign from a activity #1278
-
Is it possible to update the context of the machine from a activity. Like a activity that updates the context with the current time, once a second. When using the assign function inside the activity, it does not update context. I think assign only works in a action context right? {
activities: {
timeIncrement: (context, activity) => {
// Start the beeping activity
const timeInterval = setInterval(
() =>
assign({
time: () => new Date(),
}),
1000
);
// Return a function that stops the beeping activity
return () => clearInterval(timeInterval);
},
},
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Yes, assign is an action creator - it just returns an object describing what should happen when interpreter sees it. You cant just update the context at arbitrary times like you would like to. Statecharts prefer modelling explicit behaviors and logic so u need to wire this with a parent using events communication. |
Beta Was this translation helpful? Give feedback.
-
Ok, I get that. And is there a way to send a event from an activity without
access to the interperted machine?
Op vr 3 jul. 2020 om 17:18 schreef Mateusz Burzyński <
notifications@github.com>
… Yes, assign is an action creator - it just returns an object describing
what should happen when interpreter sees it. You cant just update the
context at arbitrary times like you would like to. Statecharts prefer
modelling explicit behaviors and logic so u need to wire this with a parent
using events communication.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1278 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACMAFWVIO6EKYNSIHGI73WDRZXZEFANCNFSM4OPYTB2A>
.
|
Beta Was this translation helpful? Give feedback.
Yes, assign is an action creator - it just returns an object describing what should happen when interpreter sees it. You cant just update the context at arbitrary times like you would like to. Statecharts prefer modelling explicit behaviors and logic so u need to wire this with a parent using events communication.