Skip to content

Instantly share code, notes, and snippets.

@nathanhammond
Created August 18, 2020 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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