Skip to content

Instantly share code, notes, and snippets.

@nathanhammond
Created August 18, 2020 10:22
Show Gist options
  • Save nathanhammond/f6dcf4f3ef92ccec7e0d48ecf335e099 to your computer and use it in GitHub Desktop.
Save nathanhammond/f6dcf4f3ef92ccec7e0d48ecf335e099 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
var windowId = 0;
function windowManager() {
return Machine({
id: 'window-manager',
initial: 'idle',
type: 'parallel',
states: {
idle: {
on: {
'OPEN': {
target: 'opening',
},
'CLOSE': {
target: 'closing'
},
'FOCUS': {
target: 'focusing'
}
}
},
opening: {
invoke: [
{
// id: () => { return `${windowId++}` },
id: windowId,
src: windowMachine(windowId)
}
],
on: {
'COMPLETE': {
target: 'idle'
}
}
},
closing: {
on: {
'COMPLETE': {
target: 'idle'
}
}
},
focusing: {
on: {
'COMPLETE': {
target: 'idle'
}
}
}
}
});
}
function windowMachine(name) {
return Machine({
id: `window-${name}`,
initial: 'loading',
states: {
loading: {},
unloading: {},
foregrounding: {},
backgrounding: {},
foreground: {},
background: {}
}
});
};
windowManager();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment