Skip to content

Commit

Permalink
feat: remove redundant dev-dependencies & rename state middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
fletcherist committed Jul 29, 2018
1 parent c98bfbc commit 7d16620
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
7 changes: 0 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,6 @@
"@types/node": "^10.5.1",
"conventional-changelog-cli": "^2.0.0",
"conventional-github-releaser": "^3.1.0",
"eslint": "^4.19.0",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-babel": "^5.1.0",
"eslint-plugin-import": "^2.10.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-standard": "^3.0.1",
"husky": "^0.14.3",
"jest": "^23.2.0",
"prettier": "^1.13.7",
Expand Down
4 changes: 2 additions & 2 deletions src/alice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { selectCommand, selectSessionId, isFunction, delay, rejectsIn } from './

import { applyMiddlewares } from './middlewares'

import aliceStateMiddleware from './middlewares/aliceStateMiddleware'
import stateMiddleware from './middlewares/stateMiddleware'

import { IConfig, IAlice } from './types/alice'
import { ICommand } from './types/command'
Expand Down Expand Up @@ -52,7 +52,7 @@ export default class Alice implements IAlice {
this.anyCallback = null
this.welcomeCallback = null
this.commands = new Commands(config.fuseOptions || null)
this.middlewares = [aliceStateMiddleware()]
this.middlewares = [stateMiddleware()]
this.scenes = []
this.currentScene = null
this.sessions = new Sessions()
Expand Down
21 changes: 21 additions & 0 deletions src/middlewares/stateMiddleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export default function stateMiddleware() {
const store = new Map()

return async ctx => {
const key = ctx.session.sessionId
let { state } = store.get(key) || { state: {} }
Object.defineProperty(ctx, 'state', {
get() {
return state
},
set(value) {
state = Object.assign({}, value)
},
})
store.set(key, {
state,
})

return ctx
}
}
8 changes: 1 addition & 7 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@
"extends": ["tslint:recommended"],
"jsRules": {},
"rules": {
// We handle this manually
"interface-name": [true, "always-prefix"],

// There are some dependencies we have (e.g. shallowequal) that need to be var-required because
// the available typings aren't great
"no-var-requires": false,

// These rules are super annoying in this project
"object-literal-sort-keys": false,
"ordered-imports": false,
"semicolon": [true, "never"],
"quotemark": [true, "single"],
"indent": [true, "spaces", 2],
"indent": [true, "spaces", 2]
},
"rulesDirectory": []
}

0 comments on commit 7d16620

Please sign in to comment.