Skip to content

Commit

Permalink
feat(debug): #38 di (remove combine from devtools log)
Browse files Browse the repository at this point in the history
  • Loading branch information
artalar committed Jan 16, 2020
1 parent 8a43b49 commit 4a608a8
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions packages/debug/src/redux-devtools.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Store } from '@reatom/core'
import { initAction, Store, Action } from '@reatom/core'

// http://extension.remotedev.io/docs/API/Methods.html#connect
export function connectReduxDevtools(store: Store, config: object = {}) {
export function connectReduxDevtools(store: Store, config = {}) {
const devTools =
// @ts-ignore
window.__REDUX_DEVTOOLS_EXTENSION__ &&
Expand All @@ -10,6 +10,35 @@ export function connectReduxDevtools(store: Store, config: object = {}) {

if (!devTools) return

devTools.init(store.getState())
return store.subscribe(action => devTools.send(action, store.getState()))
let state = store.getState()

devTools.init(state)

devTools.subscribe((action: any) => {
if (action.type === 'DISPATCH') {
// TODO: improve action types
// @ts-ignore
store.dispatch({ ...initAction, payload: JSON.parse(action.state) })
}
})
return store.subscribe((action, diff) => {
if (action.type === initAction.type) return

const keys: (string | symbol)[] = Object.keys(diff)
keys.push(...Object.getOwnPropertySymbols(diff))

if (keys.length) {
state = { ...state }
keys.forEach(k => {
if (
typeof k !== 'symbol' ||
// combine
!k.toString().startsWith('Symbol({')
) {
state[k.toString()] = diff[k as string]
}
})
}
devTools.send(action, state)
})
}

0 comments on commit 4a608a8

Please sign in to comment.