Skip to content

Commit 59e0289

Browse files
committed
use typed-emitter@1.5.0-from-event for fromEvent typing (#4)
1 parent 07377fc commit 59e0289

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wechaty-redux",
3-
"version": "1.1.2",
3+
"version": "1.7.0",
44
"description": "Wechaty Redux Plugin Powered By Ducks",
55
"type": "module",
66
"exports": {
@@ -53,13 +53,13 @@
5353
"typesafe-actions": "^5.1.0"
5454
},
5555
"peerDependencies": {
56-
"gerror": "^1.0.8",
56+
"gerror": "^1.0.14",
5757
"redux": "^4.1.2",
5858
"redux-observable": "^2.0.0",
5959
"rxjs": "^7.4",
60-
"state-switch": "^1.3.5",
60+
"state-switch": "^1.6.1",
6161
"uuid": "^8.3.2",
62-
"wechaty-puppet": "^1.7.5"
62+
"wechaty-puppet": "^1.7.19"
6363
},
6464
"devDependencies": {
6565
"@chatie/eslint-config": "^1.0.4",
@@ -72,10 +72,10 @@
7272
"ducks": "^1.0.2",
7373
"glob": "^7.2.0",
7474
"remote-redux-devtools": "^0.5.16",
75-
"typed-emitter": "^1.4.0",
75+
"typed-emitter": "^1.5.0-from-event",
7676
"utility-types": "^3.10.0",
77-
"wechaty": "^1.5.2",
78-
"wechaty-puppet-mock": "^1.0.3"
77+
"wechaty": "^1.7.24",
78+
"wechaty-puppet-mock": "^1.7.1"
7979
},
8080
"files": [
8181
"bin/",

src/wechaty-redux.ts

+30-22
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ import {
2727
} from 'wechaty'
2828

2929
import {
30-
fromEvent,
30+
fromEvent as rxFromEvent,
3131
merge,
32-
} from 'rxjs'
32+
} from 'rxjs'
33+
import type { FromEvent } from 'typed-emitter/rxjs'
34+
import type { StateSwitch } from 'state-switch'
3335
import {
3436
map,
3537
} from 'rxjs/operators'
@@ -42,7 +44,9 @@ import * as duck from './duck/mod.js'
4244

4345
import * as instances from './manager.js'
4446

45-
export interface WechatyReduxOptions {
47+
const fromEvent: FromEvent = rxFromEvent
48+
49+
interface WechatyReduxOptions {
4650
store: Store,
4751
}
4852

@@ -94,30 +98,31 @@ function install (
9498
* but the Puppet for convenience
9599
*/
96100

97-
// TODO: find a better way to remove `any` with StateSwitch interface
98-
const switchActive$ = fromEvent<true | 'pending'>(wechaty.puppet.state as any, 'active')
99-
const switchInactive$ = fromEvent<true | 'pending'>(wechaty.puppet.state as any, 'inactive')
101+
const state = wechaty.puppet.state as StateSwitch
102+
103+
const switchActive$ = fromEvent(state, 'active')
104+
const switchInactive$ = fromEvent(state, 'inactive')
100105

101106
/**
102107
* FIXME: Huan(20200312) remove the specified explicit types
103108
* https://github.com/wechaty/wechaty-redux/issues/4
104109
*/
105-
const puppet = wechaty.puppet
106-
107-
const dong$ = fromEvent<PUPPET.payload.EventDong> (puppet, 'dong')
108-
const error$ = fromEvent<PUPPET.payload.EventError> (puppet, 'error')
109-
const friendship$ = fromEvent<PUPPET.payload.EventFriendship> (puppet, 'friendship')
110-
const heartbeat$ = fromEvent<PUPPET.payload.EventHeartbeat> (puppet, 'heartbeat')
111-
const login$ = fromEvent<PUPPET.payload.EventLogin> (puppet, 'login')
112-
const logout$ = fromEvent<PUPPET.payload.EventLogout> (puppet, 'logout')
113-
const message$ = fromEvent<PUPPET.payload.EventMessage> (puppet, 'message')
114-
const ready$ = fromEvent<PUPPET.payload.EventReady> (puppet, 'ready')
115-
const reset$ = fromEvent<PUPPET.payload.EventReset> (puppet, 'reset')
116-
const roomInvite$ = fromEvent<PUPPET.payload.EventRoomInvite> (puppet, 'room-invite')
117-
const roomJoin$ = fromEvent<PUPPET.payload.EventRoomJoin> (puppet, 'room-join')
118-
const roomLeave$ = fromEvent<PUPPET.payload.EventRoomLeave> (puppet, 'room-leave')
119-
const roomTopic$ = fromEvent<PUPPET.payload.EventRoomTopic> (puppet, 'room-topic')
120-
const scan$ = fromEvent<PUPPET.payload.EventScan> (puppet, 'scan')
110+
const puppet = wechaty.puppet as PUPPET.impl.PuppetAbstract
111+
112+
const dong$ = fromEvent(puppet, 'dong')
113+
const error$ = fromEvent(puppet, 'error')
114+
const friendship$ = fromEvent(puppet, 'friendship')
115+
const heartbeat$ = fromEvent(puppet, 'heartbeat')
116+
const login$ = fromEvent(puppet, 'login')
117+
const logout$ = fromEvent(puppet, 'logout')
118+
const message$ = fromEvent(puppet, 'message')
119+
const ready$ = fromEvent(puppet, 'ready')
120+
const reset$ = fromEvent(puppet, 'reset')
121+
const roomInvite$ = fromEvent(puppet, 'room-invite')
122+
const roomJoin$ = fromEvent(puppet, 'room-join')
123+
const roomLeave$ = fromEvent(puppet, 'room-leave')
124+
const roomTopic$ = fromEvent(puppet, 'room-topic')
125+
const scan$ = fromEvent(puppet, 'scan')
121126

122127
merge(
123128
/* eslint-disable no-whitespace-before-property */
@@ -141,6 +146,9 @@ function install (
141146
).subscribe(store.dispatch)
142147
}
143148

149+
export type {
150+
WechatyReduxOptions,
151+
}
144152
export {
145153
WechatyRedux,
146154
}

0 commit comments

Comments
 (0)