Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc91fec

Browse files
tomchentwcchamberlain
authored andcommitted
Fix/switch chai to invariant (#10)
* yarn* add invariant to dependencies* switch chai to invariant* remove chai from dependenciescloses#9
1 parent6ffe50f commitbc91fec

File tree

6 files changed

+560
-548
lines changed

6 files changed

+560
-548
lines changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
],
3535
"dependencies": {
3636
"babel-runtime":"^6.18.0",
37-
"chai":"^3.5.0",
37+
"invariant":"^2.2.2",
3838
"localsync":"^1.1.8",
3939
"redux":"^3.5.2",
4040
"redux-actions":"^0.9.1",

‎src/lib/actions.js‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
importinvariantfrom'invariant'
12
import{startBlueprint,stopBlueprint,resetIdleStatusBlueprint,activityBlueprint,activityDetectionBlueprint}from'./blueprints'
23
import{IS_DEV,IDLESTATUS_ACTIVE,USER_ACTIVE,NEXT_IDLE_STATUS,RESET_IDLE_STATUS}from'./constants'
34
importlocalsyncfrom'localsync'
4-
constshould=require('chai').should()
55

66
constSTOP_TYPES=['pointermove','MSPointerMove']
77
constFILTER_TYPES=['mousemove']
@@ -30,17 +30,17 @@ const createShouldActivityUpdate = ({ log, thresholds }) => store => ({ type, pa
3030
constselectIdleState=state=>{
3131
const{ idle}=state
3232
if(IS_DEV){
33-
should.exist(idle,'idle monitor state should have idle value')
34-
state.idle.should.be.an('object')
33+
invariant(idle,'idle monitor state should have idle value')
34+
invariant(typeofstate.idle==='object')
3535
}
3636
returnidle
3737
}
3838

3939
constisRunning=(dispatch,getState)=>{
4040
const{ isDetectionRunning}=selectIdleState(getState())
4141
if(IS_DEV){
42-
should.exist('isDetectionRunning','idle monitor state should have idDetectionRunning defined')
43-
isDetectionRunning.should.be.a('boolean')
42+
invariant('isDetectionRunning','idle monitor state should have idDetectionRunning defined')
43+
invariant(typeofisDetectionRunning==='boolean')
4444
}
4545
returnisDetectionRunning
4646
}
@@ -98,12 +98,12 @@ export const createDetection = ({ log, activeEvents, thresholds, translateBluepr
9898
const{ startActivityDetection, stopActivityDetection}=createActivityDetection({ log, thresholds, activeEvents, activity, activityDetection, getIsTransition})(store)
9999
constlocalSync=createLocalSync({ log, activity, getIsTransition})(store)
100100

101-
should.exist(startActivityDetection,'startActivityDetection should be a return property of createActivityDetection')
102-
should.exist(stopActivityDetection,'stopActivityDetection should be a return property of createActivityDetection')
103-
should.exist(localSync,'localSync should exist')
104-
should.exist(localSync.start,'localSync.start should exist')
105-
should.exist(localSync.stop,'localSync.stop should exist')
106-
should.exist(localSync.trigger,'localSync.trigger should exist')
101+
invariant(startActivityDetection,'startActivityDetection should be a return property of createActivityDetection')
102+
invariant(stopActivityDetection,'stopActivityDetection should be a return property of createActivityDetection')
103+
invariant(localSync,'localSync should exist')
104+
invariant(localSync.start,'localSync.start should exist')
105+
invariant(localSync.stop,'localSync.stop should exist')
106+
invariant(localSync.trigger,'localSync.trigger should exist')
107107

108108
log.info('activity detection starting')
109109

‎src/lib/blueprints.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import{assert}from'chai'
1+
importinvariantfrom'invariant'
22
import{createBlueprint}from'redux-blueprint'
33
import{IDLESTATUS_ACTIVE,START_BLUEPRINT,STOP_BLUEPRINT,GOTO_IDLE_STATUS_BLUEPRINT,ACTIVITY_BLUEPRINT,ACTIVITY_DETECTION_BLUEPRINT,NEXT_IDLE_STATUS_BLUEPRINT,LAST_IDLE_STATUS_BLUEPRINT}from'./constants'
44

@@ -13,7 +13,7 @@ export const activityDetectionBlueprint = createBlueprint(ACTIVITY_DETECTION_BLU
1313
exportconstpublicBlueprints={start:startBlueprint,stop:stopBlueprint,gotoIdleStatus:gotoIdleStatusBlueprint}
1414

1515
exportconstnextIdleStatusBlueprint=createBlueprint(NEXT_IDLE_STATUS_BLUEPRINT,nextIdleStatus=>{
16-
assert.ok(nextIdleStatus,'nextIdleStatus must be defined')
16+
invariant(nextIdleStatus,'nextIdleStatus must be defined')
1717
return{ nextIdleStatus}
1818
})
1919

‎src/lib/context.js‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import{assert}from'chai'
1+
importinvariantfrom'invariant'
22
import{ROOT_STATE_KEY,ACTION_PREFIX,IDLESTATUS_ACTIVE}from'./constants'
33
import{getActiveEvents,getUseFastState,getUseLocalState,getUseWebRTCState,getUseWebSocketsState,getThresholds,getLevel}from'./defaults'
44
import{translateBlueprintsWith,translateBlueprintTypesWith}from'redux-blueprint'
55

66
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')
99

1010
const{ libName, appName}=libContext
1111
const{ activeEvents, thresholds}=appContext
1212

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')
2525
}
2626

2727
constconfigureInitialState=libContext=>appContext=>{
@@ -57,28 +57,28 @@ const cleanActionName = name => name.toUpperCase().replace(/-+\s+/, '_')
5757

5858
/** Validates library creators options */
5959
constvalidateLibOpts=libOptsRaw=>{
60-
assert.ok(libOptsRaw,'libOpts definition is required')
60+
invariant(libOptsRaw,'libOpts definition is required')
6161
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')
6464

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')
6767

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')
7070

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')
7373
}
7474

7575
/** Validates library consumers options */
7676
constvalidateAppOpts=appOptsRaw=>{
77-
assert.ok(appOptsRaw,'appOpts are required')
77+
invariant(appOptsRaw,'appOpts are required')
7878
const{ appName}=appOptsRaw
7979

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')
8282
}
8383

8484
functionconfigureContext(libOpts){

‎src/lib/middleware.js‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
importinvariantfrom'invariant'
12
importcreateContextfrom'./context'
23
import{IS_DEV,IDLESTATUS_ACTIVE,ROOT_STATE_KEY,NEXT_IDLE_STATUS_BLUEPRINT,LAST_IDLE_STATUS_BLUEPRINT,START_BLUEPRINT,STOP_BLUEPRINT,ACTIVITY_BLUEPRINT}from'./constants'
34
import{bisectStore}from'redux-mux'
45
import{publicBlueprints,nextIdleStatusBlueprint,lastIdleStatusBlueprint}from'./blueprints'
56
import{createDetection}from'./actions'
67
import{getNextIdleStatusIn}from'./states'
7-
constshould=require('chai').should()
8-
98

109
/** When context has already been created, it can be shared to middleware component. */
1110
exportconstcreateMiddleware=context=>{
@@ -43,9 +42,9 @@ export const createMiddleware = context => {
4342
constidleStore=bisectStore(ROOT_STATE_KEY)(store)
4443
const{ startActivityDetection, stopActivityDetection, localSync}=createDetection(context)(store)
4544
if(IS_DEV){
46-
should.exist(startActivityDetection,'createDetection should return startActivityDetection')
47-
should.exist(stopActivityDetection,'createDetection should return stopActivityDetection')
48-
should.exist(localSync,'localSync should exist')
45+
invariant(startActivityDetection,'createDetection should return startActivityDetection')
46+
invariant(stopActivityDetection,'createDetection should return stopActivityDetection')
47+
invariant(localSync,'localSync should exist')
4948
}
5049
returnnext=>action=>{
5150
const{ dispatch, getState}=store
@@ -57,8 +56,8 @@ export const createMiddleware = context => {
5756
constscheduleTransition=idleStatus=>{
5857
clearTimeout(nextTimeoutID)
5958
letdelay=dispatch(idleStatusDelay(idleStatus))
60-
should.exist(delay,`must return an idle status delay for idleStatus === '${idleStatus}'`)
61-
delay.should.be.a('number',`idle status delay must be a number type for idleStatus === '${idleStatus}'`)
59+
invariant(delay,`must return an idle status delay for idleStatus === '${idleStatus}'`)
60+
invariant(typeofdelay==='number',`idle status delay must be a number type for idleStatus === '${idleStatus}'`)
6261

6362
letlastActive=newDate().toTimeString()
6463
letnextMessage=`${NEXT_IDLE_STATUS} action continuing after${delay} MS delay, lastActive:${newDate().toTimeString()}`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp