Skip to content

Instantly share code, notes, and snippets.

@saulshanabrook
Last active April 2, 2020 15:45
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 saulshanabrook/0cb54933391eefe07da4b6983cd7a4e0 to your computer and use it in GitHub Desktop.
Save saulshanabrook/0cb54933391eefe07da4b6983cd7a4e0 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const newPreVersion = assign({
preVersion: () => 0
});
const bumpPreVersion = assign({
preVersion: context => context.preVersion + 1
});
const bumpVersion = assign({
version: context => context.version + 1
});
const addCommit = assign({
unreleasedCommits: context => context.unreleasedCommits + 1
});
const resetCommits = assign({
unreleasedCommits: context => 0
});
const commits = {
initial: 'clean',
states: {
clean: {
on: { COMMIT: { target: 'dirty', actions: 'addCommit' } }
},
dirty: {
on: { COMMIT: { target: 'dirty', actions: 'addCommit' } }
}
}
};
Machine({
id: 'release',
context: {
version: 1,
preVersion: 0,
unreleasedCommits: 0
},
initial: 'final',
states: {
final: {
on: {
ALPHA: { target: 'alpha', actions: ['newPreVersion', resetCommits] }
},
...commits
},
alpha: {
on: {
ALPHA: { target: 'alpha', actions: ['bumpPreVersion', resetCommits] },
RC: { target: 'rc', actions: ['newPreVersion', resetCommits] }
},
...commits
},
rc: {
on: {
RC: { target: 'rc', actions: ['bumpPreVersion', resetCommits] },
FINAL: { target: 'final', actions: ['bumpVersion', resetCommits] }
},
...commits
}
}
}, {
actions: {
newPreVersion,
bumpPreVersion,
bumpVersion,
addCommit,
resetCommits
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment