Tiny provider factory for generating IDs.
Table of contents
npm install provide-id-gen --save
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.
// 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
genBarId- Increments and returns the current
newFooId- The current new
newBarId- The current new
Real world example
On the server, you should probably set
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.