Skip to content

Commit

Permalink
refactor: cleanup some code
Browse files Browse the repository at this point in the history
  • Loading branch information
henri-hulski committed Mar 5, 2024
1 parent 27497b0 commit 2dd7a34
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn-error.log*
dist
es
lib
.cache
.*cache
.DS_Store
devtoolsDist

Expand Down
2 changes: 1 addition & 1 deletion packages/overmind-react/src/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ describe('React', () => {

const FooComponent: React.FunctionComponent = () => {
const state = useState((state) => state.foo[0])
console.log('WTF?')
renderCount++

return <h1>{state.foo}</h1>
Expand Down Expand Up @@ -169,6 +168,7 @@ describe('React', () => {
return <h1>{(state as any).foo}</h1>
}

jest.spyOn(console, 'error') // suppress the error message
expect(() => {
render(<FooComponent />)
}).toThrow(Error)
Expand Down
52 changes: 1 addition & 51 deletions packages/overmind-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,56 +71,6 @@ const useCurrentComponent = () => {
: {}
}

class ReactTrackerV18 {
tree
result
cb
updateCb
constructor(tree: any) {
this.tree = tree
this.result = { state: tree.state }
this.updateCb = () => {
this.result = {
state: this.tree.state,
}

if (this.cb) {
this.cb()
} else {
this.tree.dispose()
}
}
}

subscribe = (cb) => {
this.cb = cb

return () => {
if (IS_PRODUCTION) {
this.tree.dispose()
} else {
// In development we do not dispose of the tree as React will do
// "test runs" on effect hooks, it will rather be disposed when there is an
// update to the tracked paths, but there is no longer a callback to trigger. This
// can cause memory leaks in edge cases, but this is just development and does not matter
delete this.cb
}
}
}

getState = () => {
return this.result
}

track() {
this.tree.track(this.updateCb)
}

stopTracking() {
this.tree.stopTracking()
}
}

const useState = <Context extends IContext<{ state: {} }>>(
cb?: (state: Context['state']) => any
): Context['state'] => {
Expand All @@ -134,7 +84,7 @@ const useState = <Context extends IContext<{ state: {} }>>(
return overmind.state
}

const { flushId, forceRerender } = useForceRerender()
const { forceRerender } = useForceRerender()

const trackStateTree = (
overmind as any
Expand Down
1 change: 0 additions & 1 deletion packages/overmind/src/Overmind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,6 @@ export class Overmind<ThisConfig extends IConfiguration>
} else {
const tree = this.proxyStateTreeInstance.getTrackStateTree()
let returnValue
let disposer
const updateReaction = () => {
tree.trackScope(() => (returnValue = stateCallback(tree.state as any)))
disposer = tree.subscribe(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/overmind/src/rehydrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('REHYDRATE', () => {
foo: 'bar2',
})
})
test.only('should allow rehydration of single class value', () => {
test('should allow rehydration of single class value', () => {
expect.assertions(1)
class User {
name = 'Bob'
Expand Down
6 changes: 0 additions & 6 deletions packages/proxy-state-tree/src/TrackStateTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import {
ITrackStateTree,
} from './types'

// @ts-ignore
/// const registry = new FinalizationRegistry((message) => console.log(message))
// let id = 0

export class TrackStateTree<T extends object> implements ITrackStateTree<T> {
private disposeOnReset: Function
root: IProxyStateTree<T>
Expand All @@ -21,8 +17,6 @@ export class TrackStateTree<T extends object> implements ITrackStateTree<T> {
this.root = root
this.proxifier = root.proxifier
this.state = root.state

// registry.register(this, id++ + ' has been collected')
}

trackPaths() {
Expand Down

0 comments on commit 2dd7a34

Please sign in to comment.