Skip to content

Commit f31c615

Browse files
feat(overmind-vue): add custom connect
1 parent 6c8932a commit f31c615

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

packages/node_modules/overmind-vue/src/Index.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ describe('Vue', () => {
2121
)
2222
expect(vm.overmind.state.foo).toBe('bar')
2323
})
24+
it('should mount with custom connected app', () => {
25+
const app = new Overmind({
26+
state: {
27+
foo: 'bar',
28+
},
29+
})
30+
const connect = createConnect(app)
31+
const vm = new Vue(
32+
connect(
33+
({ state }) => ({
34+
state,
35+
}),
36+
{
37+
el: dom.window.document.createElement('div'),
38+
}
39+
)
40+
)
41+
expect(vm.state.foo).toBe('bar')
42+
})
2443
it('should expose actions', (done) => {
2544
const app = new Overmind({
2645
state: {

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { EventType } from 'overmind'
22

33
let nextComponentId = 0
44

5-
export const createConnect = (overmind) => (options) => {
5+
export const createConnect = (overmind) => (...args) => {
66
const componentId = nextComponentId++
77
let componentInstanceId = 0
8+
let options = args.length === 1 ? args[0] : args[1]
9+
let propsCallback = args.length === 1 ? null : args[0]
810

911
return {
1012
...options,
@@ -22,6 +24,16 @@ export const createConnect = (overmind) => (options) => {
2224
effects: overmind.effects,
2325
addMutationListener: overmind.addMutationListener,
2426
}
27+
if (propsCallback) {
28+
Object.assign(
29+
this,
30+
propsCallback({
31+
state: this.__tree.state,
32+
actions: overmind.actions,
33+
effects: overmind.effects,
34+
})
35+
)
36+
}
2537
this.__tree.track(this.__onUpdate)
2638
},
2739
beforeUpdate(this: any) {

0 commit comments

Comments
 (0)