Skip to content

Commit adb02fd

Browse files
refactor(overmind-vue): forgot to save a file
1 parent 5ac76aa commit adb02fd

File tree

1 file changed

+1
-174
lines changed
  • packages/node_modules/overmind-vue/src

1 file changed

+1
-174
lines changed

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

Lines changed: 1 addition & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,7 @@ import {
55
MODE_SSR,
66
Overmind,
77
} from 'overmind'
8-
import {
9-
Component,
10-
ComponentOptions,
11-
defineComponent,
12-
provide,
13-
Ref,
14-
h,
15-
inject,
16-
ref,
17-
onBeforeUpdate,
18-
onRenderTracked,
19-
onMounted,
20-
onBeforeUnmount,
21-
} from 'vue'
8+
import { Component, ComponentOptions, defineComponent, provide, h } from 'vue'
229

2310
type AnyComponent = ComponentOptions | Component
2411

@@ -204,163 +191,3 @@ export const withOvermind = (
204191
},
205192
})
206193
}
207-
208-
export interface StateHook<Config extends IConfiguration> {
209-
(): Ref<Overmind<Config>['state']>
210-
<CB extends (state: Overmind<Config>['state']) => object>(
211-
cb: CB
212-
): CB extends (state: Overmind<Config>['state']) => infer O
213-
? O extends object
214-
? Ref<O>
215-
: never
216-
: never
217-
}
218-
219-
export function createStateHook<Config extends IConfiguration>(): StateHook<
220-
Config
221-
> {
222-
const componentId = nextComponentId++
223-
let componentInstanceId = 0
224-
return ((cb: any) => {
225-
const overmindInstance = inject<any>('overmind')
226-
227-
if (overmindInstance.mode.mode === MODE_SSR) {
228-
return cb ? cb(overmindInstance.state) : overmindInstance.state
229-
} else {
230-
const overmindRef = ref<any>({})
231-
const flushIds = ref(-1)
232-
const { value } = overmindRef
233-
const state = ref(
234-
cb ? cb(overmindInstance.state) : overmindInstance.state
235-
)
236-
237-
if (!value.tree) {
238-
value.tree = overmindInstance.proxyStateTree.getTrackStateTree()
239-
value.componentInstanceId = componentInstanceId++
240-
value.onUpdate = (_: any, __: any, flushId: number) => {
241-
value.currentFlushId = flushId
242-
value.isUpdating = true
243-
flushIds.value = flushId
244-
state.value = {
245-
...(cb ? cb(overmindInstance.state) : overmindInstance.state),
246-
}
247-
248-
// this.$forceUpdate()
249-
}
250-
value.isUpdating = false
251-
}
252-
253-
onBeforeUpdate(function(this: any, ...args) {
254-
if (overmindInstance.mode.mode === MODE_SSR) return
255-
256-
value.tree.track(value.onUpdate)
257-
})
258-
259-
onRenderTracked(function(this: any, ...args) {
260-
if (IS_PRODUCTION) {
261-
return
262-
}
263-
264-
if (overmindInstance.isUpdating) {
265-
overmindInstance.eventHub.emitAsync(EventType.COMPONENT_UPDATE, {
266-
componentId,
267-
componentInstanceId: value.componentInstanceId,
268-
name: '', // this.$options.name || '',
269-
flushId: value.currentFlushId,
270-
paths: Array.from(value.tree.pathDependencies) as any,
271-
})
272-
value.isUpdating = false
273-
}
274-
})
275-
276-
onMounted(() => {
277-
if (IS_PRODUCTION || overmindInstance.mode.mode === MODE_SSR) return
278-
value.tree.stopTracking()
279-
overmindInstance.eventHub.emitAsync(EventType.COMPONENT_ADD, {
280-
componentId,
281-
componentInstanceId: value.componentInstanceId,
282-
name: '', // this.$options.name || '',
283-
paths: Array.from(value.tree.pathDependencies) as any,
284-
})
285-
})
286-
287-
onBeforeUnmount(() => {
288-
if (overmindInstance.mode.mode === MODE_SSR) return
289-
290-
overmindInstance.proxyStateTree.disposeTree(value.tree)
291-
if (IS_PRODUCTION) {
292-
return
293-
}
294-
295-
overmindInstance.eventHub.emitAsync(EventType.COMPONENT_REMOVE, {
296-
componentId,
297-
componentInstanceId: value.componentInstanceId,
298-
name: '', // this.$options.name || '',
299-
})
300-
})
301-
302-
value.tree.track(value.onUpdate)
303-
304-
return state
305-
}
306-
}) as any
307-
}
308-
309-
export interface ActionsHook<Config extends IConfiguration> {
310-
(): Ref<Overmind<Config>['actions']>
311-
<CB extends (actions: Overmind<Config>['actions']) => object>(
312-
cb: CB
313-
): CB extends (actions: Overmind<Config>['actions']) => infer O
314-
? O extends object
315-
? Ref<O>
316-
: never
317-
: never
318-
}
319-
320-
export function createActionsHook<Config extends IConfiguration>(): ActionsHook<
321-
Config
322-
> {
323-
return ((cb?: any): Overmind<Config>['actions'] => {
324-
const overmindInstance = inject<any>('overmind')
325-
326-
return cb ? cb(overmindInstance.actions) : overmindInstance.actions
327-
}) as any
328-
}
329-
330-
export interface EffectsHook<Config extends IConfiguration> {
331-
(): Ref<Overmind<Config>['effects']>
332-
<CB extends (effects: Overmind<Config>['effects']) => object>(
333-
cb: CB
334-
): CB extends (effects: Overmind<Config>['effects']) => infer O
335-
? O extends object
336-
? Ref<O>
337-
: never
338-
: never
339-
}
340-
341-
export function createEffectsHook<Config extends IConfiguration>(): EffectsHook<
342-
Config
343-
> {
344-
return ((cb?: any): Overmind<Config>['effects'] => {
345-
const overmindInstance = inject<any>('overmind')
346-
347-
return cb ? cb(overmindInstance.effects) : overmindInstance.effects
348-
}) as any
349-
}
350-
351-
export function createReactionHook<Config extends IConfiguration>() {
352-
return (): Overmind<Config>['reaction'] => {
353-
const overmindInstance = inject<any>('overmind')
354-
355-
return overmindInstance.reaction
356-
}
357-
}
358-
359-
export function createHooks<Config extends IConfiguration>() {
360-
return {
361-
state: createStateHook<Config>(),
362-
actions: createActionsHook<Config>(),
363-
effects: createEffectsHook<Config>(),
364-
reaction: createReactionHook<Config>(),
365-
}
366-
}

0 commit comments

Comments
 (0)