This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Machine, State, actions, assign, send, sendParent, interpret, spawn} from 'xstate'; | |
const example1Machine = Machine( | |
{ | |
id: 'mainRegion', | |
initial: 'green', | |
states: { | |
green: { | |
type: 'atomic', | |
id: 'greenState', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Machine, State, actions, assign, send, sendParent, interpret, spawn, EventObject} from 'xstate'; | |
export const wizardMachine = Machine( | |
{ | |
id: 'mainregion', | |
context: { | |
one: null, | |
two: null, | |
three: null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { resetStatus, getStatus, getNotStatus} from "./utils"; | |
import { Machine, State, actions, assign, send, sendParent, interpret, spawn, EventObject} from 'xstate'; | |
export const wizardMachine = Machine( | |
{ | |
id: 'wizard', | |
context: { | |
one: null, | |
two: null, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Add another import */ | |
import { resetStatus, getStatus, getNotStatus} from "./utils"; | |
/** [...] */ | |
/** Add functionality for the called operations */ | |
actions: { | |
assignOne: | |
assign({ one: function (context : any, event : EventObject) { return event.value; } }), | |
assignTwo: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Class for defining callbacks for statechart out-events | |
class Callback: | |
statechart = None | |
oven = None | |
def __init__(self, statechart, oven): | |
self.statechart = statechart | |
self.oven = oven | |
def heat_on(self): | |
self.oven.heatOn() | |
def heat_off(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set statechart observer for out-events | |
class Reached_Temperature_Observer( Observer ): | |
def __init__(self, aws): | |
self.aws = aws | |
def next(self, value=None): | |
if self.aws is not None: | |
self.aws.publish("reachedTemperature", None) | |
else: | |
print("Could not publish '" + "reachedTemperature" + "' because not connection was established.") | |
self.statechart.ready_observable.subscribe( Reached_Temperature_Observer(self.aws) ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
class Oven: | |
def __init__(self): | |
self.temperature = 0 | |
self.heating = False | |
def heatOn(self): | |
self.heating = True | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def customCallback(self, client, userdata, message): | |
dictionary = json.loads(message.payload) | |
if dictionary["event"] and dictionary["value"]: | |
if dictionary["event"] == "setTargetTemperature": | |
value = float(dictionary["value"]) | |
self.raise_set_target_temp(value, False) | |
print('Received: "' + str(json.loads(message.payload)) + '" from topic "' + "'" + (message.topic) + "'") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createMachine, Machine, State, actions, assign, send, sendParent, interpret, spawn, EventObject, DoneInvokeEvent} from 'xstate'; | |
import { Subject } from 'rxjs'; | |
const {choose} = actions; | |
export class StatechartContext { | |
operationCallback : OperationCallback; | |
constructor(operationCallback : OperationCallback = new class{ | |
assignBeneficiaryInfoToContext(): void {throw "Method 'assignBeneficiaryInfoToContext' does not have an implementation in DefaultOperationCallback."}; | |
assignDateToContext(): void {throw "Method 'assignDateToContext' does not have an implementation in DefaultOperationCallback."}; |