Skip to content

Commit bba8d13

Browse files
committed
fix(overmind): use the full and complete app for onInitialize
this is the only way for advance uses of this important initialization step like connecting components in configurations.
1 parent 8288890 commit bba8d13

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

packages/node_modules/overmind-devtools/src/app/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import {
3131
} from './operators'
3232

3333
export const onInitialize: OnInitialize = async ({
34-
value: actions,
34+
value: app,
3535
state,
3636
storage,
3737
connector,
@@ -40,7 +40,7 @@ export const onInitialize: OnInitialize = async ({
4040
if (port) {
4141
state.port = port
4242
}
43-
connector.onMessage(actions.onMessage)
43+
connector.onMessage(app.actions.onMessage)
4444
connector.connect(state.port)
4545
}
4646

packages/node_modules/overmind-devtools/src/app/effects.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as jsonStorage from 'electron-json-storage'
2-
import BackendConnector from 'overmind-devtools/src/BackendConnector'
2+
import BackendConnector from '../BackendConnector'
33

44
export const connector = new BackendConnector()
55

@@ -31,9 +31,9 @@ export const storage = {
3131
// Insanely weird that when "no value", an empty
3232
// object is returned. Should be null
3333
typeof data === 'object' &&
34-
!Array.isArray(data) &&
35-
data !== null &&
36-
Object.keys(data).length === 0
34+
!Array.isArray(data) &&
35+
data !== null &&
36+
Object.keys(data).length === 0
3737
? null
3838
: data
3939
)

packages/node_modules/overmind/src/index.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ describe('Overmind', () => {
8181
expect(app.state.foo).toEqual('bar')
8282
})
8383

84-
test('should instantiate app with onInitialize', () => {
84+
test('should instantiate app with onInitialize', async () => {
8585
expect.assertions(2)
86+
let value: any
8687
const app = new Overmind({
8788
onInitialize(context) {
8889
expect(context.state.foo).toBe('bar')
89-
expect(typeof context.value.doThis === 'function').toBe(true)
90+
value = context.value
9091
},
9192
state: {
9293
foo: 'bar',
@@ -95,8 +96,8 @@ describe('Overmind', () => {
9596
doThis() {},
9697
},
9798
})
98-
99-
return app.initialized
99+
await app.initialized
100+
expect(value).toBe(app)
100101
})
101102
test('should be able to type actions', () => {
102103
expect.assertions(2)

packages/node_modules/overmind/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export class Overmind<Config extends Configuration> implements Configuration {
151151
configuration.onInitialize
152152
)
153153

154-
this.initialized = Promise.resolve(onInitialize(this.actions))
154+
this.initialized = Promise.resolve(onInitialize(this))
155155
} else {
156156
this.initialized = Promise.resolve(null)
157157
}

packages/node_modules/overmind/src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ResolveActions, ResolveState, TBaseContext } from './internalTypes'
2+
import { Overmind } from './'
23

34
/** ===== PUBLIC API
45
*/
@@ -58,5 +59,5 @@ export type TReaction<Config extends Configuration> = (
5859
) => any
5960

6061
export type TOnInitialize<Config extends Configuration> = (
61-
context: TValueContext<Config, ResolveActions<Config['actions']>>
62+
context: TValueContext<Config, Overmind<Config>>
6263
) => void

0 commit comments

Comments
 (0)