|
1 | | -import { EventType, MODE_SSR } from 'overmind' |
| 1 | +import { EventType, IConfiguration, MODE_SSR, Overmind } from 'overmind' |
| 2 | +import { Component, ComponentOptions } from 'vue' |
| 3 | + |
| 4 | +type AnyComponent = ComponentOptions<any, any, any> | Component |
2 | 5 |
|
3 | 6 | const OVERMIND = Symbol('OVERMIND') |
4 | 7 | const IS_PRODUCTION = process.env.NODE_ENV === 'production' |
@@ -143,21 +146,25 @@ export const createPlugin = (overmind) => ({ |
143 | 146 | }, |
144 | 147 | }) |
145 | 148 |
|
146 | | -export const createConnect = (overmind) => (...args) => { |
147 | | - let options = args.length === 1 ? args[0] : args[1] |
148 | | - let propsCallback = args.length === 1 ? null : args[0] |
149 | 149 |
|
150 | | - if (propsCallback && typeof propsCallback !== 'function') { |
151 | | - throw new Error( |
152 | | - `OVERMIND-VUE: When passing two arguments to "connect", the first has to be a function. You can alternatively only pass a single argument, which is the component` |
153 | | - ) |
154 | | - } |
155 | 150 |
|
156 | | - return { |
157 | | - ...options, |
158 | | - mixins: (options.mixins ? options.mixins : []).concat( |
159 | | - createMixin(overmind, propsCallback, true) |
160 | | - ), |
161 | | - overmind, |
162 | | - } as any |
| 151 | +export function createConnect<Config extends IConfiguration>(overmind: Overmind<Config>) { |
| 152 | + return <T extends {}>(cb: ((overmind: Overmind<Config>) => T) | AnyComponent, component?: AnyComponent) => { |
| 153 | + let options: any = component || cb |
| 154 | + let propsCallback = component ? cb : null |
| 155 | + |
| 156 | + if (propsCallback && typeof propsCallback !== 'function') { |
| 157 | + throw new Error( |
| 158 | + `OVERMIND-VUE: When passing two arguments to "connect", the first has to be a function. You can alternatively only pass a single argument, which is the component` |
| 159 | + ) |
| 160 | + } |
| 161 | + |
| 162 | + return { |
| 163 | + ...options, |
| 164 | + mixins: (options.mixins ? options.mixins : []).concat( |
| 165 | + createMixin(overmind, propsCallback, true) |
| 166 | + ), |
| 167 | + overmind, |
| 168 | + } as any |
| 169 | + } |
163 | 170 | } |
0 commit comments