Skip to content

Commit bae7005

Browse files
fix(proxy-state-tree): keep track of tracking, avoiding async access to affect tracking
1 parent cc7eac7 commit bae7005

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

packages/node_modules/overmind-react/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
145145
componentInstanceId = componentInstanceId++
146146
currentFlushId = 0
147147
componentDidMount() {
148+
console.log(this.tree)
148149
overmind.eventHub.emitAsync(EventType.COMPONENT_ADD, {
149150
componentId: populatedComponent.__componentId,
150151
componentInstanceId: this.componentInstanceId,

packages/node_modules/proxy-state-tree/src/TrackStateTree.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class TrackStateTree<T extends object> implements ITrackStateTree<T> {
1010
master: IProxyStateTree<T>
1111
pathDependencies: Set<string> = new Set()
1212
callback: ITrackCallback
13+
shouldTrack: boolean = false
1314
state: T
1415
proxifier: IProxifier<T>
1516
constructor(master: IProxyStateTree<T>) {
@@ -24,6 +25,10 @@ export class TrackStateTree<T extends object> implements ITrackStateTree<T> {
2425
return true
2526
}
2627
addTrackingPath(path: string) {
28+
if (!this.shouldTrack) {
29+
return
30+
}
31+
2732
this.pathDependencies.add(path)
2833

2934
if (this.callback) {
@@ -32,7 +37,8 @@ export class TrackStateTree<T extends object> implements ITrackStateTree<T> {
3237
}
3338
track(cb?: ITrackCallback) {
3439
this.master.changeTrackStateTree(this)
35-
40+
this.shouldTrack = true
41+
setTimeout(() => (this.shouldTrack = false))
3642
if (this.callback) {
3743
for (let path of this.pathDependencies) {
3844
this.master.removePathDependency(path, this.callback)

packages/overmind-website/src/app/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ declare module 'overmind' {
1616
interface IConfig extends TConfig<typeof config> {}
1717
}
1818

19-
export type Connect = TConnect<typeof config>
20-
2119
const app = new Overmind(
2220
config,
2321
process.env.NODE_ENV === 'production'
@@ -28,5 +26,3 @@ const app = new Overmind(
2826
)
2927

3028
export const useOvermind = createHook(app)
31-
32-
export const connect = createConnect(app)

packages/overmind-website/src/app/state.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ type State = {
2525
isLoadingSearchResult: boolean
2626
searchResult: SearchResult[]
2727
showSearchResult: boolean
28-
test: Derive<State, Guide[]>
2928
}
3029

3130
const state: State = {
@@ -44,7 +43,6 @@ const state: State = {
4443
isLoadingSearchResult: false,
4544
searchResult: [],
4645
showSearchResult: false,
47-
test: (state) => state.guides.filter((guide) => guide.type === 'beginner'),
4846
}
4947

5048
export default state

packages/overmind-website/src/components/App/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createElement, SFC, useRef, useEffect } from 'react'
2-
import { useOvermind, connect, Connect } from '../../app'
2+
import { useOvermind } from '../../app'
33
import * as styles from './styles'
44
import TopBar from '../TopBar'
55
import FrontPage from '../FrontPage'
@@ -30,7 +30,8 @@ const fadeInPage = () => {
3030
logo.style.opacity = '0'
3131
}
3232

33-
const App: SFC<Connect> = ({ overmind: { state } }) => {
33+
const App: SFC = () => {
34+
const { state } = useOvermind()
3435
const mainRef = useRef(null)
3536
const isMobile = useIsMobile()
3637
useScrollToTop(state.page)
@@ -53,4 +54,4 @@ const App: SFC<Connect> = ({ overmind: { state } }) => {
5354
)
5455
}
5556

56-
export default connect(App)
57+
export default App

0 commit comments

Comments
 (0)