Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getActiveComparator = (
comparedRevisions: State['comparedRevisions'],
builds: State['builds'],
artifactConfig: State['artifactConfig']
): Comparator => {
return new Comparator({
artifactBudgets: artifactConfig.budgets,
builds: builds.filter(build => comparedRevisions.includes(build.getMetaValue('revision'))),
groups: artifactConfig.groups
});
};
export default function makeStore(initialState: Partial = {}): Store {
const store = createStore(reducer, {
activeArtifacts: {},
activeComparator: null,
artifactConfig: {},
builds: [],
colorScale: Object.keys(ColorScale)[0],
comparator: new Comparator({ builds: [] }),
comparedRevisions: [],
disabledArtifactsVisible: true,
fetchState: FetchState.NONE,
graphType: GraphType.AREA,
hideAttribution: false,
hoveredArtifacts: [],
name: 'Build Tracker',
snacks: [],
sizeKey: '',
...initialState
});
if (process.env.NODE_ENV !== 'production' && canUseDOM && !window.hasOwnProperty('redux')) {
Object.defineProperty(window, 'redux', {
writable: false,
value: store
});
.then((parentBuild: BT$Build) => {
const comparator = new BuildComparator({ builds: [parentBuild, build].filter(Boolean) });
return onBuildInserted ? onBuildInserted(comparator) : Promise.resolve();
})
.then(data => {
.then(parentBuildData => {
const parentBuild = new Build(parentBuildData.meta, parentBuildData.artifacts);
return {
comparator: new Comparator({
artifactBudgets: artifactConfig.budgets,
artifactFilters: artifactConfig.filters,
builds: [build, parentBuild],
groups: artifactConfig.groups
})
};
})
.then(context => {
export default function reducer(state: State, action: Actions): State {
switch (action.type) {
case 'ARTIFACT_SET_ACTIVE': {
const activeArtifacts = action.meta.reduce(
(memo, artifactName) => {
memo[artifactName] = action.payload;
return memo;
},
{ ...state.activeArtifacts }
);
return { ...state, activeArtifacts };
}
case 'BUILDS_SET': {
const builds = action.payload;
const comparator = new Comparator({ builds });
const currentKeys = Object.keys(state.activeArtifacts).some(key => comparator.artifactNames.includes(key));
const activeArtifacts = comparator.artifactNames.reduce((memo, artifactName) => {
memo[artifactName] = currentKeys ? !!state.activeArtifacts[artifactName] : true;
return memo;
}, {});
const newRevisions = comparator.builds.map(build => build.getMetaValue('revision'));
const activeComparator = state.comparedRevisions.every(rev => newRevisions.includes(rev))
? getActiveComparator(state.comparedRevisions, builds, state.artifactConfig)
: null;
const graphType = builds.length <= 10 ? GraphType.STACKED_BAR : state.graphType;
const sizeKey = comparator.sizeKeys.includes(state.sizeKey) ? state.sizeKey : comparator.sizeKeys[0];
return { ...state, activeComparator, activeArtifacts, builds, comparator, graphType, sizeKey };