dataloader-sort
DataLoader Sort
Last updated 3 years ago by andrewreedy .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install dataloader-sort 
SYNC missed versions from official npm registry.

DataLoader Sort npm version Build Status Coverage Status

Sort function for DataLoader to ensure the correct data is returned for the matching keys

Installation

npm i -S dataloader-sort

Notes

  • If no match is found it will return null for this key
  • Includes Flow types

Usage

Basic Usage

import sort from 'dataloader-sort';

const keys = [1, 2, 3];
const data = [
  { id: 3, value: 'three' },
  { id: 1, value: 'one' },
  { id: 4, value: 'four' },
];

const result = sort(keys, data);
Output
[
  { id: 1, value: 'one' },
  null,
  { id: 3, value: 'three' },
]

Custom Prop Usage

const keys = [1, 2, 3];
const data = [
  { other: 3, value: 'three' },
  { other: 1, value: 'one' },
  { other: 2, value: 'two' },
];

const result = sort(keys, data, 'other');
Output
[
  { other: 1, value: 'one' },
  { other: 2, value: 'two' },
  { other: 3, value: 'three' },
]

Object Keys Usage

const keys = [
  { userId: 1, messageId: 3 },
  { userId: 2, messageId: 4 },
  { userId: 3, messageId: 9 },
  { userId: 3, messageId: 7 },
  { userId: 1, messageId: 2 },
];
const data = [
  { userId: 1, messageId: 2, value: 'yayy' },
  { userId: 3, messageId: 7, value: 'ya' },
  { userId: 1, messageId: 3, value: 'woot' },
  { userId: 2, messageId: 4, value: 'blue' },
  { userId: 3, messageId: 9, value: 'green' },
];

const result = sort(keys, data);
Output
[
  { userId: 1, messageId: 3, value: 'woot' },
  { userId: 2, messageId: 4, value: 'blue' },
  { userId: 3, messageId: 9, value: 'green' },
  { userId: 3, messageId: 7, value: 'ya' },
  { userId: 1, messageId: 2, value: 'yayy' },
]

Current Tags

  • 0.0.5                                ...           latest (3 years ago)

5 Versions

  • 0.0.5                                ...           3 years ago
  • 0.0.4                                ...           3 years ago
  • 0.0.3                                ...           3 years ago
  • 0.0.2                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 5
Last Day 0
Last Week 5
Last Month 12
Dependencies (5)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |