Skip to content

Commit b69c8ac

Browse files
feat(overmind-angular): optimize for SSR
1 parent da7f905 commit b69c8ac

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/node_modules/overmind-angular/src/directive.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
// @ts-ignore
1313
} from '@angular/core'
1414
import { OvermindService } from './service'
15-
import { EventType, Overmind } from 'overmind'
15+
import { EventType, Overmind, MODE_SSR } from 'overmind'
1616
import { IS_PROXY } from 'proxy-state-tree'
1717

1818
export const OVERMIND_INSTANCE = new InjectionToken('OVERMIND')
@@ -40,13 +40,12 @@ export class OvermindTrackDirective implements OnInit, OnDestroy {
4040
) {
4141
this.component = (this.viewContainer as any)._view.component
4242
this.overmind = overmind
43+
if (this.overmind.mode === MODE_SSR) {
44+
return
45+
}
46+
4347
this.tree = this.overmind.proxyStateTree.getTrackStateTreeWithProxifier()
4448
}
45-
findService(target) {
46-
return Object.keys(target).find(
47-
(key) => target[key] instanceof OvermindService
48-
)
49-
}
5049
rescope() {
5150
let hasRescoped = false
5251
for (let key in this.component) {
@@ -67,6 +66,10 @@ export class OvermindTrackDirective implements OnInit, OnDestroy {
6766
}
6867
}
6968
ngOnInit() {
69+
if (this.overmind.mode === MODE_SSR) {
70+
return
71+
}
72+
7073
this.rescope()
7174
this.view = this.viewContainer.createEmbeddedView(this.templateRef)
7275

@@ -113,6 +116,10 @@ export class OvermindTrackDirective implements OnInit, OnDestroy {
113116
}
114117

115118
ngOnDestroy() {
119+
if (this.overmind.mode === MODE_SSR) {
120+
return
121+
}
122+
116123
this.overmind.proxyStateTree.disposeTree(this.tree)
117124
if (this.componentDetails) {
118125
this.overmind.eventHub.emitAsync(EventType.COMPONENT_REMOVE, {

0 commit comments

Comments
 (0)