added gitgraph in imperative state

This commit is contained in:
Austin Fulbright 2024-08-20 14:53:01 -04:00
parent 8ef30a2642
commit 24ba5b73da

View File

@ -45,11 +45,13 @@ const getConfig = (): Required<GitGraphDiagramConfig> => {
}); });
return config; return config;
}; };
const state = new ImperativeState<GitGraphState>(() => {
const config = getConfig(); const config = getConfig();
const mainBranchName = config.mainBranchName; const mainBranchName = config.mainBranchName;
const mainBranchOrder = config.mainBranchOrder; const mainBranchOrder = config.mainBranchOrder;
return {
const state = new ImperativeState<GitGraphState>(() => ({ mainBranchName,
commits: new Map(), commits: new Map(),
head: null, head: null,
branchConfig: new Map([[mainBranchName, { name: mainBranchName, order: mainBranchOrder }]]), branchConfig: new Map([[mainBranchName, { name: mainBranchName, order: mainBranchOrder }]]),
@ -58,7 +60,8 @@ const state = new ImperativeState<GitGraphState>(() => ({
direction: 'LR', direction: 'LR',
seq: 0, seq: 0,
options: {}, options: {},
})); };
});
function getID() { function getID() {
return random({ length: 7 }); return random({ length: 7 });
@ -121,7 +124,7 @@ export const commit = function (commitDB: CommitDB) {
branch: state.records.currBranch, branch: state.records.currBranch,
}; };
state.records.head = newCommit; state.records.head = newCommit;
log.info('main branch', mainBranchName); log.info('main branch', config.mainBranchName);
state.records.commits.set(newCommit.id, newCommit); state.records.commits.set(newCommit.id, newCommit);
state.records.branches.set(state.records.currBranch, newCommit.id); state.records.branches.set(state.records.currBranch, newCommit.id);
log.debug('in pushCommit ' + newCommit.id); log.debug('in pushCommit ' + newCommit.id);