Tiny provider factory for generating IDs.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src include `clientStateKeys` Jun 19, 2016
test updated deps Oct 25, 2017
.babelrc Initial commit Jun 2, 2016
.gitignore Initial commit Jun 2, 2016
.npmignore Initial commit Jun 2, 2016
.travis.yml Initial commit Jun 2, 2016
LICENSE Initial commit Jun 2, 2016
README.md include info about `isGlobal` property Jun 23, 2016
package-lock.json 1.0.0 Oct 25, 2017
package.json
webpack.config.base.js Initial commit Jun 2, 2016
webpack.config.development.js Initial commit Jun 2, 2016
webpack.config.production.js Initial commit Jun 2, 2016

README.md

provide-id-gen

build status npm version npm downloads

Tiny provider factory for generating IDs.

Table of contents

  1. Installation
  2. Usage
  3. Example
  4. Real world example
  5. Protip

Installation

npm install provide-id-gen --save

Usage

Pass any set of keys (an array of strings) to the provideIdGen function and it will return a provider with genId action(s) and newId reducer(s) based on each key. Each key is usually some provider key for which you would like to generate IDs.

Example

// src/providers/idGen.js

import provideIdGen from 'provide-id-gen';

const idGen = provideIdGen([
  'foo',
  'bar'
]);

export default idGen;

You'll then have a provider with the following actions:

  • genFooId - Increments and returns the current fooId.
  • genBarId - Increments and returns the current barId.

And reducers:

  • newFooId - The current new fooId.
  • newBarId - The current new barId.

Real world example

See Lumbur's user login component.

Protip

On the server, you should probably set isGlobal to true. This will ensure the same provider instance is used across multiple requests and prevent any race conditions with replication if/when some ID of the same key is generated for more than one request at almost the exact same time.