How to use the @build-tracker/comparator function in @build-tracker/comparator

To help you get started, we’ve selected a few @build-tracker/comparator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github paularmstrong / build-tracker / src / app / src / store / reducer.ts View on Github external
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
  });
};
github paularmstrong / build-tracker / src / app / src / store / index.ts View on Github external
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
    });
github paularmstrong / build-tracker / packages / server / src / api / builds.js View on Github external
.then((parentBuild: BT$Build) => {
      const comparator = new BuildComparator({ builds: [parentBuild, build].filter(Boolean) });
      return onBuildInserted ? onBuildInserted(comparator) : Promise.resolve();
    })
    .then(data => {
github paularmstrong / build-tracker / src / server / src / api / insert.ts View on Github external
.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 => {
github paularmstrong / build-tracker / src / app / src / store / reducer.ts View on Github external
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 };