How to use the stable function in stable

To help you get started, we’ve selected a few stable 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 chanzuckerberg / czi-prosemirror / src / patchStyleElements.js View on Github external
if (selectorText.indexOf(',') > -1) {
        selectorText.split(/\s*,\s*/).forEach(st => {
          buildSelectorTextToCSSText(selectorTextToCSSTexts, st, cssText);
        });
      } else {
        buildSelectorTextToCSSText(
          selectorTextToCSSTexts,
          selectorText,
          cssText
        );
      }
    });
  });

  // Sort selector by
  stable(selectorTextToCSSTexts, sortBySpecificity)
    .reduce(buildElementToCSSTexts.bind(null, doc), new Map())
    .forEach(applyInlineStyleSheetCSSTexts);
}
github Opentrons / opentrons / discovery-client / src / service-list.js View on Github external
result.seenIps[ip] = true
      result.unique.push(cleanedService)

      return result
    },
    { unique: [], seenIps: {} }
  ).unique

  const dedupedWithoutIp = differenceBy(
    uniqBy(listWithoutIp, 'name'),
    sanitizedWithIp,
    'name'
  )

  // use a stable sort because core-js polyfills can mess with Array.sort order
  return stableSort(sanitizedWithIp.concat(dedupedWithoutIp), compareServices)
}
github mitmproxy / mitmproxy / web / src / js / ducks / utils / store.js View on Github external
export default function reduce(state = defaultState, action) {

    let { byId, list, listIndex, view, viewIndex } = state

    switch (action.type) {
        case SET_FILTER:
            view = stable(list.filter(action.filter), action.sort)
            viewIndex = {}
            view.forEach((item, index) => {
                viewIndex[item.id] = index
            })
            break

        case SET_SORT:
            view = stable([...view], action.sort)
            viewIndex = {}
            view.forEach((item, index) => {
                viewIndex[item.id] = index
            })
            break

        case ADD:
            if (action.item.id in byId) {
                // we already had that.
                break
            }
            byId = { ...byId, [action.item.id]: action.item }
            listIndex = { ...listIndex, [action.item.id]: list.length }
            list = [...list, action.item]
            if (action.filter(action.item)) {
                ({ view, viewIndex } = sortedInsert(state, action.item, action.sort))
github pbeshai / react-taco-table / src / Utils.js View on Github external
const dataToSort = data.map((rowData, index) => ({
    rowData,
    index,
    sortValue: getSortValue(column, rowData, index, data, columns),
  }));

  // check if already sorted, and if so, just reverse
  let sortedData;

  // if already sorted in the opposite order, just reverse it
  if (alreadySorted(!sortDirection, dataToSort, comparator)) {
    sortedData = dataToSort.reverse();

  // if not sorted, stable sort it
  } else {
    sortedData = stable(dataToSort, comparator);
    if (sortDirection === SortDirection.Descending) {
      sortedData.reverse();
    }
  }

  sortedData = sortedData.map(sortItem => sortItem.rowData);

  return sortedData;
}
github mitmproxy / mitmproxy / web / src / js / ducks / utils / store.js View on Github external
export default function reduce(state = defaultState, action) {

    let { byId, list, listIndex, view, viewIndex } = state

    switch (action.type) {
        case SET_FILTER:
            view = stable(list.filter(action.filter), action.sort)
            viewIndex = {}
            view.forEach((item, index) => {
                viewIndex[item.id] = index
            })
            break

        case SET_SORT:
            view = stable([...view], action.sort)
            viewIndex = {}
            view.forEach((item, index) => {
                viewIndex[item.id] = index
            })
            break

        case ADD:
            if (action.item.id in byId) {
github conartist6 / sequins / src / factories / sort.js View on Github external
return function sort(inPlace, iterable, selector, comparator = defaultComparator) {
    let array = ensureArray(iterable);

    const wrappedComparator = selector
      ? (a, b) => comparator(selector(itemValue(a)), selector(itemValue(b)))
      : (a, b) => comparator(itemValue(a), itemValue(b));

    if (inPlace) {
      stable.inplace(array, wrappedComparator);
    } else {
      array = stable(array, wrappedComparator);
    }

    if (collectionType === 'Sequence' || collectionSubtype === 'Indexed') {
      return array;
    }
    return new NativeConstructor(array);
  };
}
github wjohnsto / simple-site / server / routes / bloglist.ts View on Github external
const frontMatter = fm(contents);
            const attributes = frontMatter.attributes;
            const body = frontMatter.body;
            const slug = file.replace('.md', '');

            attributes.body = body;
            attributes.url = `${baseUrl}/blog/${slug}/`;
            attributes.fullImage = `${baseUrl}${attributes.image}`;
            attributes.slug = slug;
            attributes.created = new Date(attributes.created);
            attributes.readTime = utils.readTime(body);

            return { file: filePath, attributes };
        });

        const sortedFiles: IFileObject[] = sort(
            _(newFiles)
                .filter(_.isObject)
                .value(),
            (a: IFileObject, b: IFileObject) => {
                return a.attributes.created <= b.attributes.created;
            }
        );

        const filteredFiles = _(sortedFiles)
            .filter((file) => {
                return file.attributes.published !== false;
            })
            .value();

        if (config.ENV.prod) {
            cache.store('blog-files', blogFiles);

stable

A stable array sort for JavaScript

MIT
Latest version published 6 years ago

Package Health Score

55 / 100
Full package analysis