Skip to content

Commit 4c3ba65

Browse files
authored
Merge pull request #60 from retejs/fix/unmount
Fix/unmount
2 parents 68cab7f + 4d17a2e commit 4c3ba65

6 files changed

Lines changed: 34 additions & 26 deletions

File tree

ng16/patch/module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33

4-
import { NodeComponent, RefDirective } from './presets/classic/components/node/node.component';
4+
import { NodeComponent } from './presets/classic/components/node/node.component';
55
import { ConnectionComponent } from './presets/classic/components/connection/connection.component';
66
import { SocketComponent } from './presets/classic/components/socket/socket.component';
77
import { ConnectionWrapperComponent } from './presets/classic/components/connection/connection-wrapper.component';
88
import { ControlComponent } from './presets/classic/components/control/control.component';
9+
import { RefDirective } from './ref';
910

1011
@NgModule({
1112
declarations: [
@@ -28,4 +29,4 @@ import { ControlComponent } from './presets/classic/components/control/control.c
2829
ControlComponent
2930
]
3031
})
31-
export class ReteModule {}
32+
export class ReteModule { }

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ export * from './presets/classic/components'
1010
export * from './presets/context-menu/components'
1111
export * from './presets/minimap/components'
1212
export * from './presets/reroute/components'
13+
export * from './ref'
1314
export * from './core'

src/module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33

4-
import { NodeComponent, RefDirective } from './presets/classic/components/node/node.component';
4+
import { NodeComponent } from './presets/classic/components/node/node.component';
55
import { ConnectionComponent } from './presets/classic/components/connection/connection.component';
66
import { SocketComponent } from './presets/classic/components/socket/socket.component';
77
import { ConnectionWrapperComponent } from './presets/classic/components/connection/connection-wrapper.component';
88
import { ControlComponent } from './presets/classic/components/control/control.component';
9+
import { RefDirective } from './ref';
910

1011
@NgModule({
1112
declarations: [
@@ -35,4 +36,4 @@ import { ControlComponent } from './presets/classic/components/control/control.c
3536
ControlComponent
3637
]
3738
})
38-
export class ReteModule {}
39+
export class ReteModule { }

src/presets/classic/components/control/control.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, ChangeDetectionStrategy, AfterViewInit, OnChanges, SimpleChanges, AfterViewChecked, ChangeDetectorRef, HostListener } from '@angular/core';
1+
import { Component, Input, OnChanges, SimpleChanges, ChangeDetectorRef, HostListener } from '@angular/core';
22
import { ClassicPreset } from 'rete';
33

44
@Component({
@@ -15,7 +15,7 @@ export class ControlComponent<T extends 'text' | 'number'> implements OnChanges
1515
event.stopPropagation();
1616
}
1717

18-
constructor(private cdr: ChangeDetectorRef) {
18+
constructor(private cdr: ChangeDetectorRef) {
1919
this.cdr.detach()
2020
}
2121

@@ -33,8 +33,8 @@ export class ControlComponent<T extends 'text' | 'number'> implements OnChanges
3333
onChange(e: Event) {
3434
const target = e.target as HTMLInputElement
3535
const value = (this.data.type === 'number'
36-
? +target.value
37-
: target.value) as ClassicPreset.InputControl<T>['value']
36+
? +target.value
37+
: target.value) as ClassicPreset.InputControl<T>['value']
3838

3939
this.data.setValue(value)
4040
this.cdr.detectChanges()

src/presets/classic/components/node/node.component.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,8 @@
1-
import { Component, Input, HostBinding, ElementRef, ChangeDetectorRef, OnChanges } from '@angular/core';
1+
import { Component, Input, HostBinding, ChangeDetectorRef, OnChanges } from '@angular/core';
22
import { ClassicPreset as Classic } from 'rete';
3-
import { Directive } from '@angular/core';
43
import { KeyValue } from '@angular/common';
54

6-
@Directive({
7-
selector: '[refComponent]'
8-
})
9-
export class RefDirective implements OnChanges {
10-
@Input() data!: any
11-
@Input() emit!: any
12-
13-
constructor(private el: ElementRef) { }
14-
15-
ngOnChanges() {
16-
this.emit({ type: 'render', data: { ...this.data, element: this.el.nativeElement } })
17-
}
18-
}
19-
20-
type SortValue<N extends Classic.Node> = (N['controls'] | N['inputs'] | N['outputs'])[string]
5+
type SortValue<N extends Classic.Node> = (N['controls'] | N['inputs'] | N['outputs'])[string]
216

227
@Component({
238
templateUrl: './node.component.html',
@@ -37,7 +22,7 @@ export class NodeComponent implements OnChanges {
3722
return this.data.selected
3823
}
3924

40-
constructor(private cdr: ChangeDetectorRef) {
25+
constructor(private cdr: ChangeDetectorRef) {
4126
this.cdr.detach()
4227
}
4328

src/ref.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Input, ElementRef, OnChanges, OnDestroy } from '@angular/core';
2+
import { Directive } from '@angular/core';
3+
4+
@Directive({
5+
selector: '[refComponent]'
6+
})
7+
export class RefDirective implements OnChanges, OnDestroy {
8+
@Input() data!: any
9+
@Input() emit!: any
10+
11+
constructor(private el: ElementRef) { }
12+
13+
ngOnChanges() {
14+
this.emit({ type: 'render', data: { ...this.data, element: this.el.nativeElement } })
15+
}
16+
17+
ngOnDestroy() {
18+
this.emit({ type: 'unmount', data: { element: this.el.nativeElement } })
19+
}
20+
}

0 commit comments

Comments
 (0)