|
1 | | -import{assert}from'chai' |
| 1 | +importinvariantfrom'invariant' |
2 | 2 | import{ROOT_STATE_KEY,ACTION_PREFIX,IDLESTATUS_ACTIVE}from'./constants' |
3 | 3 | import{getActiveEvents,getUseFastState,getUseLocalState,getUseWebRTCState,getUseWebSocketsState,getThresholds,getLevel}from'./defaults' |
4 | 4 | import{translateBlueprintsWith,translateBlueprintTypesWith}from'redux-blueprint' |
5 | 5 |
|
6 | 6 | constvalidateContext=(libContext,appContext)=>{ |
7 | | -assert.ok(libContext,'must pass opts to validate') |
8 | | -assert.ok(appContext,'must pass opts to validate') |
| 7 | +invariant(libContext,'must pass opts to validate') |
| 8 | +invariant(appContext,'must pass opts to validate') |
9 | 9 |
|
10 | 10 | const{ libName, appName}=libContext |
11 | 11 | const{ activeEvents, thresholds}=appContext |
12 | 12 |
|
13 | | -assert.ok(libName,'libName must exist') |
14 | | -assert(typeoflibName==='string','libName option must be a string') |
15 | | -assert(libName.length>0,'libName option must not be empty') |
16 | | -assert.ok(appName,'appName must exist') |
17 | | -assert(typeofappName==='string','appName option must be a string') |
18 | | -assert(appName.length>0,'appName option must not be empty') |
19 | | -assert.ok(activeEvents,'active events must exist') |
20 | | -assert.ok(thresholds,'thresholds must exist') |
21 | | -assert.ok(thresholds.mouse,'thresholds.mouse must exist') |
22 | | -assert(typeofthresholds.mouse==='number','thresholds.mouse must be a number corresponding to pixels') |
23 | | -assert(typeofthresholds.phaseOffMS==='number','thresholds.phaseOffMS must be a number corresponding to minimum milliseconds between updates to redux') |
24 | | -assert(typeofthresholds.phaseOnMS==='number','thresholds.phaseOnMS must be a number corresponding to minimum milliseconds between updates to redux') |
| 13 | +invariant(libName,'libName must exist') |
| 14 | +invariant(typeoflibName==='string','libName option must be a string') |
| 15 | +invariant(libName.length>0,'libName option must not be empty') |
| 16 | +invariant(appName,'appName must exist') |
| 17 | +invariant(typeofappName==='string','appName option must be a string') |
| 18 | +invariant(appName.length>0,'appName option must not be empty') |
| 19 | +invariant(activeEvents,'active events must exist') |
| 20 | +invariant(thresholds,'thresholds must exist') |
| 21 | +invariant(thresholds.mouse,'thresholds.mouse must exist') |
| 22 | +invariant(typeofthresholds.mouse==='number','thresholds.mouse must be a number corresponding to pixels') |
| 23 | +invariant(typeofthresholds.phaseOffMS==='number','thresholds.phaseOffMS must be a number corresponding to minimum milliseconds between updates to redux') |
| 24 | +invariant(typeofthresholds.phaseOnMS==='number','thresholds.phaseOnMS must be a number corresponding to minimum milliseconds between updates to redux') |
25 | 25 | } |
26 | 26 |
|
27 | 27 | constconfigureInitialState=libContext=>appContext=>{ |
@@ -57,28 +57,28 @@ const cleanActionName = name => name.toUpperCase().replace(/-+\s+/, '_') |
57 | 57 |
|
58 | 58 | /** Validates library creators options */ |
59 | 59 | constvalidateLibOpts=libOptsRaw=>{ |
60 | | -assert.ok(libOptsRaw,'libOpts definition is required') |
| 60 | +invariant(libOptsRaw,'libOpts definition is required') |
61 | 61 | const{ libName, validateContext, configureAppContext, configureInitialState}=libOptsRaw |
62 | | -assert(typeoflibName==='string','libName must be a string') |
63 | | -assert(libName.length>0,'libName must not be empty') |
| 62 | +invariant(typeoflibName==='string','libName must be a string') |
| 63 | +invariant(libName.length>0,'libName must not be empty') |
64 | 64 |
|
65 | | -assert.ok(validateContext,'validateContext must exist') |
66 | | -assert(typeofvalidateContext==='function','validateContext must be a function') |
| 65 | +invariant(validateContext,'validateContext must exist') |
| 66 | +invariant(typeofvalidateContext==='function','validateContext must be a function') |
67 | 67 |
|
68 | | -assert.ok(configureAppContext,'configureAppContext must exist') |
69 | | -assert(typeofconfigureAppContext==='function','configureAppContext must be a function') |
| 68 | +invariant(configureAppContext,'configureAppContext must exist') |
| 69 | +invariant(typeofconfigureAppContext==='function','configureAppContext must be a function') |
70 | 70 |
|
71 | | -assert.ok(configureInitialState,'configureInitialState must exist') |
72 | | -assert(typeofconfigureInitialState==='function','configureInitialState must be a function') |
| 71 | +invariant(configureInitialState,'configureInitialState must exist') |
| 72 | +invariant(typeofconfigureInitialState==='function','configureInitialState must be a function') |
73 | 73 | } |
74 | 74 |
|
75 | 75 | /** Validates library consumers options */ |
76 | 76 | constvalidateAppOpts=appOptsRaw=>{ |
77 | | -assert.ok(appOptsRaw,'appOpts are required') |
| 77 | +invariant(appOptsRaw,'appOpts are required') |
78 | 78 | const{ appName}=appOptsRaw |
79 | 79 |
|
80 | | -assert(typeofappName==='string','appName opt must be a string') |
81 | | -assert(appName.length>0,'appName opt must not be empty') |
| 80 | +invariant(typeofappName==='string','appName opt must be a string') |
| 81 | +invariant(appName.length>0,'appName opt must not be empty') |
82 | 82 | } |
83 | 83 |
|
84 | 84 | functionconfigureContext(libOpts){ |
|